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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: dc8123d1ad73cb760f30d7c6a3496f13ad54fcb1
4
- data.tar.gz: 41ae8b2437dfe3fdc2b0ec6c01fc511a0e5ada20
2
+ SHA256:
3
+ metadata.gz: 9e8d8b8a38ad55ec12170a103c39607b841855790e279ae4c003e394900f3391
4
+ data.tar.gz: 8d74d4f0917015c74accd26293cb4036d9befa0bbe0d562893a324881a1b005f
5
5
  SHA512:
6
- metadata.gz: 39615da4c1208ebfdb06644ce2a6612ed88172afc334c36eb9a08b20211c3fb89359bcdb4e348924fd09fad057745397774be8f3de00e211373a98c6cc6ab11c
7
- data.tar.gz: 7e6b01b7f44b95ccb8f2c8a9419d74f730ef1bd6eac59afa7dc128c1e5cfa6ffb171cd151957a8d6d41a4fcbc987ebae63487bb0b30c5299513c936c7179f205
6
+ metadata.gz: c6ea5c48fba49380581ae07cef869767a73ab1e3f2d8bda7481b352241bf3bd82197a188d529bf230ec786dedb35bb9a49145d430b54f298729598f7b3ba6702
7
+ data.tar.gz: b02fb89b9fbb8fe9bc1dd3456ef99507d4d1d1e659b3a2884243ea5342100bca7bee219550e6764e15e43c352cf4561bea5615db56827c2d9365596e9e098802
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).
@@ -1,5 +1,5 @@
1
1
  rmath3d : Ruby math module for 3D Applications
2
- Copyright (c) 2008-2017 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,9 +4,12 @@
4
4
 
5
5
  rmath3d is a math module for 3D game programming and computer graphics.
6
6
 
7
- * Last Update: Jul 22, 2017
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 ###
@@ -14,7 +14,7 @@
14
14
 
15
15
  /*
16
16
  RMath : Ruby math module for 3D Applications
17
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>
17
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
18
18
 
19
19
  This software is provided 'as-is', without any express or implied
20
20
  warranty. In no event will the authors be held liable for any damages
@@ -232,7 +232,7 @@ RMtx2Scale( RMtx2* out, const RMtx2* m, rmReal f )
232
232
 
233
233
  /*
234
234
  RMath : Ruby math module for 3D Applications
235
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>
235
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
236
236
 
237
237
  This software is provided 'as-is', without any express or implied
238
238
  warranty. In no event will the authors be held liable for any damages
@@ -65,7 +65,7 @@ void RMtx2Scale( RMtx2* out, const RMtx2* m, rmReal f );
65
65
 
66
66
  /*
67
67
  RMath : Ruby math module for 3D Applications
68
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>
68
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
69
69
 
70
70
  This software is provided 'as-is', without any express or implied
71
71
  warranty. In no event will the authors be held liable for any damages
@@ -347,7 +347,7 @@ RMtx3Scale( RMtx3* out, const RMtx3* m, rmReal f )
347
347
 
348
348
  /*
349
349
  RMath : Ruby math module for 3D Applications
350
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>
350
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
351
351
 
352
352
  This software is provided 'as-is', without any express or implied
353
353
  warranty. In no event will the authors be held liable for any damages
@@ -72,7 +72,7 @@ void RMtx3Scale( RMtx3* out, const RMtx3* m, rmReal f );
72
72
 
73
73
  /*
74
74
  RMath : Ruby math module for 3D Applications
75
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>
75
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
76
76
 
77
77
  This software is provided 'as-is', without any express or implied
78
78
  warranty. In no event will the authors be held liable for any damages
@@ -479,37 +479,42 @@ RMtx4LookAtRH( RMtx4* out, const RVec3* eye, const RVec3* at, const RVec3* up )
479
479
  }
480
480
 
481
481
  void
482
- RMtx4PerspectiveRH( RMtx4* out, rmReal width, rmReal height, rmReal znear, rmReal zfar )
482
+ RMtx4PerspectiveRH( RMtx4* out, rmReal width, rmReal height, rmReal znear, rmReal zfar, bool ndc_homogeneous )
483
483
  {
484
- RMtx4PerspectiveOffCenterRH( out, -width/2.0f, width/2.0f, -height/2.0f, height/2.0f, znear, zfar );
484
+ RMtx4PerspectiveOffCenterRH( out, -width/2.0f, width/2.0f, -height/2.0f, height/2.0f, znear, zfar, ndc_homogeneous );
485
485
  }
486
486
 
487
- /* http://pyopengl.sourceforge.net/documentation/manual/gluPerspective.3G.html
487
+ /* https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluPerspective.xml
488
+ Game Programming in C++ (2018) https://www.oreilly.com/library/view/game-programming-in/9780134598185/
488
489
  */
