geo3d 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -4
- data/lib/geo3d/version.rb +1 -1
- data/lib/matrix.rb +21 -1
- data/lib/triangle.rb +8 -8
- data/spec/opengl/matrix_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3462d13ff5931e068cd063b2bfeafe32a2f4b17
|
4
|
+
data.tar.gz: 1e9791d44fb25bd1f490a60240ca6136fa464cdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 945c70f63e01ef6be80054858899c924e383d116148b6e2b4a6b9ac7b3f24d684d6d283bd80a929fb66dec62a161942ed2f0b6334394317465a86c2bdb1965b4
|
7
|
+
data.tar.gz: a69c83d5ad537b48d77eff2441bd89889bf4066557bdfda975af972cbcfc57b1c6ab8cac449261ff79a1e5f10bbfff6f9892a542ec83ce79d5fcbf56b3062817
|
data/README.md
CHANGED
@@ -164,16 +164,18 @@ Rotation
|
|
164
164
|
angle = 0.9
|
165
165
|
Geo3d::Matrix.rotation axis, angle #rotate about an arbitrary axis
|
166
166
|
```
|
167
|
-
Projection matrix constructors ala Direct3D (clip space has a range of 0 to 1)
|
167
|
+
Projection matrix constructors ala Direct3D (clip space of z coordinate has a range of 0 to 1)
|
168
168
|
```
|
169
169
|
Geo3d::Matrix.perspective_fov_rh fovy, aspect, z_near, z_far #returns a right handed perspective projection matrix
|
170
170
|
Geo3d::Matrix.perspective_fov_lh fovy, aspect, z_near, z_far #returns a left handed perspective projection matrix
|
171
171
|
Geo3d::Matrix.ortho_off_center_rh left, right, bottom, top, z_near, z_far #returns a right handed orthographic projection matrix
|
172
172
|
Geo3d::Matrix.ortho_off_center_lh left, right, bottom, top, z_near, z_far #returns a left handed orthographic projection matrix
|
173
173
|
```
|
174
|
-
Projection matrix constructors ala OpenGL (clip space has a range of -1 to 1)
|
174
|
+
Projection matrix constructors ala OpenGL (clip space of z coordinate has a range of -1 to 1)
|
175
175
|
```
|
176
|
-
Geo3d::Matrix.glu_perspective_degrees fovy, aspect, zn, zf #returns an opengl style right handed projection matrix
|
176
|
+
Geo3d::Matrix.glu_perspective_degrees fovy, aspect, zn, zf #returns an opengl style right handed perspective projection matrix
|
177
|
+
Geo3d::Matrix.gl_frustum l, r, b, t, zn, zf #returns an opengl style right handed perspective projection matrix
|
178
|
+
Geo3d::Matrix.gl_ortho l, r, b, t, zn, zf #returns an opengl style righthanded orthographic projection matrix
|
177
179
|
```
|
178
180
|
View matrix constructors
|
179
181
|
```
|
@@ -300,7 +302,18 @@ Constructors
|
|
300
302
|
|
301
303
|
```
|
302
304
|
|
303
|
-
|
305
|
+
|
306
|
+
## Triangle
|
307
|
+
|
308
|
+
Represents a triangle in three dimensional space
|
309
|
+
|
310
|
+
Constructors
|
311
|
+
```
|
312
|
+
Geo3d::Triangle.from_axis rotation_axis, radians #returns a quaternion from an axis and angle
|
313
|
+
Geo3d::Quaternion.from_matrix m #returns a quaternion from a rotation matrix
|
314
|
+
Geo3d::Quaternion.identity #returns the identity quaternion
|
315
|
+
|
316
|
+
```
|
304
317
|
|
305
318
|
|
306
319
|
|
data/lib/geo3d/version.rb
CHANGED
data/lib/matrix.rb
CHANGED
@@ -471,7 +471,7 @@ module Geo3d
|
|
471
471
|
matrix = self.new
|
472
472
|
matrix._11 = 2.0 * zn / (r-l)
|
473
473
|
matrix._31 = a
|
474
|
-
matrix._22 = zn / (t-b)
|
474
|
+
matrix._22 = zn / (t-b) #todo: the man page says multiply this by two, but I don't actually match what glFrustum does if I do
|
475
475
|
matrix._32 = b
|
476
476
|
matrix._33 = c
|
477
477
|
matrix._43 = d
|
@@ -479,6 +479,8 @@ module Geo3d
|
|
479
479
|
matrix
|
480
480
|
end
|
481
481
|
|
482
|
+
|
483
|
+
|
482
484
|
def self.perspective_fov_rh fovy, aspect, zn, zf
|
483
485
|
fovy = fovy.to_f
|
484
486
|
aspect = aspect.to_f
|
@@ -511,6 +513,24 @@ module Geo3d
|
|
511
513
|
matrix
|
512
514
|
end
|
513
515
|
|
516
|
+
def self.gl_ortho l, r, b, t, zn, zf
|
517
|
+
l = l.to_f
|
518
|
+
r = r.to_f
|
519
|
+
b = b.to_f
|
520
|
+
t = t.to_f
|
521
|
+
zn = zn.to_f
|
522
|
+
zf = zf.to_f
|
523
|
+
matrix = self.new
|
524
|
+
matrix._11 = 2.0 / (r-l)
|
525
|
+
matrix._22 = 2.0 / (t-b)
|
526
|
+
matrix._33 = -2.0 / (zf - zn)
|
527
|
+
matrix._41 = -(r+l) / (r-l)
|
528
|
+
matrix._42 = -(t+b) / (t-b)
|
529
|
+
matrix._43 = -(zf+zn) / (zf-zn)
|
530
|
+
matrix._44 = 1.0
|
531
|
+
matrix
|
532
|
+
end
|
533
|
+
|
514
534
|
def self.ortho_off_center_rh l, r, b, t, zn, zf
|
515
535
|
l = l.to_f
|
516
536
|
r = r.to_f
|
data/lib/triangle.rb
CHANGED
@@ -6,10 +6,10 @@ module Geo3d
|
|
6
6
|
[a, b, c]
|
7
7
|
end
|
8
8
|
|
9
|
-
def initialize
|
10
|
-
@a = Vector.new
|
11
|
-
@b = Vector.new
|
12
|
-
@c = Vector.new
|
9
|
+
def initialize *args
|
10
|
+
@a = args.size > 0 ? args[0] : Vector.new
|
11
|
+
@b = args.size > 1 ? args[1] : Vector.new
|
12
|
+
@c = args.size > 2 ? args[2] : Vector.new
|
13
13
|
end
|
14
14
|
|
15
15
|
def flip!
|
@@ -35,12 +35,12 @@ module Geo3d
|
|
35
35
|
reference_normal.dot(sum) / 2.0
|
36
36
|
end
|
37
37
|
|
38
|
-
def clockwise?
|
39
|
-
signed_area > 0
|
38
|
+
def clockwise? reference_normal = Vector.new(0,0,-1)
|
39
|
+
signed_area( reference_normal ) > 0
|
40
40
|
end
|
41
41
|
|
42
|
-
def counter_clockwise?
|
43
|
-
signed_area < 0
|
42
|
+
def counter_clockwise? reference_normal = Vector.new(0,0,-1)
|
43
|
+
signed_area( reference_normal ) < 0
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
data/spec/opengl/matrix_spec.rb
CHANGED
@@ -69,6 +69,20 @@ describe Geo3d::Matrix do
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
+
it "gl_ortho should be equivalent to opengl glOrtho" do
|
73
|
+
[{:l => -2, :r => 2, :b => -2, :t => 2, :zn => 1, :zf => 1000},
|
74
|
+
{:l => -231, :r => 453, :b => -232, :t => 2786, :zn => 9.221, :zf => 10000}].each do |data|
|
75
|
+
glMatrixMode GL_PROJECTION
|
76
|
+
glLoadIdentity
|
77
|
+
glOrtho data[:l], data[:r], data[:b], data[:t], data[:zn], data[:zf]
|
78
|
+
|
79
|
+
gl_version = Geo3d::Matrix.new *(glGetFloatv(GL_PROJECTION_MATRIX).flatten)
|
80
|
+
geo3d_matrix = Geo3d::Matrix.gl_ortho data[:l], data[:r], data[:b], data[:t], data[:zn], data[:zf]
|
81
|
+
|
82
|
+
gl_version.should == geo3d_matrix
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
72
86
|
it "should multiply matrices the same way opengl does" do
|
73
87
|
10000.times do
|
74
88
|
a_values = (0..15).to_a.map do |i|
|
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.
|
4
|
+
version: 0.1.1
|
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-
|
11
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|