rmath3d 1.0.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2fa4b132536ee9bcbe0c7da9e51fe53bd566010e
4
- data.tar.gz: 17eee04a0ac050c85fbc1953d7302ff7f41e1d06
2
+ SHA256:
3
+ metadata.gz: 9e8d8b8a38ad55ec12170a103c39607b841855790e279ae4c003e394900f3391
4
+ data.tar.gz: 8d74d4f0917015c74accd26293cb4036d9befa0bbe0d562893a324881a1b005f
5
5
  SHA512:
6
- metadata.gz: 9bfefb8f3a0a41f88c8e25fa3074d1b45a05a2be87085c6759029b7566362188c65d41261254b7afacaab22c1fdc221b2e50bccac6097ca36e2e42089cc167d6
7
- data.tar.gz: ac604ce99ae372569cdf291ae09166dc4c67f8d9e86f970bfe6da7b2967ebe6e57ac652dcd0f1a07f222d9801a348df8d5372c6dc5d6d395ea291dfc9d08ec5c
6
+ metadata.gz: c6ea5c48fba49380581ae07cef869767a73ab1e3f2d8bda7481b352241bf3bd82197a188d529bf230ec786dedb35bb9a49145d430b54f298729598f7b3ba6702
7
+ data.tar.gz: b02fb89b9fbb8fe9bc1dd3456ef99507d4d1d1e659b3a2884243ea5342100bca7bee219550e6764e15e43c352cf4561bea5615db56827c2d9365596e9e098802
data/ChangeLog CHANGED
@@ -1,3 +1,29 @@
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
+
9
+ 2017-07-22 vaiorabbit <http://twitter.com/vaiorabbit>
10
+
11
+ * Added 'Integer' type for argument type branching (constant ::Fixnum is deprecated since ruby 2.4).
12
+
13
+ 2015-08-23 vaiorabbit <http://twitter.com/vaiorabbit>
14
+
15
+ * rmath3d.c (def ==): Removed control path returning Qnil.
16
+ * rmath3d_plain.rb (def ==): Removed control path returning Qnil.
17
+
18
+ 2015-05-02 vaiorabbit <http://twitter.com/vaiorabbit>
19
+
20
+ * Ruby 1.9.3 and prior versions are no longer supported. Ref.: https://www.ruby-lang.org/en/news/2015/02/23/support-for-ruby-1-9-3-has-ended/
21
+ * rmath3d.c: Data_Get_Struct -> TypedData_Get_Struct, etc.
22
+
23
+ 2015-04-12 vaiorabbit <http://twitter.com/vaiorabbit>
24
+
25
+ * RVec2.c|h, RMtx2.c|h: Added.
26
+
1
27
  2014-05-17 vaiorabbit <http://twitter.com/vaiorabbit>
2
28
 
3
29
  * ext/rmath3d/rmath3d.c: Fixed memory management
@@ -1,5 +1,5 @@
1
1
  rmath3d : Ruby math module for 3D Applications
2
- Copyright (c) 2008-2014 vaiorabbit <http://twitter.com/vaiorabbit>
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,18 +4,23 @@
4
4
 
5
5
  rmath3d is a math module for 3D game programming and computer graphics.
6
6
 
7
- * Last Update: May 17, 2014
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 ###
13
16
 
17
+ * RMtx2 (2x2 matrix)
14
18
  * RMtx3 (3x3 matrix)
15
19
  * RMtx4 (4x4 matrix)
16
20
  * RQuat (Quaternion)
17
- * RVec3 (3 element vector)
18
- * RVec4 (4 element vector)
21
+ * RVec2 (2-element vector)
22
+ * RVec3 (3-element vector)
23
+ * RVec4 (4-element vector)
19
24
 
20
25
  ### Two implementations that are interchangeable with each other ###
21
26
 
@@ -33,6 +38,9 @@ Notice: This library provides native extension. You must setup develop environme
33
38
  * I used: DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe
34
39
  * Unpack the archive -> "> ruby dk.rb init" -> edit config.yml (just add your ruby foldier) -> "> ruby dk.rb install"
35
40
  * Ref.: http://blog.mattwynne.net/2010/10/12/installing-ruby-gems-with-native-extensions-on-windows/
41
+ * ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
42
+ * Ruby 1.9.3 and prior versions are no longer supported.
43
+ * Ref.: https://www.ruby-lang.org/en/news/2015/02/23/support-for-ruby-1-9-3-has-ended/
36
44
 
37
45
  ## Building rmath3d.{so|bundle} ##
38
46
 
@@ -1,10 +1,12 @@
1
- #ifndef RMATH_H_INCLUDED
2
- #define RMATH_H_INCLUDED
1
+ #ifndef RMATH3D_H_INCLUDED
2
+ #define RMATH3D_H_INCLUDED
3
3
 
4
4
  #include "RType.h"
