mittsu 0.3.1 → 0.4.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/build-workflow.yml +71 -0
- data/.gitignore +1 -0
- data/Gemfile +0 -3
- data/LICENSE.txt +1 -1
- data/README.md +6 -8
- data/Rakefile +1 -0
- data/install-glfw.ps1 +13 -0
- data/lib/mittsu/cameras/camera.rb +0 -2
- data/lib/mittsu/cameras/cube_camera.rb +0 -2
- data/lib/mittsu/cameras/orthographic_camera.rb +2 -4
- data/lib/mittsu/cameras/perspective_camera.rb +4 -5
- data/lib/mittsu/core/buffer_attribute.rb +12 -0
- data/lib/mittsu/core/buffer_geometry.rb +3 -3
- data/lib/mittsu/core/geometry.rb +2 -4
- data/lib/mittsu/core/object_3d.rb +9 -7
- data/lib/mittsu/core/raycaster.rb +0 -2
- data/lib/mittsu/extras/geometries/circle_geometry.rb +3 -3
- data/lib/mittsu/extras/geometries/cylinder_geometry.rb +5 -5
- data/lib/mittsu/extras/geometries/dodecahedron_geometry.rb +2 -2
- data/lib/mittsu/extras/geometries/icosahedron_geometry.rb +2 -2
- data/lib/mittsu/extras/geometries/lathe_geometry.rb +3 -3
- data/lib/mittsu/extras/geometries/parametric_geometry.rb +19 -19
- data/lib/mittsu/extras/geometries/polyhedron_geometry.rb +6 -7
- data/lib/mittsu/extras/geometries/ring_geometry.rb +4 -4
- data/lib/mittsu/extras/geometries/sphere_geometry.rb +4 -4
- data/lib/mittsu/extras/geometries/torus_geometry.rb +7 -7
- data/lib/mittsu/extras/geometries/torus_knot_buffer_geometry.rb +9 -9
- data/lib/mittsu/extras/helpers/camera_helper.rb +38 -38
- data/lib/mittsu/extras/image_utils.rb +1 -1
- data/lib/mittsu/lights/directional_light.rb +9 -5
- data/lib/mittsu/lights/spot_light.rb +1 -1
- data/lib/mittsu/loaders/loader.rb +2 -2
- data/lib/mittsu/loaders/obj_loader.rb +4 -0
- data/lib/mittsu/materials/material.rb +6 -3
- data/lib/mittsu/math/box2.rb +0 -2
- data/lib/mittsu/math/box3.rb +0 -2
- data/lib/mittsu/math/color.rb +3 -4
- data/lib/mittsu/math/euler.rb +25 -26
- data/lib/mittsu/math/frustum.rb +0 -2
- data/lib/mittsu/math/line3.rb +0 -2
- data/lib/mittsu/math/matrix3.rb +0 -2
- data/lib/mittsu/math/matrix4.rb +10 -12
- data/lib/mittsu/math/plane.rb +0 -2
- data/lib/mittsu/math/quaternion.rb +18 -20
- data/lib/mittsu/math/ray.rb +1 -3
- data/lib/mittsu/math/sphere.rb +1 -3
- data/lib/mittsu/math/spline.rb +0 -2
- data/lib/mittsu/math/triangle.rb +1 -3
- data/lib/mittsu/math/vector.rb +3 -3
- data/lib/mittsu/math/vector2.rb +0 -1
- data/lib/mittsu/math/vector3.rb +108 -1
- data/lib/mittsu/math/vector4.rb +8 -9
- data/lib/mittsu/math.rb +0 -5
- data/lib/mittsu/objects/line.rb +0 -1
- data/lib/mittsu/renderers/glfw_lib.rb +24 -3
- data/lib/mittsu/renderers/glfw_window.rb +6 -2
- data/lib/mittsu/renderers/opengl/core/object_3d.rb +1 -1
- data/lib/mittsu/renderers/opengl/lights/spot_light.rb +1 -1
- data/lib/mittsu/renderers/opengl/opengl_geometry_group.rb +1 -0
- data/lib/mittsu/renderers/opengl/opengl_program.rb +1 -2
- data/lib/mittsu/renderers/opengl/textures/texture.rb +2 -2
- data/lib/mittsu/renderers/opengl_renderer.rb +9 -14
- data/lib/mittsu/scenes/scene.rb +0 -2
- data/lib/mittsu/textures/texture.rb +4 -2
- data/lib/mittsu/utils.rb +15 -0
- data/lib/mittsu/version.rb +1 -2
- data/lib/mittsu.rb +1 -16
- data/mittsu.gemspec +14 -13
- metadata +60 -47
- data/.circleci/config.yml +0 -87
- data/.circleci/images/primary/Dockerfile +0 -10
- data/appveyor.yml +0 -23
- data/install_glfw.ps1 +0 -11
@@ -3,7 +3,7 @@ require 'mittsu/math'
|
|
3
3
|
|
4
4
|
module Mittsu
|
5
5
|
class TorusGeometry < Geometry
|
6
|
-
def initialize(radius = 100.0, tube = 40.0, radial_segments = 8, tubular_segments = 6, arc = (Math::PI * 2.0))
|
6
|
+
def initialize(radius = 100.0, tube = 40.0, radial_segments = 8, tubular_segments = 6, arc = (::Math::PI * 2.0))
|
7
7
|
super()
|
8
8
|
|
9
9
|
@type = 'TorusGeometry'
|
@@ -23,15 +23,15 @@ module Mittsu
|
|
23
23
|
for j in 0..radial_segments do
|
24
24
|
for i in 0..tubular_segments do
|
25
25
|
u = i.to_f / tubular_segments * arc
|
26
|
-
v = j.to_f / radial_segments * Math::PI * 2.0
|
26
|
+
v = j.to_f / radial_segments * ::Math::PI * 2.0
|
27
27
|
|
28
|
-
center.x = radius * Math.cos(u)
|
29
|
-
center.y = radius * Math.sin(u)
|
28
|
+
center.x = radius * ::Math.cos(u)
|
29
|
+
center.y = radius * ::Math.sin(u)
|
30
30
|
|
31
31
|
vertex = Vector3.new
|
32
|
-
vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u)
|
33
|
-
vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u)
|
34
|
-
vertex.z = tube * Math.sin(v)
|
32
|
+
vertex.x = (radius + tube * ::Math.cos(v)) * ::Math.cos(u)
|
33
|
+
vertex.y = (radius + tube * ::Math.cos(v)) * ::Math.sin(u)
|
34
|
+
vertex.z = tube * ::Math.sin(v)
|
35
35
|
|
36
36
|
@vertices << vertex
|
37
37
|
|
@@ -37,7 +37,7 @@ module Mittsu
|
|
37
37
|
|
38
38
|
for i in 0..tubular_segments do
|
39
39
|
# the radian "u" is used to calculate the position on the torus curve of the current tubular segement
|
40
|
-
u = i.to_f / tubular_segments.to_f * p_val.to_f * Math::PI * 2.0
|
40
|
+
u = i.to_f / tubular_segments.to_f * p_val.to_f * ::Math::PI * 2.0
|
41
41
|
|
42
42
|
# now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
|
43
43
|
# these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
|
@@ -57,9 +57,9 @@ module Mittsu
|
|
57
57
|
for j in 0..radial_segments do
|
58
58
|
# now calculate the vertices. they are nothing more than an extrusion of the torus curve.
|
59
59
|
# because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
|
60
|
-
v = j.to_f / radial_segments.to_f * Math::PI * 2.0
|
61
|
-
cx = -tube * Math.cos(v)
|
62
|
-
cy = tube * Math.sin(v)
|
60
|
+
v = j.to_f / radial_segments.to_f * ::Math::PI * 2.0
|
61
|
+
cx = -tube * ::Math.cos(v)
|
62
|
+
cy = tube * ::Math.sin(v)
|
63
63
|
|
64
64
|
# now calculate the final vertex position.
|
65
65
|
# first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
|
@@ -107,14 +107,14 @@ module Mittsu
|
|
107
107
|
private
|
108
108
|
|
109
109
|
def calculate_position_on_curve(u, p_val, q_val, radius, position)
|
110
|
-
cu = Math.cos(u)
|
111
|
-
su = Math.sin(u)
|
110
|
+
cu = ::Math.cos(u)
|
111
|
+
su = ::Math.sin(u)
|
112
112
|
qu_over_p = q_val.to_f / p_val.to_f * u
|
113
|
-
cs = Math.cos(qu_over_p)
|
113
|
+
cs = ::Math.cos(qu_over_p)
|
114
114
|
|
115
115
|
position.x = radius * (2.0 + cs) * 0.5 * cu
|
116
116
|
position.y = radius * (2.0 + cs) * su * 0.5
|
117
|
-
position.z = radius * Math.sin(qu_over_p) * 0.5
|
117
|
+
position.z = radius * ::Math.sin(qu_over_p) * 0.5
|
118
118
|
end
|
119
119
|
end
|
120
|
-
end
|
120
|
+
end
|
@@ -15,58 +15,58 @@ module Mittsu
|
|
15
15
|
|
16
16
|
# colors
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
hex_frustrum = 0xffaa00
|
19
|
+
hex_cone = 0xff0000
|
20
|
+
hex_up = 0x00aaff
|
21
|
+
hex_target = 0xffffff
|
22
|
+
hex_cross = 0x333333
|
23
23
|
|
24
24
|
# near
|
25
25
|
|
26
|
-
add_line(:n1, :n2,
|
27
|
-
add_line(:n2, :n4,
|
28
|
-
add_line(:n4, :n3,
|
29
|
-
add_line(:n3, :n1,
|
26
|
+
add_line(:n1, :n2, hex_frustrum)
|
27
|
+
add_line(:n2, :n4, hex_frustrum)
|
28
|
+
add_line(:n4, :n3, hex_frustrum)
|
29
|
+
add_line(:n3, :n1, hex_frustrum)
|
30
30
|
|
31
31
|
# far
|
32
32
|
|
33
|
-
add_line(:f1, :f2,
|
34
|
-
add_line(:f2, :f4,
|
35
|
-
add_line(:f4, :f3,
|
36
|
-
add_line(:f3, :f1,
|
33
|
+
add_line(:f1, :f2, hex_frustrum)
|
34
|
+
add_line(:f2, :f4, hex_frustrum)
|
35
|
+
add_line(:f4, :f3, hex_frustrum)
|
36
|
+
add_line(:f3, :f1, hex_frustrum)
|
37
37
|
|
38
38
|
# sides
|
39
39
|
|
40
|
-
add_line(:n1, :f1,
|
41
|
-
add_line(:n2, :f2,
|
42
|
-
add_line(:n3, :f3,
|
43
|
-
add_line(:n4, :f4,
|
40
|
+
add_line(:n1, :f1, hex_frustrum)
|
41
|
+
add_line(:n2, :f2, hex_frustrum)
|
42
|
+
add_line(:n3, :f3, hex_frustrum)
|
43
|
+
add_line(:n4, :f4, hex_frustrum)
|
44
44
|
|
45
45
|
# cone
|
46
46
|
|
47
|
-
add_line(:p, :n1,
|
48
|
-
add_line(:p, :n2,
|
49
|
-
add_line(:p, :n3,
|
50
|
-
add_line(:p, :n4,
|
47
|
+
add_line(:p, :n1, hex_cone)
|
48
|
+
add_line(:p, :n2, hex_cone)
|
49
|
+
add_line(:p, :n3, hex_cone)
|
50
|
+
add_line(:p, :n4, hex_cone)
|
51
51
|
|
52
52
|
# up
|
53
53
|
|
54
|
-
add_line(:u1, :u2,
|
55
|
-
add_line(:u2, :u3,
|
56
|
-
add_line(:u3, :u1,
|
54
|
+
add_line(:u1, :u2, hex_up)
|
55
|
+
add_line(:u2, :u3, hex_up)
|
56
|
+
add_line(:u3, :u1, hex_up)
|
57
57
|
|
58
58
|
# target
|
59
59
|
|
60
|
-
add_line(:c, :t,
|
61
|
-
add_line(:p, :c,
|
60
|
+
add_line(:c, :t, hex_target)
|
61
|
+
add_line(:p, :c, hex_cross)
|
62
62
|
|
63
63
|
# cross
|
64
64
|
|
65
|
-
add_line(:cn1, :cn2,
|
66
|
-
add_line(:cn3, :cn4,
|
65
|
+
add_line(:cn1, :cn2, hex_cross)
|
66
|
+
add_line(:cn3, :cn4, hex_cross)
|
67
67
|
|
68
|
-
add_line(:cf1, :cf2,
|
69
|
-
add_line(:cf3, :cf4,
|
68
|
+
add_line(:cf1, :cf2, hex_cross)
|
69
|
+
add_line(:cf3, :cf4, hex_cross)
|
70
70
|
|
71
71
|
super(@geometry, @material, LinePieces)
|
72
72
|
|
@@ -101,10 +101,10 @@ module Mittsu
|
|
101
101
|
|
102
102
|
# far
|
103
103
|
|
104
|
-
set_point(:f1, -w, -h,
|
105
|
-
set_point(:f2, w, -h,
|
106
|
-
set_point(:f3, -w, h,
|
107
|
-
set_point(:f4, w, h,
|
104
|
+
set_point(:f1, -w, -h, 1.0)
|
105
|
+
set_point(:f2, w, -h, 1.0)
|
106
|
+
set_point(:f3, -w, h, 1.0)
|
107
|
+
set_point(:f4, w, h, 1.0)
|
108
108
|
|
109
109
|
# up
|
110
110
|
|
@@ -119,10 +119,10 @@ module Mittsu
|
|
119
119
|
set_point(:cf3, 0.0, -h, 1.0)
|
120
120
|
set_point(:cf4, 0.0, h, 1.0)
|
121
121
|
|
122
|
-
set_point(:cn1, -w, 0.0, 1.0)
|
123
|
-
set_point(:cn2, w, 0.0, 1.0)
|
124
|
-
set_point(:cn3, 0.0, -h, 1.0)
|
125
|
-
set_point(:cn4, 0.0, h, 1.0)
|
122
|
+
set_point(:cn1, -w, 0.0, -1.0)
|
123
|
+
set_point(:cn2, w, 0.0, -1.0)
|
124
|
+
set_point(:cn3, 0.0, -h, -1.0)
|
125
|
+
set_point(:cn4, 0.0, h, -1.0)
|
126
126
|
|
127
127
|
@geometry.vertices_need_update = true
|
128
128
|
end
|
@@ -120,12 +120,16 @@ module Mittsu
|
|
120
120
|
light.shadow_cascade_offset.copy(@shadow_cascade_offset)
|
121
121
|
light.shadow_cascade_count = @shadow_cascade_count
|
122
122
|
|
123
|
-
|
124
|
-
|
125
|
-
|
123
|
+
light.shadow_cascade_bias = @shadow_cascade_bias.dup
|
124
|
+
light.shadow_cascade_width = @shadow_cascade_width.dup
|
125
|
+
light.shadow_cascade_height = @shadow_cascade_height.dup
|
126
126
|
|
127
|
-
|
128
|
-
|
127
|
+
light.shadow_cascade_near_z = @shadow_cascade_near_z.dup
|
128
|
+
light.shadow_cascade_far_z = @shadow_cascade_far_z.dup
|
129
|
+
end
|
130
|
+
|
131
|
+
def virtual?
|
132
|
+
false
|
129
133
|
end
|
130
134
|
|
131
135
|
protected
|
@@ -20,7 +20,7 @@ module Mittsu
|
|
20
20
|
:shadow_camera,
|
21
21
|
:shadow_matrix
|
22
22
|
|
23
|
-
def initialize(color = nil, intensity = 1.0, distance = 0.0, angle = (Math::PI / 3.0), exponent = 10.0, decay = 1.0)
|
23
|
+
def initialize(color = nil, intensity = 1.0, distance = 0.0, angle = (::Math::PI / 3.0), exponent = 10.0, decay = 1.0)
|
24
24
|
super(color)
|
25
25
|
|
26
26
|
@type = 'SpotLight'
|
@@ -151,8 +151,8 @@ module Mittsu
|
|
151
151
|
private
|
152
152
|
|
153
153
|
def nearest_pow2(n)
|
154
|
-
l = Math.log(n) / Math::LN2
|
155
|
-
Math.pow(2, Math.round(l))
|
154
|
+
l = ::Math.log(n) / Math::LN2
|
155
|
+
::Math.pow(2, ::Math.round(l))
|
156
156
|
end
|
157
157
|
|
158
158
|
def create_texture(where, name, source_file, repeat, offset, wrap, anisotropy)
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'securerandom'
|
2
|
-
require 'mittsu'
|
3
2
|
|
4
3
|
module Mittsu
|
5
4
|
class Material
|
@@ -7,9 +6,13 @@ module Mittsu
|
|
7
6
|
|
8
7
|
attr_reader :id, :uuid, :type
|
9
8
|
|
10
|
-
attr_accessor :name, :side, :opacity, :transparent, :blending, :blend_src, :blend_dst, :blend_equation, :blend_src_alpha,
|
9
|
+
attr_accessor :name, :side, :opacity, :transparent, :blending, :blend_src, :blend_dst, :blend_equation, :blend_src_alpha,
|
10
|
+
:blend_dst_alpha, :blend_equation_alpha, :depth_test, :depth_write, :color_write, :polygon_offset, :polygon_offset_factor,
|
11
|
+
:polygon_offset_units, :alpha_test, :overdraw, :visible, :attributes, :shading, :program
|
11
12
|
|
12
|
-
attr_accessor :map, :env_map, :light_map, :
|
13
|
+
attr_accessor :map, :env_map, :light_map, :normal_map, :specular_map, :alpha_map, :combine, :vertex_colors, :fog,
|
14
|
+
:size_attenuation, :skinning, :morph_targets, :morph_normals, :metal, :wrap_around, :defines, :lights, :color, :bump_map,
|
15
|
+
:reflectivity, :refraction_ratio, :wireframe, :default_attribute_values, :uniforms, :vertex_shader, :fragment_shader
|
13
16
|
|
14
17
|
def initialize
|
15
18
|
super
|
data/lib/mittsu/math/box2.rb
CHANGED
data/lib/mittsu/math/box3.rb
CHANGED
data/lib/mittsu/math/color.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'mittsu/math'
|
2
1
|
require 'mittsu/math/vector3'
|
3
2
|
|
4
3
|
module Mittsu
|
@@ -121,9 +120,9 @@ module Mittsu
|
|
121
120
|
end
|
122
121
|
|
123
122
|
def convert_linear_to_gamma
|
124
|
-
self.r = Math.sqrt(self.r)
|
125
|
-
self.g = Math.sqrt(self.g)
|
126
|
-
self.b = Math.sqrt(self.b)
|
123
|
+
self.r = ::Math.sqrt(self.r)
|
124
|
+
self.g = ::Math.sqrt(self.g)
|
125
|
+
self.b = ::Math.sqrt(self.b)
|
127
126
|
self
|
128
127
|
end
|
129
128
|
|
data/lib/mittsu/math/euler.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'mittsu/math'
|
2
|
-
|
3
1
|
module Mittsu
|
4
2
|
class Euler
|
5
3
|
RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ]
|
@@ -9,6 +7,7 @@ module Mittsu
|
|
9
7
|
|
10
8
|
def initialize(x = 0.0, y = 0.0, z = 0.0, order = DefaultOrder)
|
11
9
|
@x, @y, @z, @order = x.to_f, y.to_f, z.to_f, order
|
10
|
+
@on_change_callback = nil
|
12
11
|
end
|
13
12
|
|
14
13
|
def set(x, y, z, order = nil)
|
@@ -57,57 +56,57 @@ module Mittsu
|
|
57
56
|
m31 = te[2]; m32 = te[6]; m33 = te[10]
|
58
57
|
order = order || @order
|
59
58
|
if order == 'XYZ'
|
60
|
-
@y = Math.asin(Math.clamp(m13, -1.0, 1.0))
|
59
|
+
@y = ::Math.asin(Math.clamp(m13, -1.0, 1.0))
|
61
60
|
if m13.abs < 0.99999
|
62
|
-
@x = Math.atan2(- m23, m33)
|
63
|
-
@z = Math.atan2(- m12, m11)
|
61
|
+
@x = ::Math.atan2(- m23, m33)
|
62
|
+
@z = ::Math.atan2(- m12, m11)
|
64
63
|
else
|
65
|
-
@x = Math.atan2(m32, m22)
|
64
|
+
@x = ::Math.atan2(m32, m22)
|
66
65
|
@z = 0.0
|
67
66
|
end
|
68
67
|
elsif order == 'YXZ'
|
69
|
-
@x = Math.asin(- Math.clamp(m23, -1.0, 1.0))
|
68
|
+
@x = ::Math.asin(- Math.clamp(m23, -1.0, 1.0))
|
70
69
|
if m23.abs < 0.99999
|
71
|
-
@y = Math.atan2(m13, m33)
|
72
|
-
@z = Math.atan2(m21, m22)
|
70
|
+
@y = ::Math.atan2(m13, m33)
|
71
|
+
@z = ::Math.atan2(m21, m22)
|
73
72
|
else
|
74
|
-
@y = Math.atan2(- m31, m11)
|
73
|
+
@y = ::Math.atan2(- m31, m11)
|
75
74
|
@z = 0.0
|
76
75
|
end
|
77
76
|
elsif order == 'ZXY'
|
78
|
-
@x = Math.asin(Math.clamp(m32, -1.0, 1.0))
|
77
|
+
@x = ::Math.asin(Math.clamp(m32, -1.0, 1.0))
|
79
78
|
if m32.abs < 0.99999
|
80
|
-
@y = Math.atan2(- m31, m33)
|
81
|
-
@z = Math.atan2(- m12, m22)
|
79
|
+
@y = ::Math.atan2(- m31, m33)
|
80
|
+
@z = ::Math.atan2(- m12, m22)
|
82
81
|
else
|
83
82
|
@y = 0.0
|
84
|
-
@z = Math.atan2(m21, m11)
|
83
|
+
@z = ::Math.atan2(m21, m11)
|
85
84
|
end
|
86
85
|
elsif order == 'ZYX'
|
87
|
-
@y = Math.asin(- Math.clamp(m31, -1.0, 1.0))
|
86
|
+
@y = ::Math.asin(- Math.clamp(m31, -1.0, 1.0))
|
88
87
|
if m31.abs < 0.99999
|
89
|
-
@x = Math.atan2(m32, m33)
|
90
|
-
@z = Math.atan2(m21, m11)
|
88
|
+
@x = ::Math.atan2(m32, m33)
|
89
|
+
@z = ::Math.atan2(m21, m11)
|
91
90
|
else
|
92
91
|
@x = 0.0
|
93
|
-
@z = Math.atan2(- m12, m22)
|
92
|
+
@z = ::Math.atan2(- m12, m22)
|
94
93
|
end
|
95
94
|
elsif order == 'YZX'
|
96
|
-
@z = Math.asin(Math.clamp(m21, -1.0, 1.0))
|
95
|
+
@z = ::Math.asin(Math.clamp(m21, -1.0, 1.0))
|
97
96
|
if m21.abs < 0.99999
|
98
|
-
@x = Math.atan2(- m23, m22)
|
99
|
-
@y = Math.atan2(- m31, m11)
|
97
|
+
@x = ::Math.atan2(- m23, m22)
|
98
|
+
@y = ::Math.atan2(- m31, m11)
|
100
99
|
else
|
101
100
|
@x = 0.0
|
102
|
-
@y = Math.atan2(m13, m33)
|
101
|
+
@y = ::Math.atan2(m13, m33)
|
103
102
|
end
|
104
103
|
elsif order == 'XZY'
|
105
|
-
@z = Math.asin(- Math.clamp(m12, -1.0, 1.0))
|
104
|
+
@z = ::Math.asin(- Math.clamp(m12, -1.0, 1.0))
|
106
105
|
if m12.abs < 0.99999
|
107
|
-
@x = Math.atan2(m32, m22)
|
108
|
-
@y = Math.atan2(m13, m11)
|
106
|
+
@x = ::Math.atan2(m32, m22)
|
107
|
+
@y = ::Math.atan2(m13, m11)
|
109
108
|
else
|
110
|
-
@x = Math.atan2(- m23, m33)
|
109
|
+
@x = ::Math.atan2(- m23, m33)
|
111
110
|
@y = 0.0
|
112
111
|
end
|
113
112
|
else
|
data/lib/mittsu/math/frustum.rb
CHANGED
data/lib/mittsu/math/line3.rb
CHANGED
data/lib/mittsu/math/matrix3.rb
CHANGED
data/lib/mittsu/math/matrix4.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'mittsu/math'
|
2
|
-
|
3
1
|
module Mittsu
|
4
2
|
class Matrix4
|
5
3
|
attr_accessor :elements
|
@@ -88,9 +86,9 @@ module Mittsu
|
|
88
86
|
def make_rotation_from_euler(euler)
|
89
87
|
te = self.elements
|
90
88
|
x, y, z = euler.x, euler.y, euler.z
|
91
|
-
a, b = Math.cos(x), Math.sin(x)
|
92
|
-
c, d = Math.cos(y), Math.sin(y)
|
93
|
-
e, f = Math.cos(z), Math.sin(z)
|
89
|
+
a, b = ::Math.cos(x), ::Math.sin(x)
|
90
|
+
c, d = ::Math.cos(y), ::Math.sin(y)
|
91
|
+
e, f = ::Math.cos(z), ::Math.sin(z)
|
94
92
|
if euler.order == 'XYZ'
|
95
93
|
ae = a * e; af = a * f; be = b * e; bf = b * f
|
96
94
|
te[0] = c * e
|
@@ -401,7 +399,7 @@ module Mittsu
|
|
401
399
|
scale_x_sq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2]
|
402
400
|
scale_y_sq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6]
|
403
401
|
scale_z_sq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10]
|
404
|
-
Math.sqrt([scale_x_sq, scale_y_sq, scale_z_sq].max)
|
402
|
+
::Math.sqrt([scale_x_sq, scale_y_sq, scale_z_sq].max)
|
405
403
|
end
|
406
404
|
|
407
405
|
def make_translation(x, y, z)
|
@@ -415,7 +413,7 @@ module Mittsu
|
|
415
413
|
end
|
416
414
|
|
417
415
|
def make_rotation_x(theta)
|
418
|
-
c, s = Math.cos(theta), Math.sin(theta)
|
416
|
+
c, s = ::Math.cos(theta), ::Math.sin(theta)
|
419
417
|
self.set(
|
420
418
|
1.0, 0.0, 0.0, 0.0,
|
421
419
|
0.0, c, -s, 0.0,
|
@@ -426,7 +424,7 @@ module Mittsu
|
|
426
424
|
end
|
427
425
|
|
428
426
|
def make_rotation_y(theta)
|
429
|
-
c, s = Math.cos(theta), Math.sin(theta)
|
427
|
+
c, s = ::Math.cos(theta), ::Math.sin(theta)
|
430
428
|
self.set(
|
431
429
|
c, 0.0, s, 0.0,
|
432
430
|
0.0, 1.0, 0.0, 0.0,
|
@@ -437,7 +435,7 @@ module Mittsu
|
|
437
435
|
end
|
438
436
|
|
439
437
|
def make_rotation_z(theta)
|
440
|
-
c, s = Math.cos(theta), Math.sin(theta)
|
438
|
+
c, s = ::Math.cos(theta), ::Math.sin(theta)
|
441
439
|
self.set(
|
442
440
|
c, -s, 0.0, 0.0,
|
443
441
|
s, c, 0.0, 0.0,
|
@@ -449,8 +447,8 @@ module Mittsu
|
|
449
447
|
|
450
448
|
def make_rotation_axis(axis, angle)
|
451
449
|
# Based on http:#www.gamedev.net/reference/articles/article1199.asp
|
452
|
-
c = Math.cos(angle)
|
453
|
-
s = Math.sin(angle)
|
450
|
+
c = ::Math.cos(angle)
|
451
|
+
s = ::Math.sin(angle)
|
454
452
|
t = 1.0 - c
|
455
453
|
x, y, z = axis.x, axis.y, axis.z
|
456
454
|
tx, ty = t * x, t * y
|
@@ -536,7 +534,7 @@ module Mittsu
|
|
536
534
|
def make_perspective(fov, aspect, near, far)
|
537
535
|
fov, aspect, near, far =
|
538
536
|
fov.to_f, aspect.to_f, near.to_f, far.to_f
|
539
|
-
ymax = near * Math.tan(Math.deg_to_rad(fov * 0.5))
|
537
|
+
ymax = near * ::Math.tan(Math.deg_to_rad(fov * 0.5))
|
540
538
|
ymin = -ymax
|
541
539
|
xmin = ymin * aspect
|
542
540
|
xmax = ymax * aspect
|
data/lib/mittsu/math/plane.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'mittsu/math'
|
2
|
-
|
3
1
|
module Mittsu
|
4
2
|
class Quaternion
|
5
3
|
EPS = 0.000001
|
@@ -8,6 +6,7 @@ module Mittsu
|
|
8
6
|
|
9
7
|
def initialize(x = 0.0, y = 0.0, z = 0.0, w = 1.0)
|
10
8
|
@x, @y, @z, @w = x, y, z, w
|
9
|
+
@on_change_callback = nil
|
11
10
|
end
|
12
11
|
|
13
12
|
def set(x, y, z, w)
|
@@ -52,12 +51,12 @@ module Mittsu
|
|
52
51
|
# http:#www.mathworks.com/matlabcentral/fileexchange/
|
53
52
|
# 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
|
54
53
|
# content/SpinCalc.m
|
55
|
-
c1 = Math.cos(euler.x / 2.0)
|
56
|
-
c2 = Math.cos(euler.y / 2.0)
|
57
|
-
c3 = Math.cos(euler.z / 2.0)
|
58
|
-
s1 = Math.sin(euler.x / 2.0)
|
59
|
-
s2 = Math.sin(euler.y / 2.0)
|
60
|
-
s3 = Math.sin(euler.z / 2.0)
|
54
|
+
c1 = ::Math.cos(euler.x / 2.0)
|
55
|
+
c2 = ::Math.cos(euler.y / 2.0)
|
56
|
+
c3 = ::Math.cos(euler.z / 2.0)
|
57
|
+
s1 = ::Math.sin(euler.x / 2.0)
|
58
|
+
s2 = ::Math.sin(euler.y / 2.0)
|
59
|
+
s3 = ::Math.sin(euler.z / 2.0)
|
61
60
|
if euler.order == 'XYZ'
|
62
61
|
@x = s1 * c2 * c3 + c1 * s2 * s3
|
63
62
|
@y = c1 * s2 * c3 - s1 * c2 * s3
|
@@ -97,11 +96,11 @@ module Mittsu
|
|
97
96
|
# http:#www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
|
98
97
|
# assumes axis is normalized
|
99
98
|
half_angle = angle / 2.0
|
100
|
-
s = Math.sin(half_angle)
|
99
|
+
s = ::Math.sin(half_angle)
|
101
100
|
@x = axis.x * s
|
102
101
|
@y = axis.y * s
|
103
102
|
@z = axis.z * s
|
104
|
-
@w = Math.cos(half_angle)
|
103
|
+
@w = ::Math.cos(half_angle)
|
105
104
|
self.on_change_callback
|
106
105
|
self
|
107
106
|
end
|
@@ -115,25 +114,25 @@ module Mittsu
|
|
115
114
|
m31 = te[2]; m32 = te[6]; m33 = te[10]
|
116
115
|
trace = m11 + m22 + m33
|
117
116
|
if trace > 0
|
118
|
-
s = 0.5 / Math.sqrt(trace + 1.0)
|
117
|
+
s = 0.5 / ::Math.sqrt(trace + 1.0)
|
119
118
|
@w = 0.25 / s
|
120
119
|
@x = (m32 - m23) * s
|
121
120
|
@y = (m13 - m31) * s
|
122
121
|
@z = (m21 - m12) * s
|
123
122
|
elsif m11 > m22 && m11 > m33
|
124
|
-
s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33)
|
123
|
+
s = 2.0 * ::Math.sqrt(1.0 + m11 - m22 - m33)
|
125
124
|
@w = (m32 - m23) / s
|
126
125
|
@x = 0.25 * s
|
127
126
|
@y = (m12 + m21) / s
|
128
127
|
@z = (m13 + m31) / s
|
129
128
|
elsif m22 > m33
|
130
|
-
s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33)
|
129
|
+
s = 2.0 * ::Math.sqrt(1.0 + m22 - m11 - m33)
|
131
130
|
@w = (m13 - m31) / s
|
132
131
|
@x = (m12 + m21) / s
|
133
132
|
@y = 0.25 * s
|
134
133
|
@z = (m23 + m32) / s
|
135
134
|
else
|
136
|
-
s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22)
|
135
|
+
s = 2.0 * ::Math.sqrt(1.0 + m33 - m11 - m22)
|
137
136
|
@w = (m21 - m12) / s
|
138
137
|
@x = (m13 + m31) / s
|
139
138
|
@y = (m23 + m32) / s
|
@@ -188,7 +187,7 @@ module Mittsu
|
|
188
187
|
end
|
189
188
|
|
190
189
|
def length
|
191
|
-
Math.sqrt(@x * @x + @y * @y + @z * @z + @w * @w)
|
190
|
+
::Math.sqrt(@x * @x + @y * @y + @z * @z + @w * @w)
|
192
191
|
end
|
193
192
|
|
194
193
|
def normalize
|
@@ -247,8 +246,8 @@ module Mittsu
|
|
247
246
|
@z = _z
|
248
247
|
return self
|
249
248
|
end
|
250
|
-
half_theta = Math.acos(cos_half_theta)
|
251
|
-
sin_half_theta = Math.sqrt(1.0 - cos_half_theta * cos_half_theta)
|
249
|
+
half_theta = ::Math.acos(cos_half_theta)
|
250
|
+
sin_half_theta = ::Math.sqrt(1.0 - cos_half_theta * cos_half_theta)
|
252
251
|
if sin_half_theta.abs < 0.001
|
253
252
|
@w = 0.5 * (_w + @w)
|
254
253
|
@x = 0.5 * (_x + @x)
|
@@ -256,8 +255,8 @@ module Mittsu
|
|
256
255
|
@z = 0.5 * (_z + @z)
|
257
256
|
return self
|
258
257
|
end
|
259
|
-
ratio_a = Math.sin((1.0. - t) * half_theta) / sin_half_theta,
|
260
|
-
ratio_b = Math.sin(t * half_theta) / sin_half_theta
|
258
|
+
ratio_a = ::Math.sin((1.0. - t) * half_theta) / sin_half_theta,
|
259
|
+
ratio_b = ::Math.sin(t * half_theta) / sin_half_theta
|
261
260
|
@w = (_w * ratio_a + @w * ratio_b)
|
262
261
|
@x = (_x * ratio_a + @x * ratio_b)
|
263
262
|
@y = (_y * ratio_a + @y * ratio_b)
|
@@ -304,6 +303,5 @@ module Mittsu
|
|
304
303
|
def self.slerp(qa, qb, qm, t)
|
305
304
|
qm.copy(qa).slerp(qb, t)
|
306
305
|
end
|
307
|
-
|
308
306
|
end
|
309
307
|
end
|
data/lib/mittsu/math/ray.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'mittsu/math'
|
2
|
-
|
3
1
|
module Mittsu
|
4
2
|
class Ray
|
5
3
|
attr_accessor :origin, :direction
|
@@ -140,7 +138,7 @@ module Mittsu
|
|
140
138
|
d2 = v1.dot(v1) - tca * tca
|
141
139
|
radius2 = sphere.radius * sphere.radius
|
142
140
|
return nil if d2 > radius2
|
143
|
-
thc = Math.sqrt(radius2 - d2)
|
141
|
+
thc = ::Math.sqrt(radius2 - d2)
|
144
142
|
# t0 = first intersect point - entrance on front of sphere
|
145
143
|
t0 = tca - thc
|
146
144
|
# t1 = second intersect point - exit point on back of sphere
|
data/lib/mittsu/math/sphere.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'mittsu/math'
|
2
|
-
|
3
1
|
module Mittsu
|
4
2
|
class Sphere
|
5
3
|
attr_accessor :center, :radius
|
@@ -26,7 +24,7 @@ module Mittsu
|
|
26
24
|
points.each do |point|
|
27
25
|
max_radius_sq = [max_radius_sq, c.distance_to_squared(point)].max
|
28
26
|
end
|
29
|
-
@radius = Math.sqrt(max_radius_sq)
|
27
|
+
@radius = ::Math.sqrt(max_radius_sq)
|
30
28
|
self
|
31
29
|
end
|
32
30
|
|