rmath3d 1.1.0 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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]
@@ -1,4 +1,4 @@
1
- begin
1
+ begin
2
2
  require 'rmath3d/rmath3d'
3
3
  rescue LoadError
4
4
  require 'rmath3d/rmath3d_plain'
@@ -485,6 +485,29 @@ class TC_RMtx4 < Minitest::Test
485
485
  end
486
486
  end
487
487
 
488
+ def test_lookAtLH
489
+ pEye = RVec3.new( 10, 10, 10 )
490
+ vDir = ( RVec3.new(0,0,0) - pEye ).normalize! # staring at (0,0,0)
491
+ vUp = RVec3.new( 0, 1, 0 )
492
+ vRight = RVec3.cross( vUp, vDir ).normalize!
493
+ vUp = RVec3.cross( vDir, vRight ).normalize!
494
+
495
+ m0 = RMtx4.new( vRight.x, vRight.y, vRight.z, -RVec3.dot(pEye,vRight),
496
+ vUp.x, vUp.y, vUp.z, -RVec3.dot(pEye,vUp),
497
+ vDir.x, vDir.y, vDir.z, -RVec3.dot(pEye,vDir),
498
+ 0.0, 0.0, 0.0, 1.0 )
499
+
500
+ m1 = RMtx4.new.lookAtLH( RVec3.new(10,10,10), # posistion
501
+ RVec3.new(0,0,0), # at
502
+ RVec3.new(0,1,0) ) # up
503
+
504
+ for r in 0...4 do
505
+ for c in 0...4 do
506
+ assert_in_delta( m0.getElement(r,c), m1.getElement(r,c), @tolerance )
507
+ end
508
+ end
509
+ end
510
+
488
511
  def test_lookAtRH
489
512
  pEye = RVec3.new( 10, 10, 10 )
490
513
  vDir = ( pEye - RVec3.new(0,0,0) ).normalize! # staring at (0,0,0)
@@ -526,7 +549,7 @@ class TC_RMtx4 < Minitest::Test
526
549
  0.0, 2*z_n/height, 0.0, 0.0,
527
550
  0.0, 0.0, -(z_f+z_n)/(z_f-z_n), -2.0*z_f*z_n / (z_f-z_n),
528
551
  0.0, 0.0, -1.0, 0.0 )
529
- m1 = RMtx4.new.perspectiveRH( width, height, z_n, z_f )
552
+ m1 = RMtx4.new.perspectiveRH( width, height, z_n, z_f, true )
530
553
 
531
554
  for r in 0...4 do
532
555
  for c in 0...4 do
@@ -540,15 +563,15 @@ class TC_RMtx4 < Minitest::Test
540
563
  fovy = 2.0 * Math::atan( (height/2.0) / z_n )
541
564
  f = 1.0/Math::tan( fovy/2.0 )
542
565
 
543
- m2 = RMtx4.new( f/aspect, 0.0, 0.0, 0.0,
544
- 0.0, f, 0.0, 0.0,
545
- 0.0, 0.0, (z_f+z_n)/(z_n-z_f), 2*z_f*z_n/(z_n-z_f),
546
- 0.0, 0.0, -1.0, 0.0 )
547
- m3 = RMtx4.new.perspectiveFovRH( fovy, aspect, z_n, z_f );
566
+ m2 = RMtx4.new( f/aspect, 0.0, 0.0, 0.0,
567
+ 0.0, f, 0.0, 0.0,
568
+ 0.0, 0.0, -(z_f+z_n)/(z_f-z_n), -2*z_f*z_n/(z_f-z_n),
569
+ 0.0, 0.0, -1.0, 0.0 )
570
+ m3 = RMtx4.new.perspectiveFovRH( fovy, aspect, z_n, z_f, true );
548
571
 
549
572
  for r in 0...4 do
550
573
  for c in 0...4 do
551
- assert_in_delta( m2.getElement(r,c), m2.getElement(r,c), @tolerance )
574
+ assert_in_delta( m2.getElement(r,c), m3.getElement(r,c), @tolerance )
552
575
  end
553
576
  end
554
577
 
@@ -563,7 +586,68 @@ class TC_RMtx4 < Minitest::Test
563
586
  0.0, 0.0, c, d,
564
587
  0.0, 0.0, -1.0, 0.0 )
565
588
 