5
+ #include "RVec2.h"
5
6
  #include "RVec3.h"
6
7
  #include "RVec4.h"
7
8
  #include "RQuat.h"
9
+ #include "RMtx2.h"
8
10
  #include "RMtx3.h"
9
11
  #include "RMtx4.h"
10
12
 
@@ -12,7 +14,7 @@
12
14
 
13
15
  /*
14
16
  RMath : Ruby math module for 3D Applications
15
- Copyright (c) 2008- vaiorabbit <http://twitter.com/vaiorabbit>
17
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
16
18
 
17
19
  This software is provided 'as-is', without any express or implied
18
20
  warranty. In no event will the authors be held liable for any damages
@@ -0,0 +1,255 @@
1
+ #include <math.h>
2
+ #include <string.h>
3
+
4
+ #include "RVec2.h"
5
+ #include "RMtx2.h"
6
+
7
+ /* NOTE : column-major */
8
+ #define SET_ELEMENT(out, row, col, val) (out)->e[(col)*2+(row)] = (val)
9
+ #define GET_ELEMENT(in, row, col) ((in)->e[(col)*2+(row)])
10
+
11
+ void
12
+ RMtx2SetElement( RMtx2* out, int row, int col, rmReal e )
13
+ {
14
+ SET_ELEMENT( out, row, col, e );
15
+ }
16
+
17
+ rmReal
18
+ RMtx2GetElement( const RMtx2* in, int row, int col )
19
+ {
20
+ return GET_ELEMENT( in, row, col );
21
+ }
22
+
23
+ void
24
+ RMtx2GetRow( RVec2* out, const RMtx2* in, int row )
25
+ {
26
+ RVec2SetX( out, GET_ELEMENT( in, row, 0 ) );
27
+ RVec2SetY( out, GET_ELEMENT( in, row, 1 ) );
28
+ }
29
+
30
+ void
31
+ RMtx2GetColumn( RVec2* out, const RMtx2* in, int col )
32
+ {
33
+ RVec2SetX( out, GET_ELEMENT( in, 0, col ) );
34
+ RVec2SetY( out, GET_ELEMENT( in, 1, col ) );
35
+ }
36
+
37
+ void
38
+ RMtx2SetRow( RMtx2* out, const RVec2* in, int row )
39
+ {
40
+ SET_ELEMENT( out, row, 0, RVec2GetElement( in, 0 ) );
41
+ SET_ELEMENT( out, row, 1, RVec2GetElement( in, 1 ) );
42
+ }
43
+
44
+ void
45
+ RMtx2SetColumn( RMtx2* out, const RVec2* in, int col )
46
+ {
47
+ SET_ELEMENT( out, 0, col, RVec2GetElement( in, 0 ) );
48
+ SET_ELEMENT( out, 1, col, RVec2GetElement( in, 1 ) );
49
+ }
50
+
51
+ void
52
+ RMtx2Copy( RMtx2* out, const RMtx2* in )
53
+ {
54
+ memmove( out, in, sizeof(RMtx2) );
55
+ }
56
+
57
+ void
58
+ RMtx2SetElements( RMtx2* out,
59
+ rmReal e00, rmReal e01,
60
+ rmReal e10, rmReal e11
61
+ )
62
+ {
63
+ SET_ELEMENT( out, 0, 0, e00 );
64
+ SET_ELEMENT( out, 0, 1, e01 );
65
+
66
+ SET_ELEMENT( out, 1, 0, e10 );
67
+ SET_ELEMENT( out, 1, 1, e11 );
68
+ }
69
+
70
+ void
71
+ RMtx2Zero( RMtx2* out )
72
+ {
73
+ int row, col;
74
+ for ( row = 0; row < 2; ++row )
75
+ for ( col = 0; col < 2; ++col )
76
+ SET_ELEMENT( out, row, col, 0.0f );
77
+ }
78
+
79
+ void
80
+ RMtx2Identity( RMtx2* out )
81
+ {
82
+ int row, col;
83
+ for ( row = 0; row < 2; ++row )
84
+ for ( col = 0; col < 2; ++col )
85
+ SET_ELEMENT( out, row, col, (row==col) ? 1.0f : 0.0f );
86
+ }
87
+
88
+ rmReal
89
+ RMtx2Determinant( const RMtx2* in )
90
+ {
91
+ #define I( r, c ) GET_ELEMENT( in, (r), (c) )
92
+ #define D( e00, e01, e10, e11 ) ((e00)*(e11)-(e01)*(e10))
93
+
94
+ return D( I(0,0), I(0,1), I(1,0), I(1,1) );
95
+
96
+ #undef I
97
+ #undef D
98
+ }
99
+
100
+ void
101
+ RMtx2Transpose( RMtx2* out, const RMtx2* in )
102
+ {
103
+ int row, col;
104
+ RMtx2 tmp;
105
+ for ( row = 0; row < 2; ++row )
106
+ for ( col = 0; col < 2; ++col )
107
+ SET_ELEMENT( &tmp, row, col, GET_ELEMENT( in, col, row ) );
108
+
109
+ RMtx2Copy( out, &tmp );
110
+ }
111
+
112
+ rmReal
113
+ RMtx2Inverse( RMtx2* out, const RMtx2* in )
114
+ {
115
+ #define I( r, c ) GET_ELEMENT( in, (r), (c) )
116
+ #define R( r, c ) GET_ELEMENT( &result, (r), (c) )
117
+ #define D( e00, e01, e10, e11 ) ((e00)*(e11)-(e01)*(e10))
118
+
119
+ RMtx2 result;
120
+ rmReal det;
121
+
122
+ det = D( I(0,0), I(0,1), I(1,0), I(1,1) );
123
+
124
+ if ( rmFabs(det) < RMATH_TOLERANCE )
125
+ return det;
126
+
127
+ SET_ELEMENT( &result, 0, 0, I(1,1) );
128
+ SET_ELEMENT( &result, 0, 1, -I(0,1) );
129
+
130
+ SET_ELEMENT( &result, 1, 0, -I(1,0) );
131
+ SET_ELEMENT( &result, 1, 1, I(0,0) );
132
+
133
+ RMtx2Scale( out, &result, 1.0f / det );
134
+
135
+ return det;
136
+
137
+ #undef I
138
+ #undef R
139
+ #undef D
140
+ }
141
+
142
+
143
+ /* http://en.wikipedia.org/wiki/Rotation_representation_%28mathematics%29
144
+ http://en.wikipedia.org/wiki/Rotation_matrix
145
+ */
146
+ void
147
+ RMtx2Rotation( RMtx2* out, rmReal radian )
148
+ {
149
+ rmReal s = rmSin( radian );
150
+ rmReal c = rmCos( radian );
151
+
152
+ RMtx2Identity( out );
153
+ SET_ELEMENT( out, 0, 0, c );
154
+ SET_ELEMENT( out, 0, 1, -s );
155
+ SET_ELEMENT( out, 1, 0, s );
156
+ SET_ELEMENT( out, 1, 1, c );
157
+ }
158
+
159
+ void
160
+ RMtx2Scaling( RMtx2* out, rmReal sx, rmReal sy )
161
+ {
162
+ RMtx2Identity( out );
163
+ SET_ELEMENT( out, 0, 0, sx );
164
+ SET_ELEMENT( out, 1, 1, sy );
165
+ }
166
+
167
+
168
+ int
169
+ RMtx2Equal( const RMtx2* m1, const RMtx2* m2 )
170
+ {
171
+ if ( 0 == memcmp( m1, m2, sizeof(RMtx2) ) )
172
+ return !0;
173
+ else
174
+ return 0;
175
+ }
176
+
177
+
178
+ void
179
+ RMtx2Add( RMtx2* out, const RMtx2* m1, const RMtx2* m2 )
180
+ {
181
+ int row, col;
182
+ RMtx2 tmp;
183
+ for ( row = 0; row < 2; ++row )
184
+ for ( col = 0; col < 2; ++col )
185
+ SET_ELEMENT( &tmp, row, col,
186
+ GET_ELEMENT( m1, row, col ) + GET_ELEMENT( m2, row, col ) );
187
+
188
+ RMtx2Copy( out, &tmp );
189
+ }
190
+
191
+ void
192
+ RMtx2Sub( RMtx2* out, const RMtx2* m1, const RMtx2* m2 )
193
+ {
194
+ int row, col;
195
+ for ( row = 0; row < 2; ++row )
196
+ for ( col = 0; col < 2; ++col )
197
+ SET_ELEMENT( out, row, col,
198
+ GET_ELEMENT( m1, row, col ) - GET_ELEMENT( m2, row, col ) );
199
+ }
200
+
201
+ void
202
+ RMtx2Mul( RMtx2* out, const RMtx2* m1, const RMtx2* m2 )
203
+ {
204
+ int row, col;
205
+ RMtx2 tmp;
206
+ for ( row = 0; row < 2; ++row )
207
+ {
208
+ for ( col = 0; col < 2; ++col )
209
+ {
210
+ int i;
211
+ rmReal sum = 0.0f;
212
+ for ( i = 0; i < 2; ++i )
213
+ {
214
+ sum += GET_ELEMENT( m1, row, i ) * GET_ELEMENT( m2, i, col );
215
+ }
216
+ SET_ELEMENT( &tmp, row, col, sum );
217
+ }
218
+ }
219
+
220
+ RMtx2Copy( out, &tmp );
221
+ }
222
+
223
+ void
224
+ RMtx2Scale( RMtx2* out, const RMtx2* m, rmReal f )
225
+ {
226
+ int row, col;
227
+ for ( row = 0; row < 2; ++row )
228
+ for ( col = 0; col < 2; ++col )
229
+ SET_ELEMENT( out, row, col,
230
+ GET_ELEMENT( m, row, col ) * f );
231
+ }
232
+
233
+ /*
234
+ RMath : Ruby math module for 3D Applications
235
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
236
+
237
+ This software is provided 'as-is', without any express or implied
238
+ warranty. In no event will the authors be held liable for any damages
239
+ arising from the use of this software.
240
+
241
+ Permission is granted to anyone to use this software for any purpose,
242
+ including commercial applications, and to alter it and redistribute it
243
+ freely, subject to the following restrictions:
244
+
245
+ 1. The origin of this software must not be misrepresented; you must not
246
+ claim that you wrote the original software. If you use this software
247
+ in a product, an acknowledgment in the product documentation would be
248
+ appreciated but is not required.
249
+
250
+ 2. Altered source versions must be plainly marked as such, and must not be
251
+ misrepresented as being the original software.
252
+
253
+ 3. This notice may not be removed or altered from any source
254
+ distribution.
255
+ */
@@ -0,0 +1,88 @@
1
+ /* -*- C -*- */
2
+ #ifndef RMATHMTX2_H_INCLUDED
3
+ #define RMATHMTX2_H_INCLUDED
4
+
5
+ #include "RType.h"
6
+
7
+ struct RVec2;
8
+
9
+ typedef struct RMtx2
10
+ {
11
+ union
12
+ {
13
+ /* NOTE : column-major */
14
+ struct
15
+ {
16
+ rmReal e00, e10;
17
+ rmReal e01, e11;
18
+ };
19
+ rmReal e[4];
20
+ };
21
+ } RMtx2;
22
+
23
+ #ifdef __cplusplus
24
+ extern "C" {
25
+ #endif
26
+
27
+ void RMtx2SetElements( RMtx2* out,
28
+ rmReal e00, rmReal e01,
29
+ rmReal e10, rmReal e11
30
+ );
31
+
32
+ void RMtx2SetElement( RMtx2* out, int row, int col, rmReal e );
33
+ rmReal RMtx2GetElement( const RMtx2* in, int row, int col );
34
+
35
+ void RMtx2GetRow( struct RVec2* out, const RMtx2* in, int row );
36
+ void RMtx2GetColumn( struct RVec2* out, const RMtx2* in, int col );
37
+
38
+ void RMtx2SetRow( struct RMtx2* out, const RVec2* in, int row );
39
+ void RMtx2SetColumn( struct RMtx2* out, const RVec2* in, int col );
40
+
41
+ void RMtx2Copy( RMtx2* out, const RMtx2* in );
42
+
43
+ void RMtx2Zero( RMtx2* out );
44
+ void RMtx2Identity( RMtx2* out );
45
+ rmReal RMtx2Determinant( const RMtx2* in );
46
+ void RMtx2Transpose( RMtx2* out, const RMtx2* in );
47
+ rmReal RMtx2Inverse( RMtx2* out, const RMtx2* in );
48
+
49
+ void RMtx2Rotation( RMtx2* out, rmReal radian );
50
+ void RMtx2Scaling( RMtx2* out, rmReal sx, rmReal sy );
51
+
52
+ int RMtx2Equal( const RMtx2* m1, const RMtx2* m2 );
53
+
54
+ void RMtx2Add( RMtx2* out, const RMtx2* m1, const RMtx2* m2 );
55
+ void RMtx2Sub( RMtx2* out, const RMtx2* m1, const RMtx2* m2 );
56
+ void RMtx2Mul( RMtx2* out, const RMtx2* m1, const RMtx2* m2 );
57
+ void RMtx2Scale( RMtx2* out, const RMtx2* m, rmReal f );
58
+
59
+ #ifdef __cplusplus
60
+ }
61
+ #endif
62
+
63
+
64
+ #endif
65
+
66
+ /*
67
+ RMath : Ruby math module for 3D Applications
68
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
69
+
70
+ This software is provided 'as-is', without any express or implied
71
+ warranty. In no event will the authors be held liable for any damages
72
+ arising from the use of this software.
73
+
74
+ Permission is granted to anyone to use this software for any purpose,
75
+ including commercial applications, and to alter it and redistribute it
76
+ freely, subject to the following restrictions:
77
+
78
+ 1. The origin of this software must not be misrepresented; you must not
79
+ claim that you wrote the original software. If you use this software
80
+ in a product, an acknowledgment in the product documentation would be
81
+ appreciated but is not required.
82
+
83
+ 2. Altered source versions must be plainly marked as such, and must not be
84
+ misrepresented as being the original software.
85
+
86
+ 3. This notice may not be removed or altered from any source
87
+ distribution.
88
+ */