geo3d 0.1.3 → 0.1.4

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
2
  SHA1:
3
- metadata.gz: 1dce039052c8be50a88c59d44885cc4673bb9995
4
- data.tar.gz: 8c8e0c900000eff135456ec98ff9360d50d39c31
3
+ metadata.gz: 232252be56a981c2f600a5b56cbed43329059f87
4
+ data.tar.gz: 1b0f57fc159cd4a00a57badeb0d96c1429e79d42
5
5
  SHA512:
6
- metadata.gz: ebf820b44fea39262570b2345e6cabc0ba21ce0bf2e0a7be420a4873afb850d76b30611a8ccee5ec8b05d8dac9428aa46e69fd8b784519ef80a0a89f7f1d314b
7
- data.tar.gz: efc8897b94f0f45ae833ac230f86dcb6ad1ca83f7254b877fc04817ea27cac6b667c26e9cb82963c1da2631bcac93e2f8c09b0243c54e61c61581cfdbfdd6c3a
6
+ metadata.gz: 5080591b0755271ef5bb5f5024d81ffeeb69cb9bf7621a4ade23f4371856b0ce7c4266a6db7d5ee1e230fe9b768d4b41973314d15b0f0e26ad8e15663b787b3d
7
+ data.tar.gz: 0b5bdc014bf23de2d8551403b3fe2083c19b953edb6e45c84bf5549e2049f8ec652921ba87653bcd816e7d797f61759238914f3b436daf2ad7a503ebcd53d2d8
data/README.md CHANGED
@@ -92,6 +92,14 @@ Screenspace projections
92
92
  vec.project viewport, projection, view, world #transform an objectspace vertex to screenspace
93
93
  vec.unproject viewport, projection, view, world #transform a screenspace vertex to objectspace