566
- m5 = RMtx4.new.perspectiveOffCenterRH( left, right, bottom, top, z_n, z_f )
589
+ m5 = RMtx4.new.perspectiveOffCenterRH( left, right, bottom, top, z_n, z_f, true )
590
+
591
+ for r in 0...4 do
592
+ for c in 0...4 do
593
+ assert_in_delta( m4.getElement(r,c), m5.getElement(r,c), @tolerance )
594
+ end
595
+ end
596
+ end
597
+
598
+ def test_perspectiveLH
599
+ left = -640.0
600
+ right = 640.0
601
+ bottom = -360.0
602
+ top = 360.0
603
+ z_n = 1.0
604
+ z_f = 1000.0
605
+ width = right - left
606
+ height = top - bottom
607
+ aspect = width/height
608
+
609
+ # RMtx4#perspectiveLH
610
+ m0 = RMtx4.new( 2*z_n/width, 0.0, 0.0, 0.0,
611
+ 0.0, 2*z_n/height, 0.0, 0.0,
612
+ 0.0, 0.0, (z_f+z_n)/(z_f-z_n), -2.0*z_f*z_n / (z_f-z_n),
613
+ 0.0, 0.0, 1.0, 0.0 )
614
+ m1 = RMtx4.new.perspectiveLH( width, height, z_n, z_f, true )
615
+
616
+ for r in 0...4 do
617
+ for c in 0...4 do
618
+ assert_in_delta( m0.getElement(r,c), m1.getElement(r,c), @tolerance )
619
+ end
620
+ end
621
+
622
+ # RMtx4#perspectiveFovLH
623
+
624
+ # [NOTE] tan(fovy/2) == (height/2)/z_n
625
+ fovy = 2.0 * Math::atan( (height/2.0) / z_n )
626
+ f = 1.0/Math::tan( fovy/2.0 )
627
+
628
+ m2 = RMtx4.new( f/aspect, 0.0, 0.0, 0.0,
629
+ 0.0, f, 0.0, 0.0,
630
+ 0.0, 0.0, (z_f+z_n)/(z_f-z_n), -2.0*z_f*z_n/(z_f-z_n),
631
+ 0.0, 0.0, 1.0, 0.0 )
632
+ m3 = RMtx4.new.perspectiveFovLH( fovy, aspect, z_n, z_f, true );
633
+ for r in 0...4 do
634
+ for c in 0...4 do
635
+ assert_in_delta( m2.getElement(r,c), m3.getElement(r,c), @tolerance )
636
+ end
637
+ end
638
+
639
+ # RMtx4#perspectiveOffCenterLH
640
+
641
+ a = (right+left)/(right-left)
642
+ b = (top+bottom)/(top-bottom)
643
+ c = -(z_f+z_n)/(z_f-z_n)
644
+ d = -2.0*z_f*z_n/(z_f-z_n)
645
+ m4 = RMtx4.new( 2*z_n/(right-left), 0.0, -a, 0.0,
646
+ 0.0, 2*z_n/(top-bottom), -b, 0.0,
647
+ 0.0, 0.0, -c, d,
648
+ 0.0, 0.0, 1.0, 0.0 )
649
+
650
+ m5 = RMtx4.new.perspectiveOffCenterLH( left, right, bottom, top, z_n, z_f, true )
567
651
 
568
652
  for r in 0...4 do
569
653
  for c in 0...4 do
@@ -584,14 +668,14 @@ class TC_RMtx4 < Minitest::Test
584
668
  height = top - bottom
585
669
 
586
670
  # RMtx4#orthoRH
587
- tx = (right+left)/width
588
- ty = (top+bottom)/height
589
- tz = (z_f+z_n)/(z_f-z_n)
671
+ tx = -(right+left)/width
672
+ ty = -(top+bottom)/height
673
+ tz = -(z_f+z_n)/(z_f-z_n)
590
674
  m0 = RMtx4.new( 2.0/width, 0.0, 0.0, tx,
591
675
  0.0, 2.0/height, 0.0, ty,
592
676
  0.0, 0.0, -2.0/(z_f-z_n), tz,
593
677
  0.0, 0.0, 0.0, 1.0 )
594
- m1 = RMtx4.new.orthoRH( width, height, z_n, z_f )
678
+ m1 = RMtx4.new.orthoRH( width, height, z_n, z_f, true )
595
679
 