489
490
  void
490
- RMtx4PerspectiveFovRH( RMtx4* out, rmReal fovy_radian, rmReal aspect, rmReal znear, rmReal zfar )
491
+ RMtx4PerspectiveFovRH( RMtx4* out, rmReal fovy_radian, rmReal aspect, rmReal znear, rmReal zfar, bool ndc_homogeneous )
491
492
  {
492
493
  rmReal f = rmTan( fovy_radian / 2.0f );
493
494
  f = 1.0f / f;
494
495
 
496
+ rmReal C = ndc_homogeneous ? -(zfar+znear) / (zfar-znear) : zfar / -(zfar-znear);
497
+ rmReal D = ndc_homogeneous ? -(2*znear*zfar) / (zfar-znear) : -(znear*zfar) / (zfar-znear);
498
+
495
499
  RMtx4Identity( out );
496
500
  SET_ELEMENT( out, 0, 0, f / aspect );
497
501
  SET_ELEMENT( out, 1, 1, f );
498
- SET_ELEMENT( out, 2, 2, (zfar+znear)/(znear-zfar) );
499
- SET_ELEMENT( out, 2, 3, 2*zfar*znear/(znear-zfar) );
502
+ SET_ELEMENT( out, 2, 2, C );
503
+ SET_ELEMENT( out, 2, 3, D );
500
504
  SET_ELEMENT( out, 3, 2, -1.0f );
501
505
  SET_ELEMENT( out, 3, 3, 0.0f );
502
506
  }
503
507
 
504
- /* http://pyopengl.sourceforge.net/documentation/manual/glFrustum.3G.html
508
+ /* https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glFrustum.xml
509
+ Game Programming in C++ (2018) https://www.oreilly.com/library/view/game-programming-in/9780134598185/
505
510
  */
506
511
  void
