rmath3d_plain 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/ChangeLog +8 -0
- data/LICENSE.txt +1 -1
- data/README.md +4 -1
- data/lib/rmath3d/rmath3d_plain.rb +100 -59
- data/sample/opengl-bindings/load_matrix.rb +2 -2
- data/sample/opengl2/load_matrix.rb +2 -2
- data/test/test.rb +1 -1
- data/test/test_RMtx4.rb +11 -11
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4afeec14769aedc4dc064924600f42123b7db3001dd1d9b04887ea72226a6e62
|
4
|
+
data.tar.gz: 65f26f341e1c5c13e2e1971131132c7d641e1ac2cc1ee1abc1cc9a92c47f2731
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc52e86e9d990b0bfe033c399dbcf5da0b2eefd2309b37ce539bfaf420c58fbd8a526e4723c511d92ab5f473ea7257a696126f39b79606342dcfb91840273759
|
7
|
+
data.tar.gz: a197442846a593aa7d54a63609aa9ba3eebebdd6a2fa7b984def5741f077ec3e6322770164d2e200718769635f24a1cd58b3cc1ceb5a9bf1770336e81d7a822a
|
data/ChangeLog
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
2020-06-21 vaiorabbit <http://twitter.com/vaiorabbit>
|
2
|
+
|
3
|
+
* rmath3d.c, rmath3d_plain.rb (RMtx4): Added argument 'ndc_homogeneous' for projection matrix APIs.
|
4
|
+
Set true for the environment with Z coordinate ranges from -1 to +1 (OpenGL), and false otherwise (Direct3D, Metal)
|
5
|
+
https://www.slideshare.net/Mark_Kilgard/opengl-32-and-more/26-Direct3D_vs_OpenGL_Coordinate_System
|
6
|
+
https://metashapes.com/blog/opengl-metal-projection-matrix-problem/
|
7
|
+
* rmath3d_plain.rb: Removed Fixnum and Bignum symbols (deprecated and unified into Integer class since Ruby 2.4)
|
8
|
+
|
1
9
|
2017-07-22 vaiorabbit <http://twitter.com/vaiorabbit>
|
2
10
|
|
3
11
|
* Added 'Integer' type for argument type branching (constant ::Fixnum is deprecated since ruby 2.4).
|
data/LICENSE.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
rmath3d : Ruby math module for 3D Applications
|
2
|
-
Copyright (c) 2008-
|
2
|
+
Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
|
3
3
|
|
4
4
|
This software is provided 'as-is', without any express or implied
|
5
5
|
warranty. In no event will the authors be held liable for any damages
|
data/README.md
CHANGED
@@ -4,9 +4,12 @@
|
|
4
4
|
|
5
5
|
rmath3d is a math module for 3D game programming and computer graphics.
|
6
6
|
|
7
|
-
* Last Update:
|
7
|
+
* Last Update: Jun 21, 2020
|
8
8
|
* Since: Jul 20, 2008
|
9
9
|
|
10
|
+
* rmath3d (C Extension Library Implementation) [![Gem Version](https://badge.fury.io/rb/rmath3d.svg)](https://badge.fury.io/rb/rmath3d) [![Gem](https://img.shields.io/gem/dt/rmath3d.svg)](https://rubygems.org/gems/rmath3d)
|
11
|
+
* rmath3d_plain (Pure Ruby Implementation) [![Gem Version](https://badge.fury.io/rb/rmath3d_plain.svg)](https://badge.fury.io/rb/rmath3d_plain) [![Gem](https://img.shields.io/gem/dt/rmath3d_plain.svg)](https://rubygems.org/gems/rmath3d_plain)
|
12
|
+
|
10
13
|
## Features ##
|
11
14
|
|
12
15
|
### Supports frequently-used vector and matrix classes ###
|
@@ -29,7 +29,7 @@ module RMath3D
|
|
29
29
|
0.0, 0.0 ]
|
30
30
|
when 1
|
31
31
|
case a[0]
|
32
|
-
when Float, Integer
|
32
|
+
when Float, Integer
|
33
33
|
@e = [ a[0], a[0],
|
34
34
|
a[0], a[0] ]
|
35
35
|
when RMtx2
|
@@ -46,7 +46,7 @@ module RMath3D
|
|
46
46
|
for col in 0...2 do
|
47
47
|
index = 2*row + col
|
48
48
|
case a[index]
|
49
|
-
when Float, Integer
|
49
|
+
when Float, Integer
|
50
50
|
setElement( row, col, a[index] )
|
51
51
|
else
|
52
52
|
raise TypeError, "RMtx2#initialize : Unknown type #{a[0].class}."
|
@@ -88,7 +88,7 @@ module RMath3D
|
|
88
88
|
#
|
89
89
|
def coerce
|
90
90
|
case arg
|
91
|
-
when Float, Integer
|
91
|
+
when Float, Integer
|
92
92
|
return [ self, arg ]
|
93
93
|
else
|
94
94
|
raise TypeError, "RMtx2#coerce : #{arg.self} can't be coerced into #{self.class}."
|
@@ -411,7 +411,7 @@ module RMath3D
|
|
411
411
|
#
|
412
412
|
def *( arg )
|
413
413
|
case arg
|
414
|
-
when Float, Integer
|
414
|
+
when Float, Integer
|
415
415
|
return RMtx2.new( arg*self.e00, arg*self.e01,
|
416
416
|
arg*self.e10, arg*self.e11 )
|
417
417
|
|
@@ -503,7 +503,7 @@ module RMath3D
|
|
503
503
|
#
|
504
504
|
def mul!( other )
|
505
505
|
case other
|
506
|
-
when Float, Integer
|
506
|
+
when Float, Integer
|
507
507
|
self.e00 = other*self.e00
|
508
508
|
self.e01 = other*self.e01
|
509
509
|
self.e10 = other*self.e10
|
@@ -560,7 +560,7 @@ module RMath3D
|
|
560
560
|
0.0, 0.0, 0.0 ]
|
561
561
|
when 1
|
562
562
|
case a[0]
|
563
|
-
when Float, Integer
|
563
|
+
when Float, Integer
|
564
564
|
@e = [ a[0], a[0], a[0],
|
565
565
|
a[0], a[0], a[0],
|
566
566
|
a[0], a[0], a[0] ]
|
@@ -579,7 +579,7 @@ module RMath3D
|
|
579
579
|
for col in 0...3 do
|
580
580
|
index = 3*row + col
|
581
581
|
case a[index]
|
582
|
-
when Float, Integer
|
582
|
+
when Float, Integer
|
583
583
|
setElement( row, col, a[index] )
|
584
584
|
else
|
585
585
|
raise TypeError, "RMtx3#initialize : Unknown type #{a[0].class}."
|
@@ -622,7 +622,7 @@ module RMath3D
|
|
622
622
|
#
|
623
623
|
def coerce
|
624
624
|
case arg
|
625
|
-
when Float, Integer
|
625
|
+
when Float, Integer
|
626
626
|
return [ self, arg ]
|
627
627
|
else
|
628
628
|
raise TypeError, "RMtx3#coerce : #{arg.self} can't be coerced into #{self.class}."
|
@@ -1098,7 +1098,7 @@ module RMath3D
|
|
1098
1098
|
#
|
1099
1099
|
def *( arg )
|
1100
1100
|
case arg
|
1101
|
-
when Float, Integer
|
1101
|
+
when Float, Integer
|
1102
1102
|
return RMtx3.new( arg*self.e00, arg*self.e01, arg*self.e02,
|
1103
1103
|
arg*self.e10, arg*self.e11, arg*self.e12,
|
1104
1104
|
arg*self.e20, arg*self.e21, arg*self.e22 )
|
@@ -1191,7 +1191,7 @@ module RMath3D
|
|
1191
1191
|
#
|
1192
1192
|
def mul!( other )
|
1193
1193
|
case other
|
1194
|
-
when Float, Integer
|
1194
|
+
when Float, Integer
|
1195
1195
|
self.e00 = other*self.e00
|
1196
1196
|
self.e01 = other*self.e01
|
1197
1197
|
self.e02 = other*self.e02
|
@@ -1259,7 +1259,7 @@ module RMath3D
|
|
1259
1259
|
0.0, 0.0, 0.0, 0.0 ]
|
1260
1260
|
when 1
|
1261
1261
|
case a[0]
|
1262
|
-
when Float, Integer
|
1262
|
+
when Float, Integer
|
1263
1263
|
@e = [ a[0], a[0], a[0], a[0],
|
1264
1264
|
a[0], a[0], a[0], a[0],
|
1265
1265
|
a[0], a[0], a[0], a[0],
|
@@ -1280,7 +1280,7 @@ module RMath3D
|
|
1280
1280
|
for col in 0...4 do
|
1281
1281
|
index = 4*row + col
|
1282
1282
|
case a[index]
|
1283
|
-
when Float, Integer
|
1283
|
+
when Float, Integer
|
1284
1284
|
setElement( row, col, a[index] )
|
1285
1285
|
else
|
1286
1286
|
raise TypeError, "RMtx4#initialize : Unknown type #{a[0].class}."
|
@@ -1324,7 +1324,7 @@ module RMath3D
|
|
1324
1324
|
#
|
1325
1325
|
def coerce
|
1326
1326
|
case arg
|
1327
|
-
when Float, Integer
|
1327
|
+
when Float, Integer
|
1328
1328
|
return [ self, arg ]
|
1329
1329
|
else
|
1330
1330
|
raise TypeError, "RMtx4#coerce : #{arg.self} can't be coerced into #{self.class}."
|
@@ -1837,6 +1837,39 @@ module RMath3D
|
|
1837
1837
|
return self
|
1838
1838
|
end
|
1839
1839
|
|
1840
|
+
#
|
1841
|
+
# call-seq: lookAtLH(eye,at,up) -> self
|
1842
|
+
#
|
1843
|
+
# Builds a viewing matrix for a left-handed coordinate system from:
|
1844
|
+
# * eye position (+eye+: RVec3)
|
1845
|
+
# * a point looking at (+at+: RVec3)
|
1846
|
+
# * up vector (+up+: RVec3)
|
1847
|
+
#
|
1848
|
+
def lookAtLH( eye, at, up )
|
1849
|
+
setIdentity()
|
1850
|
+
|
1851
|
+
axis_z = (at - eye).normalize!
|
1852
|
+
axis_x = RVec3.cross( up, axis_z ).normalize!
|
1853
|
+
axis_y = RVec3.cross( axis_z, axis_x )
|
1854
|
+
|
1855
|
+
self.e00 = axis_x[0]
|
1856
|
+
self.e01 = axis_x[1]
|
1857
|
+
self.e02 = axis_x[2]
|
1858
|
+
self.e03 = -RVec3.dot( axis_x, eye )
|
1859
|
+
|
1860
|
+
self.e10 = axis_y[0]
|
1861
|
+
self.e11 = axis_y[1]
|
1862
|
+
self.e12 = axis_y[2]
|
1863
|
+
self.e13 = -RVec3.dot( axis_y, eye )
|
1864
|
+
|
1865
|
+
self.e20 = axis_z[0]
|
1866
|
+
self.e21 = axis_z[1]
|
1867
|
+
self.e22 = axis_z[2]
|
1868
|
+
self.e23 = -RVec3.dot( axis_z, eye )
|
1869
|
+
|
1870
|
+
return self
|
1871
|
+
end
|
1872
|
+
|
1840
1873
|
#
|
1841
1874
|
# call-seq: lookAtRH(eye,at,up) -> self
|
1842
1875
|
#
|
@@ -1871,37 +1904,42 @@ module RMath3D
|
|
1871
1904
|
end
|
1872
1905
|
|
1873
1906
|
#
|
1874
|
-
# call-seq: perspectiveRH(width,height,znear,zfar) -> self
|
1907
|
+
# call-seq: perspectiveRH(width,height,znear,zfar,ndc_convention) -> self
|
1875
1908
|
#
|
1876
1909
|
# Builds a perspective projection matrix for a right-handed coordinate system from:
|
1877
1910
|
# * View volume width (+width+)
|
1878
1911
|
# * View volume height (+height+)
|
1879
1912
|
# * Near clip plane distance (+znear+)
|
1880
1913
|
# * Far clip plane distance (+zfar+)
|
1914
|
+
# * Set true for the environment with Z coordinate ranges from -1 to +1 (OpenGL), and false otherwise (Direct3D, Metal) (+ndc_homogeneous+)
|
1881
1915
|
#
|
1882
|
-
def perspectiveRH( width, height, znear, zfar )
|
1883
|
-
perspectiveOffCenterRH(-width/2.0, width/2.0, -height/2.0, height/2.0, znear, zfar )
|
1916
|
+
def perspectiveRH( width, height, znear, zfar, ndc_homogeneous = true)
|
1917
|
+
perspectiveOffCenterRH(-width/2.0, width/2.0, -height/2.0, height/2.0, znear, zfar, ndc_homogeneous )
|
1884
1918
|
return self
|
1885
1919
|
end
|
1886
1920
|
|
1887
1921
|
#
|
1888
|
-
# call-seq: perspectiveFovRH(fovy,aspect,znear,zfar) -> self
|
1922
|
+
# call-seq: perspectiveFovRH(fovy,aspect,znear,zfar,ndc_homogeneous) -> self
|
1889
1923
|
#
|
1890
1924
|
# Builds a perspective projection matrix for a right-handed coordinate system from:
|
1891
1925
|
# * Field of view in y direction (+fovy+ radian)
|
1892
1926
|
# * Aspect ratio (+aspect+)
|
1893
1927
|
# * Near clip plane distance (+znear+)
|
1894
1928
|
# * Far clip plane distance (+zfar+)
|
1929
|
+
# * Set true for the environment with Z coordinate ranges from -1 to +1 (OpenGL), and false otherwise (Direct3D, Metal) (+ndc_homogeneous+)
|
1895
1930
|
#
|
1896
|
-
def perspectiveFovRH( fovy_radian, aspect, znear, zfar )
|
1931
|
+
def perspectiveFovRH( fovy_radian, aspect, znear, zfar, ndc_homogeneous = true)
|
1897
1932
|
f = Math::tan( fovy_radian / 2.0 )
|
1898
1933
|
f = 1.0 / f
|
1899
1934
|
|
1935
|
+
c = ndc_homogeneous ? -(zfar+znear) / (zfar-znear) : -zfar / (zfar-znear)
|
1936
|
+
d = ndc_homogeneous ? -(2*znear*zfar) / (zfar-znear) : -(znear*zfar) / (zfar-znear)
|
1937
|
+
|
1900
1938
|
setIdentity()
|
1901
1939
|
setElement( 0, 0, f / aspect )
|
1902
1940
|
setElement( 1, 1, f )
|
1903
|
-
setElement( 2, 2,
|
1904
|
-
setElement( 2, 3,
|
1941
|
+
setElement( 2, 2, c )
|
1942
|
+
setElement( 2, 3, d )
|
1905
1943
|
setElement( 3, 2, -1.0 )
|
1906
1944
|
setElement( 3, 3, 0.0 )
|
1907
1945
|
|
@@ -1918,12 +1956,13 @@ module RMath3D
|
|
1918
1956
|
# * Maximum value of the view volume height (+top+)
|
1919
1957
|
# * Near clip plane distance (+znear+)
|
1920
1958
|
# * Far clip plane distance (+zfar+)
|
1959
|
+
# * Set true for the environment with Z coordinate ranges from -1 to +1 (OpenGL), and false otherwise (Direct3D, Metal) (+ndc_homogeneous+)
|
1921
1960
|
#
|
1922
|
-
def perspectiveOffCenterRH( left, right, bottom, top, znear, zfar )
|
1961
|
+
def perspectiveOffCenterRH( left, right, bottom, top, znear, zfar, ndc_homogeneous = true)
|
1923
1962
|
a = (right+left) / (right-left)
|
1924
1963
|
b = (top+bottom) / (top-bottom)
|
1925
|
-
c = -(zfar+znear) / (zfar-znear)
|
1926
|
-
d = -(2*znear*zfar) / (zfar-znear)
|
1964
|
+
c = ndc_homogeneous ? -(zfar+znear) / (zfar-znear) : -zfar / (zfar-znear)
|
1965
|
+
d = ndc_homogeneous ? -(2*znear*zfar) / (zfar-znear) : -(znear*zfar) / (zfar-znear)
|
1927
1966
|
|
1928
1967
|
setIdentity()
|
1929
1968
|
|
@@ -1947,9 +1986,10 @@ module RMath3D
|
|
1947
1986
|
# * View volume height (+height+)
|
1948
1987
|
# * Near clip plane distance (+znear+)
|
1949
1988
|
# * Far clip plane distance (+zfar+)
|
1989
|
+
# * Set true for the environment with Z coordinate ranges from -1 to +1 (OpenGL), and false otherwise (Direct3D, Metal) (+ndc_homogeneous+)
|
1950
1990
|
#
|
1951
|
-
def orthoRH( width, height, znear, zfar )
|
1952
|
-
orthoOffCenterRH( -width/2.0, width/2.0, -height/2.0, height/2.0, znear, zfar )
|
1991
|
+
def orthoRH( width, height, znear, zfar, ndc_homogeneous = true)
|
1992
|
+
orthoOffCenterRH( -width/2.0, width/2.0, -height/2.0, height/2.0, znear, zfar, ndc_homogeneous )
|
1953
1993
|
return self
|
1954
1994
|
end
|
1955
1995
|
|
@@ -1963,11 +2003,12 @@ module RMath3D
|
|
1963
2003
|
# * Maximum value of the view volume height (+top+)
|
1964
2004
|
# * Near clip plane distance (+znear+)
|
1965
2005
|
# * Far clip plane distance (+zfar+)
|
2006
|
+
# * Set true for the environment with Z coordinate ranges from -1 to +1 (OpenGL), and false otherwise (Direct3D, Metal) (+ndc_homogeneous+)
|
1966
2007
|
#
|
1967
|
-
def orthoOffCenterRH( left, right, bottom, top, znear, zfar )
|
1968
|
-
tx = (right+left) / (right-left)
|
1969
|
-
ty = (top+bottom) / (top-bottom)
|
1970
|
-
tz = (zfar+znear) / (zfar-znear)
|
2008
|
+
def orthoOffCenterRH( left, right, bottom, top, znear, zfar, ndc_homogeneous = true)
|
2009
|
+
tx = -(right+left) / (right-left)
|
2010
|
+
ty = -(top+bottom) / (top-bottom)
|
2011
|
+
tz = ndc_homogeneous ? -(zfar+znear) / (zfar-znear) : -znear / (zfar-znear)
|
1971
2012
|
|
1972
2013
|
setIdentity()
|
1973
2014
|
|
@@ -1975,7 +2016,7 @@ module RMath3D
|
|
1975
2016
|
setElement( 0, 3, tx )
|
1976
2017
|
setElement( 1, 1, 2.0/(top-bottom) )
|
1977
2018
|
setElement( 1, 3, ty )
|
1978
|
-
setElement( 2, 2, -2.0/(zfar-znear) )
|
2019
|
+
setElement( 2, 2, -(ndc_homogeneous ? 2.0 : 1.0)/(zfar-znear) )
|
1979
2020
|
setElement( 2, 3, tz )
|
1980
2021
|
|
1981
2022
|
return self
|
@@ -2048,7 +2089,7 @@ module RMath3D
|
|
2048
2089
|
#
|
2049
2090
|
def *( arg )
|
2050
2091
|
case arg
|
2051
|
-
when Float, Integer
|
2092
|
+
when Float, Integer
|
2052
2093
|
return RMtx4.new( arg*self.e00, arg*self.e01, arg*self.e02, arg*self.e03,
|
2053
2094
|
arg*self.e10, arg*self.e11, arg*self.e12, arg*self.e13,
|
2054
2095
|
arg*self.e20, arg*self.e21, arg*self.e22, arg*self.e23,
|
@@ -2142,7 +2183,7 @@ module RMath3D
|
|
2142
2183
|
#
|
2143
2184
|
def mul!( other )
|
2144
2185
|
case other
|
2145
|
-
when Float, Integer
|
2186
|
+
when Float, Integer
|
2146
2187
|
self.e00 = other*self.e00
|
2147
2188
|
self.e01 = other*self.e01
|
2148
2189
|
self.e02 = other*self.e02
|
@@ -2224,7 +2265,7 @@ module RMath3D
|
|
2224
2265
|
@e = [0.0, 0.0, 0.0, 0.0]
|
2225
2266
|
when 1
|
2226
2267
|
case a[0]
|
2227
|
-
when Float, Integer
|
2268
|
+
when Float, Integer
|
2228
2269
|
@e = [ a[0], a[0], a[0], a[0] ]
|
2229
2270
|
when RQuat
|
2230
2271
|
@e = [ a[0].x, a[0].y, a[0].z, a[0].w ]
|
@@ -2235,7 +2276,7 @@ module RMath3D
|
|
2235
2276
|
when 4
|
2236
2277
|
a.each_with_index do |elem, index|
|
2237
2278
|
case elem
|
2238
|
-
when Float, Integer
|
2279
|
+
when Float, Integer
|
2239
2280
|
@e[index] = elem
|
2240
2281
|
else
|
2241
2282
|
raise TypeError, "RQuat#initialize : Unknown type #{elem.class}."
|
@@ -2274,7 +2315,7 @@ module RMath3D
|
|
2274
2315
|
#
|
2275
2316
|
def coerce( arg )
|
2276
2317
|
case arg
|
2277
|
-
when Float, Integer
|
2318
|
+
when Float, Integer
|
2278
2319
|
return [ self, arg ]
|
2279
2320
|
else
|
2280
2321
|
raise TypeError, "RQuat#coerce : #{arg.self} can't be coerced into #{self.class}."
|
@@ -2613,7 +2654,7 @@ module RMath3D
|
|
2613
2654
|
z = q1w*q2z + q1x*q2y - q1y*q2x + q1z*q2w
|
2614
2655
|
w = q1w*q2w - q1x*q2x - q1y*q2y - q1z*q2z
|
2615
2656
|
return RQuat.new( x, y, z, w )
|
2616
|
-
when Float, Integer
|
2657
|
+
when Float, Integer
|
2617
2658
|
return RQuat.new( @e[0]*arg, @e[1]*arg, @e[2]*arg, @e[3]*arg )
|
2618
2659
|
else
|
2619
2660
|
raise TypeError, "RQuat#* : Unknown type #{arg}."
|
@@ -2708,7 +2749,7 @@ module RMath3D
|
|
2708
2749
|
|
2709
2750
|
return self
|
2710
2751
|
|
2711
|
-
when Float, Integer
|
2752
|
+
when Float, Integer
|
2712
2753
|
self.x *= other
|
2713
2754
|
self.y *= other
|
2714
2755
|
self.z *= other
|
@@ -2824,7 +2865,7 @@ module RMath3D
|
|
2824
2865
|
@e = [0.0, 0.0]
|
2825
2866
|
when 1
|
2826
2867
|
case a[0]
|
2827
|
-
when Float, Integer
|
2868
|
+
when Float, Integer
|
2828
2869
|
@e = [ a[0], a[0] ]
|
2829
2870
|
when RVec2
|
2830
2871
|
@e = [ a[0].x, a[0].y ]
|
@@ -2835,7 +2876,7 @@ module RMath3D
|
|
2835
2876
|
when 2
|
2836
2877
|
a.each_with_index do |elem, index|
|
2837
2878
|
case elem
|
2838
|
-
when Float, Integer
|
2879
|
+
when Float, Integer
|
2839
2880
|
@e[index] = elem
|
2840
2881
|
else
|
2841
2882
|
raise TypeError, "RVec2#initialize : Unknown type #{elem.class}."
|
@@ -2874,7 +2915,7 @@ module RMath3D
|
|
2874
2915
|
#
|
2875
2916
|
def coerce( arg )
|
2876
2917
|
case arg
|
2877
|
-
when Float, Integer
|
2918
|
+
when Float, Integer
|
2878
2919
|
return [ self, arg ]
|
2879
2920
|
else
|
2880
2921
|
raise TypeError, "RVec2#coerce : #{arg.self} can't be coerced into #{self.class}."
|
@@ -3063,7 +3104,7 @@ module RMath3D
|
|
3063
3104
|
#
|
3064
3105
|
def *( arg )
|
3065
3106
|
case arg
|
3066
|
-
when Float, Integer
|
3107
|
+
when Float, Integer
|
3067
3108
|
return RVec2.new( @e[0]*arg, @e[1]*arg )
|
3068
3109
|
else
|
3069
3110
|
raise TypeError, "RVec2#* : Unknown type #{arg}."
|
@@ -3129,7 +3170,7 @@ module RMath3D
|
|
3129
3170
|
# vec1 *= vec2
|
3130
3171
|
#
|
3131
3172
|
def mul!( arg )
|
3132
|
-
if !(arg.class == Float || arg.class == Integer
|
3173
|
+
if !(arg.class == Float || arg.class == Integer)
|
3133
3174
|
raise TypeError, "RVec2#mul! : Unknown type #{arg.class}."
|
3134
3175
|
return nil
|
3135
3176
|
end
|
@@ -3163,7 +3204,7 @@ module RMath3D
|
|
3163
3204
|
@e = [0.0, 0.0, 0.0]
|
3164
3205
|
when 1
|
3165
3206
|
case a[0]
|
3166
|
-
when Float, Integer
|
3207
|
+
when Float, Integer
|
3167
3208
|
@e = [ a[0], a[0], a[0] ]
|
3168
3209
|
when RVec3
|
3169
3210
|
@e = [ a[0].x, a[0].y, a[0].z ]
|
@@ -3174,7 +3215,7 @@ module RMath3D
|
|
3174
3215
|
when 3
|
3175
3216
|
a.each_with_index do |elem, index|
|
3176
3217
|
case elem
|
3177
|
-
when Float, Integer
|
3218
|
+
when Float, Integer
|
3178
3219
|
@e[index] = elem
|
3179
3220
|
else
|
3180
3221
|
raise TypeError, "RVec3#initialize : Unknown type #{elem.class}."
|
@@ -3213,7 +3254,7 @@ module RMath3D
|
|
3213
3254
|
#
|
3214
3255
|
def coerce( arg )
|
3215
3256
|
case arg
|
3216
|
-
when Float, Integer
|
3257
|
+
when Float, Integer
|
3217
3258
|
return [ self, arg ]
|
3218
3259
|
else
|
3219
3260
|
raise TypeError, "RVec3#coerce : #{arg.self} can't be coerced into #{self.class}."
|
@@ -3517,9 +3558,9 @@ module RMath3D
|
|
3517
3558
|
t_z = q.w*self[2] + q.x*self[1] - q.y*self[0]
|
3518
3559
|
t_w = - q.x*self[0] - q.y*self[1] - q.z*self[2]
|
3519
3560
|
|
3520
|
-
result.x = -t_w*q.x + t_x*q.w - t_y*q.z + t_z*q.y
|
3521
|
-
result.y = -t_w*q.y + t_x*q.z + t_y*q.w - t_z*q.x
|
3522
|
-
result.z = -t_w*q.z - t_x*q.y + t_y*q.x + t_z*q.w
|
3561
|
+
result.x = -t_w*q.x + t_x*q.w - t_y*q.z + t_z*q.y
|
3562
|
+
result.y = -t_w*q.y + t_x*q.z + t_y*q.w - t_z*q.x
|
3563
|
+
result.z = -t_w*q.z - t_x*q.y + t_y*q.x + t_z*q.w
|
3523
3564
|
|
3524
3565
|
return result
|
3525
3566
|
end
|
@@ -3533,9 +3574,9 @@ module RMath3D
|
|
3533
3574
|
t_z = q.w*self[2] + q.x*self[1] - q.y*self[0]
|
3534
3575
|
t_w = - q.x*self[0] - q.y*self[1] - q.z*self[2]
|
3535
3576
|
|
3536
|
-
self.x = -t_w*q.x + t_x*q.w - t_y*q.z + t_z*q.y
|
3537
|
-
self.y = -t_w*q.y + t_x*q.z + t_y*q.w - t_z*q.x
|
3538
|
-
self.z = -t_w*q.z - t_x*q.y + t_y*q.x + t_z*q.w
|
3577
|
+
self.x = -t_w*q.x + t_x*q.w - t_y*q.z + t_z*q.y
|
3578
|
+
self.y = -t_w*q.y + t_x*q.z + t_y*q.w - t_z*q.x
|
3579
|
+
self.z = -t_w*q.z - t_x*q.y + t_y*q.x + t_z*q.w
|
3539
3580
|
|
3540
3581
|
return self
|
3541
3582
|
end
|
@@ -3616,7 +3657,7 @@ module RMath3D
|
|
3616
3657
|
#
|
3617
3658
|
def *( arg )
|
3618
3659
|
case arg
|
3619
|
-
when Float, Integer
|
3660
|
+
when Float, Integer
|
3620
3661
|
return RVec3.new( @e[0]*arg, @e[1]*arg, @e[2]*arg )
|
3621
3662
|
else
|
3622
3663
|
raise TypeError, "RVec3#* : Unknown type #{arg}."
|
@@ -3685,7 +3726,7 @@ module RMath3D
|
|
3685
3726
|
# vec1 *= vec2
|
3686
3727
|
#
|
3687
3728
|
def mul!( arg )
|
3688
|
-
if !(arg.class == Float || arg.class == Integer
|
3729
|
+
if !(arg.class == Float || arg.class == Integer)
|
3689
3730
|
raise TypeError, "RVec3#mul! : Unknown type #{arg.class}."
|
3690
3731
|
return nil
|
3691
3732
|
end
|
@@ -3720,7 +3761,7 @@ module RMath3D
|
|
3720
3761
|
@e = [0.0, 0.0, 0.0, 0.0]
|
3721
3762
|
when 1
|
3722
3763
|
case a[0]
|
3723
|
-
when Float, Integer
|
3764
|
+
when Float, Integer
|
3724
3765
|
@e = [ a[0], a[0], a[0], a[0] ]
|
3725
3766
|
when RVec3
|
3726
3767
|
@e = [ a[0].x, a[0].y, a[0].z, 0.0 ]
|
@@ -3733,7 +3774,7 @@ module RMath3D
|
|
3733
3774
|
when 4
|
3734
3775
|
a.each_with_index do |elem, index|
|
3735
3776
|
case elem
|
3736
|
-
when Float, Integer
|
3777
|
+
when Float, Integer
|
3737
3778
|
@e[index] = elem
|
3738
3779
|
else
|
3739
3780
|
raise TypeError, "RVec4#initialize : Unknown type #{elem.class}."
|
@@ -3772,7 +3813,7 @@ module RMath3D
|
|
3772
3813
|
#
|
3773
3814
|
def coerce( arg )
|
3774
3815
|
case arg
|
3775
|
-
when Float, Integer
|
3816
|
+
when Float, Integer
|
3776
3817
|
return [ self, arg ]
|
3777
3818
|
else
|
3778
3819
|
raise TypeError, "RVec4#coerce : #{arg.self} can't be coerced into #{self.class}."
|
@@ -4062,7 +4103,7 @@ module RMath3D
|
|
4062
4103
|
#
|
4063
4104
|
def *( arg )
|
4064
4105
|
case arg
|
4065
|
-
when Float, Integer
|
4106
|
+
when Float, Integer
|
4066
4107
|
return RVec4.new( @e[0]*arg, @e[1]*arg, @e[2]*arg, @e[3]*arg )
|
4067
4108
|
else
|
4068
4109
|
raise TypeError, "RVec4#* : Unknown type #{arg}."
|
@@ -4134,7 +4175,7 @@ module RMath3D
|
|
4134
4175
|
# vec1 *= vec2
|
4135
4176
|
#
|
4136
4177
|
def mul!( other )
|
4137
|
-
if !(other.class == Float || other.class == Integer
|
4178
|
+
if !(other.class == Float || other.class == Integer)
|
4138
4179
|
raise TypeError, "RVec4#mul! : Unknown type #{other.class}."
|
4139
4180
|
return nil
|
4140
4181
|
end
|
@@ -4152,7 +4193,7 @@ end
|
|
4152
4193
|
|
4153
4194
|
=begin
|
4154
4195
|
RMath : Ruby math module for 3D Applications
|
4155
|
-
Copyright (c) 2008-
|
4196
|
+
Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
|
4156
4197
|
|
4157
4198
|
This software is provided 'as-is', without any express or implied
|
4158
4199
|
warranty. In no event will the authors be held liable for any damages
|
@@ -104,7 +104,7 @@ class App
|
|
104
104
|
def size_callback( window_handle, w, h )
|
105
105
|
glViewport( 0, 0, w, h )
|
106
106
|
glMatrixMode( GL_PROJECTION )
|
107
|
-
@mtxProj.perspectiveFovRH( 30.0*Math::PI/180.0, w.to_f/h.to_f, 0.1, 1000.0 )
|
107
|
+
@mtxProj.perspectiveFovRH( 30.0*Math::PI/180.0, w.to_f/h.to_f, 0.1, 1000.0, true )
|
108
108
|
glLoadMatrixf( @mtxProj.to_a.pack('F16') )
|
109
109
|
|
110
110
|
@window_width = w
|
@@ -119,7 +119,7 @@ class App
|
|
119
119
|
@at = RVec3.new(0.0, 0.0, 0.0)
|
120
120
|
@up = RVec3.new(0.0, 1.0, 0.0)
|
121
121
|
@mtxLookAt = RMtx4.new.lookAtRH( @eye, @at, @up )
|
122
|
-
@mtxProj = RMtx4.new.perspectiveFovRH( 30.0*Math::PI/180.0, @window_width.to_f/@window_height.to_f, 0.1, 1000.0 )
|
122
|
+
@mtxProj = RMtx4.new.perspectiveFovRH( 30.0*Math::PI/180.0, @window_width.to_f/@window_height.to_f, 0.1, 1000.0, true )
|
123
123
|
|
124
124
|
@light_pos = [2.5,0,5,1]
|
125
125
|
@light_diffuse = [1,1,1,1]
|
@@ -42,7 +42,7 @@ class App
|
|
42
42
|
def reshape( width, height )
|
43
43
|
glViewport( 0, 0, width, height )
|
44
44
|
glMatrixMode( GL_PROJECTION )
|
45
|
-
@mtxProj.perspectiveFovRH( 30.0*Math::PI/180.0, width.to_f/height.to_f, 0.1, 1000.0 )
|
45
|
+
@mtxProj.perspectiveFovRH( 30.0*Math::PI/180.0, width.to_f/height.to_f, 0.1, 1000.0, true )
|
46
46
|
glLoadMatrix( @mtxProj )
|
47
47
|
|
48
48
|
@window_width = width
|
@@ -74,7 +74,7 @@ class App
|
|
74
74
|
@at = RVec3.new(0.0, 0.0, 0.0)
|
75
75
|
@up = RVec3.new(0.0, 1.0, 0.0)
|
76
76
|
@mtxLookAt = RMtx4.new.lookAtRH( @eye, @at, @up )
|
77
|
-
@mtxProj = RMtx4.new.perspectiveFovRH( 30.0*Math::PI/180.0, @window_width.to_f/@window_height.to_f, 0.1, 1000.0 )
|
77
|
+
@mtxProj = RMtx4.new.perspectiveFovRH( 30.0*Math::PI/180.0, @window_width.to_f/@window_height.to_f, 0.1, 1000.0, true )
|
78
78
|
|
79
79
|
@light_pos = [2.5,0,5,1]
|
80
80
|
@light_diffuse = [1,1,1,1]
|
data/test/test.rb
CHANGED
data/test/test_RMtx4.rb
CHANGED
@@ -526,7 +526,7 @@ class TC_RMtx4 < Minitest::Test
|
|
526
526
|
0.0, 2*z_n/height, 0.0, 0.0,
|
527
527
|
0.0, 0.0, -(z_f+z_n)/(z_f-z_n), -2.0*z_f*z_n / (z_f-z_n),
|
528
528
|
0.0, 0.0, -1.0, 0.0 )
|
529
|
-
m1 = RMtx4.new.perspectiveRH( width, height, z_n, z_f )
|
529
|
+
m1 = RMtx4.new.perspectiveRH( width, height, z_n, z_f, true )
|
530
530
|
|
531
531
|
for r in 0...4 do
|
532
532
|
for c in 0...4 do
|
@@ -544,7 +544,7 @@ class TC_RMtx4 < Minitest::Test
|
|
544
544
|
0.0, f, 0.0, 0.0,
|
545
545
|
0.0, 0.0, (z_f+z_n)/(z_n-z_f), 2*z_f*z_n/(z_n-z_f),
|
546
546
|
0.0, 0.0, -1.0, 0.0 )
|
547
|
-
m3 = RMtx4.new.perspectiveFovRH( fovy, aspect, z_n, z_f );
|
547
|
+
m3 = RMtx4.new.perspectiveFovRH( fovy, aspect, z_n, z_f, true );
|
548
548
|
|
549
549
|
for r in 0...4 do
|
550
550
|
for c in 0...4 do
|
@@ -563,7 +563,7 @@ class TC_RMtx4 < Minitest::Test
|
|
563
563
|
0.0, 0.0, c, d,
|
564
564
|
0.0, 0.0, -1.0, 0.0 )
|
565
565
|
|
566
|
-
m5 = RMtx4.new.perspectiveOffCenterRH( left, right, bottom, top, z_n, z_f )
|
566
|
+
m5 = RMtx4.new.perspectiveOffCenterRH( left, right, bottom, top, z_n, z_f, true )
|
567
567
|
|
568
568
|
for r in 0...4 do
|
569
569
|
for c in 0...4 do
|
@@ -584,14 +584,14 @@ class TC_RMtx4 < Minitest::Test
|
|
584
584
|
height = top - bottom
|
585
585
|
|
586
586
|
# RMtx4#orthoRH
|
587
|
-
tx = (right+left)/width
|
588
|
-
ty = (top+bottom)/height
|
589
|
-
tz = (z_f+z_n)/(z_f-z_n)
|
587
|
+
tx = -(right+left)/width
|
588
|
+
ty = -(top+bottom)/height
|
589
|
+
tz = -(z_f+z_n)/(z_f-z_n)
|
590
590
|
m0 = RMtx4.new( 2.0/width, 0.0, 0.0, tx,
|
591
591
|
0.0, 2.0/height, 0.0, ty,
|
592
592
|
0.0, 0.0, -2.0/(z_f-z_n), tz,
|
593
593
|
0.0, 0.0, 0.0, 1.0 )
|
594
|
-
m1 = RMtx4.new.orthoRH( width, height, z_n, z_f )
|
594
|
+
m1 = RMtx4.new.orthoRH( width, height, z_n, z_f, true )
|
595
595
|
|
596
596
|
for r in 0...4 do
|
597
597
|
for c in 0...4 do
|
@@ -600,14 +600,14 @@ class TC_RMtx4 < Minitest::Test
|
|
600
600
|
end
|
601
601
|
|
602
602
|
# RMtx4#orthoOffCenterRH
|
603
|
-
tx = (right+left)/(right-left)
|
604
|
-
ty = (top+bottom)/(top-bottom)
|
605
|
-
tz = (z_f+z_n)/(z_f-z_n)
|
603
|
+
tx = -(right+left)/(right-left)
|
604
|
+
ty = -(top+bottom)/(top-bottom)
|
605
|
+
tz = -(z_f+z_n)/(z_f-z_n)
|
606
606
|
m2 = RMtx4.new( 2.0/(right-left), 0.0, 0.0, tx,
|
607
607
|
0.0, 2.0/(top-bottom), 0.0, ty,
|
608
608
|
0.0, 0.0, -2.0/(z_f-z_n), tz,
|
609
609
|
0.0, 0.0, 0.0, 1.0 )
|
610
|
-
m3 = RMtx4.new.orthoOffCenterRH( left, right, bottom, top, z_n, z_f )
|
610
|
+
m3 = RMtx4.new.orthoOffCenterRH( left, right, bottom, top, z_n, z_f, true )
|
611
611
|
|
612
612
|
for r in 0...4 do
|
613
613
|
for c in 0...4 do
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rmath3d_plain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vaiorabbit
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Provides vector2/3/4, matrix2x2/3x3/4x4 and quaternion in plain Ruby
|
14
14
|
form.
|
15
15
|
|
16
|
-
'
|
16
|
+
'
|
17
17
|
email:
|
18
18
|
- vaiorabbit@gmail.com
|
19
19
|
executables: []
|
@@ -39,7 +39,7 @@ homepage: https://github.com/vaiorabbit/rmath3d
|
|
39
39
|
licenses:
|
40
40
|
- Zlib
|
41
41
|
metadata: {}
|
42
|
-
post_install_message:
|
42
|
+
post_install_message:
|
43
43
|
rdoc_options: []
|
44
44
|
require_paths:
|
45
45
|
- lib
|
@@ -47,16 +47,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
47
|
requirements:
|
48
48
|
- - ">="
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: 2.
|
50
|
+
version: 2.4.0
|
51
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
|
-
|
58
|
-
|
59
|
-
signing_key:
|
57
|
+
rubygems_version: 3.1.2
|
58
|
+
signing_key:
|
60
59
|
specification_version: 4
|
61
60
|
summary: Ruby Math Module for 3D Applications
|
62
61
|
test_files: []
|