596
680
  for r in 0...4 do
597
681
  for c in 0...4 do
@@ -600,14 +684,57 @@ class TC_RMtx4 < Minitest::Test
600
684
  end
601
685
 
602
686
  # RMtx4#orthoOffCenterRH
603
- tx = (right+left)/(right-left)
604
- ty = (top+bottom)/(top-bottom)
605
- tz = (z_f+z_n)/(z_f-z_n)
687
+ tx = -(right+left)/(right-left)
688
+ ty = -(top+bottom)/(top-bottom)
689
+ tz = -(z_f+z_n)/(z_f-z_n)
606
690
  m2 = RMtx4.new( 2.0/(right-left), 0.0, 0.0, tx,
607
691
  0.0, 2.0/(top-bottom), 0.0, ty,
608
692
  0.0, 0.0, -2.0/(z_f-z_n), tz,
609
693
  0.0, 0.0, 0.0, 1.0 )
610
- m3 = RMtx4.new.orthoOffCenterRH( left, right, bottom, top, z_n, z_f )
694
+ m3 = RMtx4.new.orthoOffCenterRH( left, right, bottom, top, z_n, z_f, true )
695
+
696
+ for r in 0...4 do
697
+ for c in 0...4 do
698
+ assert_in_delta( m2.getElement(r,c), m3.getElement(r,c), @tolerance )
699
+ end
700
+ end
701
+ end
702
+
703
+ def test_orthoLH
704
+ left = -640.0
705
+ right = 640.0
706
+ bottom = -360.0
707
+ top = 360.0
708
+ z_n = 1.0
709
+ z_f = 1000.0
710
+ width = right - left
711
+ height = top - bottom
712
+
713
+ # RMtx4#orthoLH
714
+ tx = -(right+left)/width
715
+ ty = -(top+bottom)/height
716
+ tz = -(z_f+z_n)/(z_f-z_n)
717
+ m0 = RMtx4.new( 2.0/width, 0.0, 0.0, tx,
718
+ 0.0, 2.0/height, 0.0, ty,
719
+ 0.0, 0.0, 2.0/(z_f-z_n), tz,
720
+ 0.0, 0.0, 0.0, 1.0 )
721
+ m1 = RMtx4.new.orthoLH( width, height, z_n, z_f, true )
722
+
723
+ for r in 0...4 do
724
+ for c in 0...4 do
725
+ assert_in_delta( m0.getElement(r,c), m1.getElement(r,c), @tolerance )
726
+ end
727
+ end
728
+
729
+ # RMtx4#orthoOffCenterLH
730
+ tx = -(right+left)/(right-left)
731
+ ty = -(top+bottom)/(top-bottom)
732
+ tz = -(z_f+z_n)/(z_f-z_n)
733
+ m2 = RMtx4.new( 2.0/(right-left), 0.0, 0.0, tx,
734
+ 0.0, 2.0/(top-bottom), 0.0, ty,
735
+ 0.0, 0.0, 2.0/(z_f-z_n), tz,
736
+ 0.0, 0.0, 0.0, 1.0 )
737
+ m3 = RMtx4.new.orthoOffCenterLH( left, right, bottom, top, z_n, z_f, true )
611
738
 
612
739
  for r in 0...4 do
613
740
  for c in 0...4 do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmath3d
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - vaiorabbit
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-12 00:00:00.000000000 Z
11
+ date: 2020-07-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Provides vector2/3/4, matrix2x2/3x3/4x4 and quaternion in C extension library form (and plain Ruby form with the same interface for debugging use).
@@ -56,9 +56,9 @@ files:
56
56
  - test/test_RVec4.rb
57
57
  homepage: https://github.com/vaiorabbit/rmath3d
58
58
  licenses:
59
- - zlib/libpng
59
+ - Zlib
60
60
  metadata: {}
61
- post_install_message:
61
+ post_install_message:
62
62
  rdoc_options: []
63
63
  require_paths:
64
64
  - lib
@@ -66,16 +66,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: 2.4.0
70
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  requirements: []
76
- rubyforge_project:
77
- rubygems_version: 2.4.6
78
- signing_key:
76
+ rubygems_version: 3.1.2
77
+ signing_key:
79
78
  specification_version: 4
80
79
  summary: Ruby Math Module for 3D Applications
81
80
  test_files: []