94
94
  ```
95
+ Reflections
96
+ ```
97
+ vec.reflect normal, incident
98
+ ```
99
+ Refractions
100
+ ```
101
+ vec.refract normal, incident, index_of_refraction
102
+ ```
95
103
 
96
104
  ## Matrix
97
105
 
data/lib/geo3d/matrix.rb CHANGED
@@ -268,7 +268,7 @@ module Geo3d
268
268
  scaling = scaling_component
269
269
  return nil if scaling.x.zero? || scaling.y.zero? || scaling.z.zero?
270
270
  m = Matrix.new
271
- m._11=_11 / scaling.x
271
+ m._11=_11/scaling.x
272
272
  m._12=_12/scaling.x
273
273
  m._13=_13/scaling.x
274
274
  m._21=_21/scaling.y
data/lib/geo3d/vector.rb CHANGED
@@ -34,7 +34,7 @@ module Geo3d
34
34
  end
35
35
 
36
36
  def xyz
37
- self.class.new x, y, z
37
+ self.class.new x, y, z, 0
38
38
  end
39
39
 
40
40
  def to_s
@@ -126,6 +126,23 @@ module Geo3d
126
126
  almost_objectspace_vector = (projection * view * world).inverse * normalized_clipspace_vector.one_w
127
127
  (almost_objectspace_vector / almost_objectspace_vector.w).one_w
128
128
  end
129
+
130
+ def self.reflect normal, incident
131
+ s = 2.0 * normal.xyz.dot(incident.xyz)
132
+ (incident - normal * s).xyz
133
+ end
134
+
135
+ def self.refract normal, incident, index_of_refraction
136
+ t = incident.xyz.dot normal.xyz
137
+ r = 1.0 - index_of_refraction * index_of_refraction * (1.0 - t*t)
138
+
139
+ if r < 0.0 # Total internal reflection
140
+ self.new 0, 0, 0, 0
141
+ else
142
+ s = index_of_refraction * t + Math.sqrt(r)
143
+ (incident * index_of_refraction - normal * s).xyz
144
+ end
145
+ end
129
146
  end
130
147
  end
131
148
 
data/lib/geo3d/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Geo3d
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -21,10 +21,10 @@ describe Geo3d::Vector do
21
21
  end
22
22
 
23
23
  it "should support cross products with other vectors" do
24
- [{:a => [1,0,0,0], :b => [0,1,0,0], :expected => [0,0,1,0] },
25
- {:a => [1,0,0,1], :b => [0,1,0,1], :expected => [0,0,1,0] },
26
- {:a => [1,1,1,1], :b => [1,1,1,1], :expected => [0,0,0,0] },
27
- {:a => [2,99,6,0], :b => [-11,-91,77,0], :expected => [8169.000000, -220.000000, 907.000000, 0.000000] }].each do |data|
24
+ [{:a => [1, 0, 0, 0], :b => [0, 1, 0, 0], :expected => [0, 0, 1, 0]},
25
+ {:a => [1, 0, 0, 1], :b => [0, 1, 0, 1], :expected => [0, 0, 1, 0]},
26
+ {:a => [1, 1, 1, 1], :b => [1, 1, 1, 1], :expected => [0, 0, 0, 0]},
27
+ {:a => [2, 99, 6, 0], :b => [-11, -91, 77, 0], :expected => [8169.000000, -220.000000, 907.000000, 0.000000]}].each do |data|
28
28
  a = Geo3d::Vector.new *data[:a]
29
29
  b = Geo3d::Vector.new *data[:b]
30
30
  expected = Geo3d::Vector.new *data[:expected]
@@ -64,13 +64,38 @@ describe Geo3d::Vector do
64
64
  end
65
65
 
66
66
  it "should be able to linearly interpolate" do
67
- [{:a => [0,0,0,0], :b => [1,1,1,1], :interpolate_fraction => 0.5, :expected => [0.5, 0.5, 0.5, 0.5]},
68
- {:a => [23,-3,425,-332], :b => [-22,-45443,886,122], :interpolate_fraction => 0.21234433, :expected => [13.444505, -9651.926758, 522.890747, -235.595673]}].each do |data|
67
+ [{:a => [0, 0, 0, 0], :b => [1, 1, 1, 1], :interpolate_fraction => 0.5, :expected => [0.5, 0.5, 0.5, 0.5]},
68
+ {:a => [23, -3, 425, -332], :b => [-22, -45443, 886, 122], :interpolate_fraction => 0.21234433, :expected => [13.444505, -9651.926758, 522.890747, -235.595673]}].each do |data|
69
69
  a = Geo3d::Vector.new *data[:a]
70
70
  b = Geo3d::Vector.new *data[:b]
71
71
  expected = Geo3d::Vector.new *data[:expected]
72
72
  s = data[:interpolate_fraction]
73
- a.lerp( b, s).should == expected
73
+ a.lerp(b, s).should == expected
74
+ end
75
+ end
76
+
77
+ it "should calculate reflection" do
78
+ [{:normal => [0, 1, 0], :incident => [1, 1, 0], :expected => [1, -1, 0]},
79
+ {:normal => [0, 1, 0], :incident => [0, -1, 0], :expected => [0, 1, 0]},
80
+ {:normal => [22, 33, 68], :incident => [65, -23, -23], :expected => [39357.000000, 58915.000000, 121425.000000, 0.000000]}].each do |data|
81
+ normal = Geo3d::Vector.new *data[:normal]
82
+ incident = Geo3d::Vector.new *data[:incident]
83
+ expected = Geo3d::Vector.new *data[:expected]
84
+ Geo3d::Vector.reflect(normal, incident).should == expected
85
+ end
86
+ end
87
+
88
+ it "should calculate refraction" do
89
+ [{:normal => [0, 1, 0], :incident => [1, 1, 0], :index_of_ref => 0.5, :expected => [0.5, -1, 0]},
90
+ {:normal => [0, 1, 0], :incident => [0, -1, 0], :index_of_ref => 21.345, :expected => [0, -1, 0]},
91
+ {:normal => [22, 33, 68], :incident => [65, -23, -23], :index_of_ref => 17.5678, :expected => [1142.121826, -403.737152, -403.395355]},
92
+ {:normal => [1, 0, 0], :incident => [0, 1, 0], :index_of_ref => 0.75, :expected => [-0.661438, 0.750000, 0.000000, 0.000000]}
93
+ ].each do |data|
94
+
95
+ normal = Geo3d::Vector.new *data[:normal]
96
+ incident = Geo3d::Vector.new *data[:incident]
97
+ expected = Geo3d::Vector.new *data[:expected]
98
+ Geo3d::Vector.refract(normal, incident, data[:index_of_ref]).should == expected
74
99
  end
75
100
  end
76
101
 
@@ -34,6 +34,12 @@ describe Geo3d::Matrix do
34
34
  # raise "opengl not able to initialize" unless @gl_initialized
35
35
  end
36
36
 
37
+ it "the identity constructor should be functionally equivalent to glLoadIdentity" do
38
+ glMatrixMode GL_MODELVIEW
39
+ glLoadIdentity
40
+ gl_version = Geo3d::Matrix.new *glGetFloatv(GL_MODELVIEW_MATRIX).flatten
41
+ Geo3d::Matrix.identity.should == gl_version
42
+ end
37
43
 
38
44
  it "the right handed view constructor should be functionally equivalent to gluLookAt" do
39
45
  [{:eye => [1, 0, 0], :focus => [100, 0, -100], :up => [0, 1, 0]}].each do |data|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geo3d
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Misha Conway
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-24 00:00:00.000000000 Z
11
+ date: 2014-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler