rmath3d 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/ext/rmath3d/RMath3D.h +1 -1
- data/ext/rmath3d/RMtx2.c +1 -1
- data/ext/rmath3d/RMtx2.h +1 -1
- data/ext/rmath3d/RMtx3.c +1 -1
- data/ext/rmath3d/RMtx3.h +1 -1
- data/ext/rmath3d/RMtx4.c +25 -19
- data/ext/rmath3d/RMtx4.h +7 -6
- data/ext/rmath3d/RQuat.c +1 -1
- data/ext/rmath3d/RQuat.h +1 -1
- data/ext/rmath3d/RType.h +1 -1
- data/ext/rmath3d/RVec2.c +1 -1
- data/ext/rmath3d/RVec2.h +1 -1
- data/ext/rmath3d/RVec3.c +1 -1
- data/ext/rmath3d/RVec3.h +1 -1
- data/ext/rmath3d/RVec4.c +1 -1
- data/ext/rmath3d/RVec4.h +1 -1
- data/ext/rmath3d/rmath3d.c +88 -31
- 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 +7 -8
@@ -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
|