507
- RMtx4PerspectiveOffCenterRH( RMtx4* out, rmReal left, rmReal right, rmReal bottom, rmReal top, rmReal znear, rmReal zfar )
512
+ RMtx4PerspectiveOffCenterRH( RMtx4* out, rmReal left, rmReal right, rmReal bottom, rmReal top, rmReal znear, rmReal zfar, bool ndc_homogeneous )
508
513
  {
509
514
  rmReal A = (right+left) / (right-left);
510
515
  rmReal B = (top+bottom) / (top-bottom);
511
- rmReal C = -(zfar+znear) / (zfar-znear);
512
- rmReal D = -(2*znear*zfar) / (zfar-znear);
516
+ rmReal C = ndc_homogeneous ? -(zfar+znear) / (zfar-znear) : -zfar / (zfar-znear);
517
+ rmReal D = ndc_homogeneous ? -(2*znear*zfar) / (zfar-znear) : -(znear*zfar) / (zfar-znear);
513
518
 
514
519
  RMtx4Identity( out );
515
520
  SET_ELEMENT( out, 0, 0, 2*znear/(right-left) );
@@ -523,33 +528,34 @@ RMtx4PerspectiveOffCenterRH( RMtx4* out, rmReal left, rmReal right, rmReal botto
523
528
  }
524
529
 
525
530
  void
526
- RMtx4OrthoRH( RMtx4* out, rmReal width, rmReal height, rmReal znear, rmReal zfar )
531
+ RMtx4OrthoRH( RMtx4* out, rmReal width, rmReal height, rmReal znear, rmReal zfar, bool ndc_homogeneous )
527
532
  {
528
- RMtx4OrthoOffCenterRH( out, -width/2.0f, width/2.0f, -height/2.0f, height/2.0f, znear, zfar );
533
+ RMtx4OrthoOffCenterRH( out, -width/2.0f, width/2.0f, -height/2.0f, height/2.0f, znear, zfar, ndc_homogeneous );
529
534
  }
530
535
 
531
- /* http://pyopengl.sourceforge.net/documentation/manual/glOrtho.3G.html
536
+ /* https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glOrtho.xml
537
+ Game Programming in C++ (2018) https://www.oreilly.com/library/view/game-programming-in/9780134598185/
532
538
  */
533
539
  void
534
- RMtx4OrthoOffCenterRH( RMtx4* out, rmReal left, rmReal right, rmReal bottom, rmReal top, rmReal znear, rmReal zfar )
540
+ RMtx4OrthoOffCenterRH( RMtx4* out, rmReal left, rmReal right, rmReal bottom, rmReal top, rmReal znear, rmReal zfar, bool ndc_homogeneous )
535
541
  {
536
- rmReal tx = (right+left) / (right-left);
537
- rmReal ty = (top+bottom) / (top-bottom);
538
- rmReal tz = (zfar+znear) / (zfar-znear);
542
+ rmReal tx = -(right+left) / (right-left);
543
+ rmReal ty = -(top+bottom) / (top-bottom);
544
+ rmReal tz = ndc_homogeneous ? -(zfar+znear) / (zfar-znear) : -znear / (zfar-znear);
539
545
 
540
546
  RMtx4Identity( out );
541
547
  SET_ELEMENT( out, 0, 0, 2.0f/(right-left) );
542
548
  SET_ELEMENT( out, 0, 3, tx );
543
549
  SET_ELEMENT( out, 1, 1, 2.0f/(top-bottom) );
544
550
  SET_ELEMENT( out, 1, 3, ty );
545
- SET_ELEMENT( out, 2, 2, -2.0f/(zfar-znear) );
551
+ SET_ELEMENT( out, 2, 2, -(ndc_homogeneous ? 2.0f : 1.0f)/(zfar-znear) );
546
552
  SET_ELEMENT( out, 2, 3, tz );
547
553
  }
548
554
 
549
555
 
550
556
  /*
551
557
  RMath : Ruby math module for 3D Applications
552
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>
558
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
553
559
 
554
560
  This software is provided 'as-is', without any express or implied
555
561
  warranty. In no event will the authors be held liable for any damages
@@ -2,6 +2,7 @@
2
2
  #ifndef RMATHMTX4_H_INCLUDED
3
3
  #define RMATHMTX4_H_INCLUDED
4
4
 
5
+ #include <stdbool.h>
5
6
  #include "RType.h"
6
7
 
7
8
  struct RVec3;
@@ -71,11 +72,11 @@ void RMtx4Mul( RMtx4* out, const RMtx4* m1, const RMtx4* m2 );
71
72
  void RMtx4Scale( RMtx4* out, const RMtx4* m, rmReal f );
72
73
 
73
74
  void RMtx4LookAtRH( RMtx4* out, const struct RVec3* eye, const struct RVec3* at, const struct RVec3* up );
74
- void RMtx4PerspectiveRH( RMtx4* out, rmReal width, rmReal height, rmReal znear, rmReal zfar );
75
- void RMtx4PerspectiveFovRH( RMtx4* out, rmReal fovy_radian, rmReal aspect, rmReal znear, rmReal zfar );
76
- void RMtx4PerspectiveOffCenterRH( RMtx4* out, rmReal left, rmReal right, rmReal bottom, rmReal top, rmReal znear, rmReal zfar );
77
- void RMtx4OrthoRH( RMtx4* out, rmReal width, rmReal height, rmReal znear, rmReal zfar );
78
- void RMtx4OrthoOffCenterRH( RMtx4* out, rmReal left, rmReal right, rmReal bottom, rmReal top, rmReal znear, rmReal zfar );
75
+ void RMtx4PerspectiveRH( RMtx4* out, rmReal width, rmReal height, rmReal znear, rmReal zfar, bool ndc_homogeneous );
76
+ void RMtx4PerspectiveFovRH( RMtx4* out, rmReal fovy_radian, rmReal aspect, rmReal znear, rmReal zfar, bool ndc_homogeneous );
77
+ void RMtx4PerspectiveOffCenterRH( RMtx4* out, rmReal left, rmReal right, rmReal bottom, rmReal top, rmReal znear, rmReal zfar, bool ndc_homogeneous );
78
+ void RMtx4OrthoRH( RMtx4* out, rmReal width, rmReal height, rmReal znear, rmReal zfar, bool ndc_homogeneous );
79
+ void RMtx4OrthoOffCenterRH( RMtx4* out, rmReal left, rmReal right, rmReal bottom, rmReal top, rmReal znear, rmReal zfar, bool ndc_homogeneous );
79
80
 
80
81
  #ifdef __cplusplus
81
82
  }
@@ -87,7 +88,7 @@ void RMtx4OrthoOffCenterRH( RMtx4* out, rmReal left, rmReal right, rmReal bot
87
88
 
88
89
  /*
89
90
  RMath : Ruby math module for 3D Applications
90
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>
91
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
91
92
 
92
93
  This software is provided 'as-is', without any express or implied
93
94
  warranty. In no event will the authors be held liable for any damages
@@ -344,7 +344,7 @@ RQuatToAxisAngle( const RQuat* in, struct RVec3* axis, rmReal* radian )
344
344
 
345
345
  /*
346
346
  RMath : Ruby math module for 3D Applications
347
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>
347
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
348
348
 
349
349
  This software is provided 'as-is', without any express or implied
350
350
  warranty. In no event will the authors be held liable for any damages
@@ -69,7 +69,7 @@ void RQuatToAxisAngle( const RQuat* in, struct RVec3* axis, rmReal* radian );
69
69
 
70
70
  /*
71
71
  RMath : Ruby math module for 3D Applications
72
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>
72
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
73
73
 
74
74
  This software is provided 'as-is', without any express or implied
75
75
  warranty. In no event will the authors be held liable for any damages
@@ -53,7 +53,7 @@ typedef double rmReal;
53
53
 
54
54
  /*
55
55
  RMath : Ruby math module for 3D Applications
56
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>
56
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
57
57
 
58
58
  This software is provided 'as-is', without any express or implied
59
59
  warranty. In no event will the authors be held liable for any damages
@@ -144,7 +144,7 @@ RVec2Transform( RVec2* out, const RMtx2* m, const RVec2* in )
144
144
 
145
145
  /*
146
146
  RMath : Ruby math module for 3D Applications
147
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>.
147
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>.
148
148
 
149
149
  This software is provided 'as-is', without any express or implied
150
150
  warranty. In no event will the authors be held liable for any damages
@@ -57,7 +57,7 @@ void RVec2Transform( struct RVec2* out, const struct RMtx2* m, const RVec2* i
57
57
 
58
58
  /*
59
59
  RMath : Ruby math module for 3D Applications
60
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>
60
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
61
61
 
62
62
  This software is provided 'as-is', without any express or implied
63
63
  warranty. In no event will the authors be held liable for any damages
@@ -262,7 +262,7 @@ RVec3TransformByQuaternion( RVec3* out, const struct RQuat* q, const RVec3* in )
262
262
 
263
263
  /*
264
264
  RMath : Ruby math module for 3D Applications
265
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>.
265
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>.
266
266
 
267
267
  This software is provided 'as-is', without any express or implied
268
268
  warranty. In no event will the authors be held liable for any damages
@@ -66,7 +66,7 @@ void RVec3TransformByQuaternion( RVec3* out, const struct RQuat* q, const RVe
66
66
 
67
67
  /*
68
68
  RMath : Ruby math module for 3D Applications
69
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>
69
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
70
70
 
71
71
  This software is provided 'as-is', without any express or implied
72
72
  warranty. In no event will the authors be held liable for any damages
@@ -192,7 +192,7 @@ RVec4TransformTransposed( RVec4* out, const struct RMtx4* m, const RVec4* in )
192
192
 
193
193
  /*
194
194
  RMath : Ruby math module for 3D Applications
195
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>
195
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
196
196
 
197
197
  This software is provided 'as-is', without any express or implied
198
198
  warranty. In no event will the authors be held liable for any damages
@@ -63,7 +63,7 @@ void RVec4TransformTransposed( RVec4* out, const struct RMtx4* m, const RVec4
63
63
 
64
64
  /*
65
65
  RMath : Ruby math module for 3D Applications
66
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>
66
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
67
67
 
68
68
  This software is provided 'as-is', without any express or implied
69
69
  warranty. In no event will the authors be held liable for any damages
@@ -258,7 +258,7 @@ RMtx2_initialize( int argc, VALUE* argv, VALUE self )
258
258
 
259
259
  default:
260
260
  {
261
- rb_raise( rb_eRuntimeError, "RMtx2_initialize : wrong # of arguments (%d)", argc );
261
+ rb_raise( rb_eArgError, "RMtx2_initialize : wrong # of arguments (%d)", argc );
262
262
  return Qnil;
263
263
  }
264
264
  break;
@@ -377,7 +377,7 @@ RMtx2_setElements( int argc, VALUE* argv, VALUE self )
377
377
  #ifdef RMATH_ENABLE_ARGUMENT_CHECK
378
378
  if ( argc != 4 )
379
379
  {
380
- rb_raise( rb_eRuntimeError, "RMtx2_setElements : wrong # of arguments (%d)", argc );
380
+ rb_raise( rb_eArgError, "RMtx2_setElements : wrong # of arguments (%d)", argc );
381
381
  return Qnil;
382
382
  }
383
383
  #endif
@@ -1139,7 +1139,7 @@ RMtx3_initialize( int argc, VALUE* argv, VALUE self )
1139
1139
 
1140
1140
  default:
1141
1141
  {
1142
- rb_raise( rb_eRuntimeError, "RMtx3_initialize : wrong # of arguments (%d)", argc );
1142
+ rb_raise( rb_eArgError, "RMtx3_initialize : wrong # of arguments (%d)", argc );
1143
1143
  return Qnil;
1144
1144
  }
1145
1145
  break;
@@ -1258,7 +1258,7 @@ RMtx3_setElements( int argc, VALUE* argv, VALUE self )
1258
1258
  #ifdef RMATH_ENABLE_ARGUMENT_CHECK
1259
1259
  if ( argc != 9 )
1260
1260
  {
1261
- rb_raise( rb_eRuntimeError, "RMtx3_setElements : wrong # of arguments (%d)", argc );
1261
+ rb_raise( rb_eArgError, "RMtx3_setElements : wrong # of arguments (%d)", argc );
1262
1262
  return Qnil;
1263
1263
  }
1264
1264
  #endif
@@ -2227,7 +2227,7 @@ RMtx4_initialize( int argc, VALUE* argv, VALUE self )
2227
2227
 
2228
2228
  default:
2229
2229
  {
2230
- rb_raise( rb_eRuntimeError, "RMtx4_initialize : wrong # of arguments (%d)", argc );
2230
+ rb_raise( rb_eArgError, "RMtx4_initialize : wrong # of arguments (%d)", argc );
2231
2231
  return Qnil;
2232
2232
  }
2233
2233
  break;
@@ -2348,7 +2348,7 @@ RMtx4_setElements( int argc, VALUE* argv, VALUE self )
2348
2348
  #ifdef RMATH_ENABLE_ARGUMENT_CHECK
2349
2349
  if ( argc != 16 )
2350
2350
  {
2351
- rb_raise( rb_eRuntimeError, "RMtx4_setElements : wrong # of arguments (%d)", argc );
2351
+ rb_raise( rb_eArgError, "RMtx4_setElements : wrong # of arguments (%d)", argc );
2352
2352
  return Qnil;
2353
2353
  }
2354
2354
  #endif
@@ -3247,59 +3247,81 @@ RMtx4_lookAtRH( VALUE self, VALUE e, VALUE a, VALUE u )
3247
3247
  }
3248
3248
 
3249
3249
  /*
3250
- * call-seq: perspectiveRH(width,height,znear,zfar) -> self
3250
+ * call-seq: perspectiveRH(width,height,znear,zfar,ndc_homogeneous) -> self
3251
3251
  *
3252
3252
  * Builds a perspective projection matrix for a right-handed coordinate system from:
3253
3253
  * * View volume width (+width+)
3254
3254
  * * View volume height (+height+)
3255
3255
  * * Near clip plane distance (+znear+)
3256
3256
  * * Far clip plane distance (+zfar+)
3257
+ * * Set true for the environment with Z coordinate ranges from -1 to +1 (OpenGL), and false otherwise (Direct3D, Metal) (+ndc_homogeneous+)
3257
3258
  */
3258
3259
  static VALUE
3259
- RMtx4_perspectiveRH( VALUE self, VALUE w, VALUE h, VALUE zn, VALUE zf )
3260
+ RMtx4_perspectiveRH( int argc, VALUE* argv, VALUE self )
3260
3261
  {
3262
+ VALUE w, h, zn, zf, ndch;
3261
3263
  RMtx4* m = NULL;
3262
3264
  rmReal width, height, znear, zfar;
3265
+ bool ndc_homogeneous;
3266
+
3267
+ if (argc < 4 || argc > 5)
3268
+ {
3269
+ rb_raise(rb_eArgError, "RMtx4_perspectiveRH : wrong # of arguments (%d)", argc );
3270
+ }
3271
+
3272
+ rb_scan_args(argc, argv, "41", &w, &h, &zn, &zf, &ndch);
3263
3273
 
3264
3274
  TypedData_Get_Struct( self, RMtx4, &RMtx4_type, m );
3265
3275
  width = NUM2DBL(w);
3266
3276
  height = NUM2DBL(h);
3267
3277
  znear = NUM2DBL(zn);
3268
3278
  zfar = NUM2DBL(zf);
3279
+ ndc_homogeneous = NIL_P(ndch) ? true : ((ndch == Qtrue) ? true : false);
3269
3280
 
3270
- RMtx4PerspectiveRH( m, width, height, znear, zfar );
3281
+ RMtx4PerspectiveRH( m, width, height, znear, zfar, ndc_homogeneous );
3271
3282
 
3272
3283
  return self;
3273
3284
  }
3274
3285
 
3275
3286
  /*
3276
- * call-seq: perspectiveFovRH(fovy,aspect,znear,zfar) -> self
3287
+ * call-seq: perspectiveFovRH(fovy,aspect,znear,zfar,ndc_homogeneous) -> self
3277
3288
  *
3278
3289
  * Builds a perspective projection matrix for a right-handed coordinate system from:
3279
3290
  * * Field of view in y direction (+fovy+ radian)
3280
3291
  * * Aspect ratio (+aspect+)
3281
3292
  * * Near clip plane distance (+znear+)
3282
3293
  * * Far clip plane distance (+zfar+)
3294
+ * * Set true for the environment with Z coordinate ranges from -1 to +1 (OpenGL), and false otherwise (Direct3D, Metal) (+ndc_homogeneous+)
3283
3295
  */
3284
3296
  static VALUE
3285
- RMtx4_perspectiveFovRH( VALUE self, VALUE fovy, VALUE asp, VALUE zn, VALUE zf )
3297
+ RMtx4_perspectiveFovRH( int argc, VALUE* argv, VALUE self )
3286
3298
  {
3299
+ VALUE fovy, asp, zn, zf, ndch;
3287
3300
  RMtx4* m = NULL;
3288
3301
  rmReal fovy_radian, aspect, znear, zfar;
3302
+ bool ndc_homogeneous;
3303
+
3304
+ if (argc < 4 || argc > 5)
3305
+ {
3306
+ rb_raise(rb_eArgError, "RMtx4_perspectiveFovRH : wrong # of arguments (%d)", argc );
3307
+ }
3308
+
3309
+ rb_scan_args(argc, argv, "41", &fovy, &asp, &zn, &zf, &ndch);
3289
3310
 
3290
3311
  TypedData_Get_Struct( self, RMtx4, &RMtx4_type, m );
3291
3312
  fovy_radian = NUM2DBL(fovy);
3292
3313
  aspect = NUM2DBL(asp);
3293
3314
  znear = NUM2DBL(zn);
3294
3315
  zfar = NUM2DBL(zf);
3316
+ ndc_homogeneous = NIL_P(ndch) ? true : ((ndch == Qtrue) ? true : false);
3295
3317
 
3296
- RMtx4PerspectiveFovRH( m, fovy_radian, aspect, znear, zfar );
3318
+ RMtx4PerspectiveFovRH( m, fovy_radian, aspect, znear, zfar, ndc_homogeneous );
3297
3319
 
3298
3320
  return self;
3299
3321
  }
3300
3322
 
3301
3323
  /*
3302
- * call-seq: perspectiveOffCenterRH(left,right,bottom,top,znear,zfar) -> self
3324
+ * call-seq: perspectiveOffCenterRH(left,right,bottom,top,znear,zfar,ndc_homogeneous) -> self
3303
3325
  *
3304
3326
  * Builds a perspective projection matrix for a right-handed coordinate system from:
3305
3327
  * * Minimum value of the view volume width (+left+)
@@ -3308,12 +3330,22 @@ RMtx4_perspectiveFovRH( VALUE self, VALUE fovy, VALUE asp, VALUE zn, VALUE zf )
3308
3330
  * * Maximum value of the view volume height (+top+)
3309
3331
  * * Near clip plane distance (+znear+)
3310
3332
  * * Far clip plane distance (+zfar+)
3333
+ * * Set true for the environment with Z coordinate ranges from -1 to +1 (OpenGL), and false otherwise (Direct3D, Metal) (+ndc_homogeneous+)
3311
3334
  */
3312
3335
  static VALUE
3313
- RMtx4_perspectiveOffCenterRH( VALUE self, VALUE l, VALUE r, VALUE b, VALUE t, VALUE zn, VALUE zf )
3336
+ RMtx4_perspectiveOffCenterRH( int argc, VALUE* argv, VALUE self )
3314
3337
  {
3338
+ VALUE l, r, b, t, zn, zf, ndch;
3315
3339
  RMtx4* m = NULL;
3316
3340
  rmReal left, right, bottom, top, znear, zfar;
3341
+ bool ndc_homogeneous;
3342
+
3343
+ if (argc < 6 || argc > 7)
3344
+ {
3345
+ rb_raise(rb_eArgError, "RMtx4_perspectiveOffCenterRH : wrong # of arguments (%d)", argc );
3346
+ }
3347
+
3348
+ rb_scan_args(argc, argv, "61", &l, &r, &b, &t, &zn, &zf, &ndch);
3317
3349
 
3318
3350
  TypedData_Get_Struct( self, RMtx4, &RMtx4_type, m );
3319
3351
  left = NUM2DBL(l);
@@ -3322,39 +3354,52 @@ RMtx4_perspectiveOffCenterRH( VALUE self, VALUE l, VALUE r, VALUE b, VALUE t, VA
3322
3354
  top = NUM2DBL(t);
3323
3355
  znear = NUM2DBL(zn);
3324
3356
  zfar = NUM2DBL(zf);
3325
- RMtx4PerspectiveOffCenterRH( m, left, right, bottom, top, znear, zfar );
3357
+ ndc_homogeneous = NIL_P(ndch) ? true : ((ndch == Qtrue) ? true : false);
3358
+
3359
+ RMtx4PerspectiveOffCenterRH( m, left, right, bottom, top, znear, zfar, ndc_homogeneous );
3326
3360
 
3327
3361
  return self;
3328
3362
  }
3329
3363
 
3330
3364
  /*
3331
- * call-seq: orthoRH(width,height,znear,zfar) -> self
3365
+ * call-seq: orthoRH(width,height,znear,zfar,ndc_homogeneous) -> self
3332
3366
  *
3333
3367
  * Builds a orthogonal projection matrix for a right-handed coordinate system from:
3334
3368
  * * View volume width (+width+)
3335
3369
  * * View volume height (+height+)
3336
3370
  * * Near clip plane distance (+znear+)
3337
3371
  * * Far clip plane distance (+zfar+)
3372
+ * * Set true for the environment with Z coordinate ranges from -1 to +1 (OpenGL), and false otherwise (Direct3D, Metal) (+ndc_homogeneous+)
3338
3373
  */
3339
3374
  static VALUE
3340
- RMtx4_orthoRH( VALUE self, VALUE w, VALUE h, VALUE zn, VALUE zf )
3375
+ RMtx4_orthoRH( int argc, VALUE* argv, VALUE self )
3341
3376
  {
3377
+ VALUE w, h, zn, zf, ndch;
3342
3378
  RMtx4* m = NULL;
3343
3379
  rmReal width, height, znear, zfar;
3380
+ bool ndc_homogeneous;
3381
+
3382
+ if (argc < 4 || argc > 5)
3383
+ {
3384
+ rb_raise(rb_eArgError, "RMtx4_orthoRH : wrong # of arguments (%d)", argc );
3385
+ }
3386
+
3387
+ rb_scan_args(argc, argv, "41", &w, &h, &zn, &zf, &ndch);
3344
3388
 
3345
3389
  TypedData_Get_Struct( self, RMtx4, &RMtx4_type, m );
3346
3390
  width = NUM2DBL(w);
3347
3391
  height = NUM2DBL(h);
3348
3392
  znear = NUM2DBL(zn);
3349
3393
  zfar = NUM2DBL(zf);
3394
+ ndc_homogeneous = NIL_P(ndch) ? true : ((ndch == Qtrue) ? true : false);
3350
3395
 
3351
- RMtx4OrthoRH( m, width, height, znear, zfar );
3396
+ RMtx4OrthoRH( m, width, height, znear, zfar, ndc_homogeneous );
3352
3397
 
3353
3398
  return self;
3354
3399
  }
3355
3400
 
3356
3401
  /*
3357
- * call-seq: orthoOffCenterRH(left,right,bottom,top,znear,zfar) -> self
3402
+ * call-seq: orthoOffCenterRH(left,right,bottom,top,znear,zfar,ndc_homogeneous) -> self
3358
3403
  *
3359
3404
  * Builds a orthogonal projection matrix for a right-handed coordinate system from:
3360
3405
  * * Minimum value of the view volume width (+left+)
@@ -3363,12 +3408,22 @@ RMtx4_orthoRH( VALUE self, VALUE w, VALUE h, VALUE zn, VALUE zf )
3363
3408
  * * Maximum value of the view volume height (+top+)
3364
3409
  * * Near clip plane distance (+znear+)
3365
3410
  * * Far clip plane distance (+zfar+)
3411
+ * * Set true for the environment with Z coordinate ranges from -1 to +1 (OpenGL), and false otherwise (Direct3D, Metal) (+ndc_homogeneous+)
3366
3412
  */
3367
3413
  static VALUE
3368
- RMtx4_orthoOffCenterRH( VALUE self, VALUE l, VALUE r, VALUE b, VALUE t, VALUE zn, VALUE zf )
3414
+ RMtx4_orthoOffCenterRH( int argc, VALUE* argv, VALUE self )
3369
3415
  {
3416
+ VALUE l, r, b, t, zn, zf, ndch;
3370
3417
  RMtx4* m = NULL;
3371
3418
  rmReal left, right, bottom, top, znear, zfar;
3419
+ bool ndc_homogeneous;
3420
+
3421
+ if (argc < 6 || argc > 7)
3422
+ {
3423
+ rb_raise(rb_eArgError, "RMtx4_orthoOffCenterRH : wrong # of arguments (%d)", argc );
3424
+ }
3425
+
3426
+ rb_scan_args(argc, argv, "61", &l, &r, &b, &t, &zn, &zf, &ndch);
3372
3427
 
3373
3428
  TypedData_Get_Struct( self, RMtx4, &RMtx4_type, m );
3374
3429
  left = NUM2DBL(l);
@@ -3377,7 +3432,9 @@ RMtx4_orthoOffCenterRH( VALUE self, VALUE l, VALUE r, VALUE b, VALUE t, VALUE zn
3377
3432
  top = NUM2DBL(t);
3378
3433
  znear = NUM2DBL(zn);
3379
3434
  zfar = NUM2DBL(zf);
3380
- RMtx4OrthoOffCenterRH( m, left, right, bottom, top, znear, zfar );
3435
+ ndc_homogeneous = NIL_P(ndch) ? true : ((ndch == Qtrue) ? true : false);
3436
+
3437
+ RMtx4OrthoOffCenterRH( m, left, right, bottom, top, znear, zfar, ndc_homogeneous );
3381
3438
 
3382
3439
  return self;
3383
3440
  }
@@ -3734,7 +3791,7 @@ RQuat_initialize( int argc, VALUE* argv, VALUE self )
3734
3791
 
3735
3792
  default:
3736
3793
  {
3737
- rb_raise( rb_eRuntimeError, "RQuat_initialize : wrong # of arguments (%d)", argc );
3794
+ rb_raise( rb_eArgError, "RQuat_initialize : wrong # of arguments (%d)", argc );
3738
3795
  return Qnil;
3739
3796
  }
3740
3797
  break;
@@ -4692,7 +4749,7 @@ RVec2_initialize( int argc, VALUE* argv, VALUE self )
4692
4749
 
4693
4750
  default:
4694
4751
  {
4695
- rb_raise( rb_eRuntimeError, "RVec2_initialize : wrong # of arguments (%d)", argc );
4752
+ rb_raise( rb_eArgError, "RVec2_initialize : wrong # of arguments (%d)", argc );
4696
4753
  return Qnil;
4697
4754
  }
4698
4755
  break;
@@ -5392,7 +5449,7 @@ RVec3_initialize( int argc, VALUE* argv, VALUE self )
5392
5449
 
5393
5450
  default:
5394
5451
  {
5395
- rb_raise( rb_eRuntimeError, "RVec3_initialize : wrong # of arguments (%d)", argc );
5452
+ rb_raise( rb_eArgError, "RVec3_initialize : wrong # of arguments (%d)", argc );
5396
5453
  return Qnil;
5397
5454
  }
5398
5455
  break;
@@ -6353,7 +6410,7 @@ RVec4_initialize( int argc, VALUE* argv, VALUE self )
6353
6410
 
6354
6411
  default:
6355
6412
  {
6356
- rb_raise( rb_eRuntimeError, "RVec4_initialize : wrong # of arguments (%d)", argc );
6413
+ rb_raise( rb_eArgError, "RVec4_initialize : wrong # of arguments (%d)", argc );
6357
6414
  return Qnil;
6358
6415
  }
6359
6416
  break;
@@ -7324,11 +7381,11 @@ Init_rmath3d()
7324
7381
  rb_define_method( rb_cRMtx4, "scaling", RMtx4_scaling, 3 );
7325
7382
 
7326
7383
  rb_define_method( rb_cRMtx4, "lookAtRH", RMtx4_lookAtRH, 3 );
7327
- rb_define_method( rb_cRMtx4, "perspectiveRH", RMtx4_perspectiveRH, 4 );
7328
- rb_define_method( rb_cRMtx4, "perspectiveFovRH", RMtx4_perspectiveFovRH, 4 );
7329
- rb_define_method( rb_cRMtx4, "perspectiveOffCenterRH", RMtx4_perspectiveOffCenterRH, 6 );
7330
- rb_define_method( rb_cRMtx4, "orthoRH", RMtx4_orthoRH, 4 );
7331
- rb_define_method( rb_cRMtx4, "orthoOffCenterRH", RMtx4_orthoOffCenterRH, 6 );
7384
+ rb_define_method( rb_cRMtx4, "perspectiveRH", RMtx4_perspectiveRH, -1 );
7385
+ rb_define_method( rb_cRMtx4, "perspectiveFovRH", RMtx4_perspectiveFovRH, -1 );
7386
+ rb_define_method( rb_cRMtx4, "perspectiveOffCenterRH", RMtx4_perspectiveOffCenterRH, -1 );
7387
+ rb_define_method( rb_cRMtx4, "orthoRH", RMtx4_orthoRH, -1 );
7388
+ rb_define_method( rb_cRMtx4, "orthoOffCenterRH", RMtx4_orthoOffCenterRH, -1 );
7332
7389
 
7333
7390
  rb_define_method( rb_cRMtx4, "+@", RMtx4_op_unary_plus, 0 );
7334
7391
  rb_define_method( rb_cRMtx4, "-@", RMtx4_op_unary_minus, 0 );
@@ -7544,7 +7601,7 @@ Init_rmath3d()
7544
7601
 
7545
7602
  /*
7546
7603
  RMath : Ruby math module for 3D Applications
7547
- Copyright (c) 2008-2017 vaiorabbit <http://twitter.com/vaiorabbit>
7604
+ Copyright (c) 2008-2020 vaiorabbit <http://twitter.com/vaiorabbit>
7548
7605
 
7549
7606
  This software is provided 'as-is', without any express or implied
7550
7607
  warranty. In no event will the authors be held liable for any damages