mittsu 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/README.md +1 -1
- data/lib/mittsu/cameras/orthographic_camera.rb +13 -0
- data/lib/mittsu/cameras/perspective_camera.rb +11 -0
- data/lib/mittsu/core/geometry.rb +12 -9
- data/lib/mittsu/core/object_3d.rb +33 -66
- data/lib/mittsu/lights/ambient_light.rb +8 -0
- data/lib/mittsu/lights/directional_light.rb +9 -0
- data/lib/mittsu/lights/hemisphere_light.rb +9 -0
- data/lib/mittsu/lights/point_light.rb +11 -0
- data/lib/mittsu/lights/spot_light.rb +13 -0
- data/lib/mittsu/loaders.rb +1 -0
- data/lib/mittsu/loaders/mtl_loader.rb +5 -12
- data/lib/mittsu/loaders/obj_loader.rb +212 -0
- data/lib/mittsu/loaders/obj_mtl_loader.rb +11 -207
- data/lib/mittsu/materials/material.rb +5 -2
- data/lib/mittsu/materials/mesh_basic_material.rb +0 -9
- data/lib/mittsu/math/color.rb +44 -104
- data/lib/mittsu/math/matrix3.rb +8 -1
- data/lib/mittsu/math/matrix4.rb +6 -0
- data/lib/mittsu/math/vector.rb +251 -0
- data/lib/mittsu/math/vector2.rb +14 -213
- data/lib/mittsu/math/vector3.rb +61 -351
- data/lib/mittsu/math/vector4.rb +45 -295
- data/lib/mittsu/objects/line.rb +12 -2
- data/lib/mittsu/objects/mesh.rb +18 -9
- data/lib/mittsu/renderers/glfw_window.rb +15 -13
- data/lib/mittsu/renderers/opengl/core/opengl_geometry.rb +253 -0
- data/lib/mittsu/renderers/opengl/core/opengl_object_3d.rb +131 -0
- data/lib/mittsu/renderers/opengl/lights/opengl_ambient_light.rb +26 -0
- data/lib/mittsu/renderers/opengl/lights/opengl_directional_light.rb +35 -0
- data/lib/mittsu/renderers/opengl/lights/opengl_hemisphere_light.rb +42 -0
- data/lib/mittsu/renderers/opengl/lights/opengl_light.rb +52 -0
- data/lib/mittsu/renderers/opengl/lights/opengl_point_light.rb +36 -0
- data/lib/mittsu/renderers/opengl/lights/opengl_spot_light.rb +47 -0
- data/lib/mittsu/renderers/opengl/materials/opengl_line_basic_material.rb +16 -0
- data/lib/mittsu/renderers/opengl/materials/opengl_material.rb +275 -0
- data/lib/mittsu/renderers/opengl/materials/opengl_mesh_basic_material.rb +69 -0
- data/lib/mittsu/renderers/opengl/materials/opengl_mesh_lambert_material.rb +29 -0
- data/lib/mittsu/renderers/opengl/materials/opengl_mesh_phong_material.rb +40 -0
- data/lib/mittsu/renderers/opengl/materials/opengl_shader_material.rb +11 -0
- data/lib/mittsu/renderers/opengl/objects/opengl_group.rb +8 -0
- data/lib/mittsu/renderers/opengl/objects/opengl_line.rb +54 -0
- data/lib/mittsu/renderers/opengl/objects/opengl_mesh.rb +77 -0
- data/lib/mittsu/renderers/opengl/opengl_buffer.rb +5 -0
- data/lib/mittsu/renderers/opengl/opengl_debug.rb +49 -7
- data/lib/mittsu/renderers/opengl/opengl_default_target.rb +54 -0
- data/lib/mittsu/renderers/opengl/opengl_geometry_group.rb +763 -0
- data/lib/mittsu/renderers/opengl/opengl_geometry_like.rb +130 -0
- data/lib/mittsu/renderers/opengl/opengl_helper.rb +161 -0
- data/lib/mittsu/renderers/opengl/opengl_implementations.rb +61 -0
- data/lib/mittsu/renderers/opengl/opengl_light_renderer.rb +43 -0
- data/lib/mittsu/renderers/opengl/opengl_mittsu_params.rb +53 -0
- data/lib/mittsu/renderers/opengl/opengl_program.rb +147 -296
- data/lib/mittsu/renderers/opengl/opengl_state.rb +3 -5
- data/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +12 -10
- data/lib/mittsu/renderers/opengl/scenes/opengl_scene.rb +8 -0
- data/lib/mittsu/renderers/opengl/textures/opengl_compressed_texture.rb +21 -0
- data/lib/mittsu/renderers/opengl/textures/opengl_cube_texture.rb +75 -0
- data/lib/mittsu/renderers/opengl/textures/opengl_data_texture.rb +23 -0
- data/lib/mittsu/renderers/opengl/textures/opengl_texture.rb +111 -0
- data/lib/mittsu/renderers/opengl_render_target.rb +117 -2
- data/lib/mittsu/renderers/opengl_renderer.rb +653 -2978
- data/lib/mittsu/renderers/shaders/rbsl_loader.rb +166 -0
- data/lib/mittsu/renderers/shaders/shader_chunk.rb +6 -9
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_fragment.glsl +36 -37
- data/lib/mittsu/renderers/shaders/shader_lib.rb +26 -403
- data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_fragment.rbsl +37 -0
- data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_uniforms.rbslu +3 -0
- data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_vertex.rbsl +33 -0
- data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_fragment.rbsl +12 -0
- data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_uniforms.rbslu +2 -0
- data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_vertex.rbsl +12 -0
- data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_fragment.rbsl +26 -0
- data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_uniforms.rbslu +0 -0
- data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_vertex.rbsl +12 -0
- data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_fragment.rbsl +56 -0
- data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_uniforms.rbslu +7 -0
- data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_vertex.rbsl +37 -0
- data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_fragment.rbsl +45 -0
- data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_uniforms.rbslu +11 -0
- data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_vertex.rbsl +43 -0
- data/lib/mittsu/renderers/shaders/shader_templates/fragment.glsl.erb +105 -0
- data/lib/mittsu/renderers/shaders/shader_templates/vertex.glsl.erb +143 -0
- data/lib/mittsu/renderers/shaders/uniforms_lib.rb +54 -55
- data/lib/mittsu/textures/texture.rb +5 -2
- data/lib/mittsu/version.rb +1 -1
- data/run_all_examples.sh +7 -0
- metadata +77 -28
- data/.ruby-version +0 -1
- data/lib/mittsu/core/hash_object.rb +0 -19
data/lib/mittsu/math/vector3.rb
CHANGED
@@ -1,117 +1,26 @@
|
|
1
1
|
require 'mittsu/math'
|
2
|
+
require 'mittsu/math/vector'
|
2
3
|
|
3
4
|
module Mittsu
|
4
|
-
class Vector3
|
5
|
-
|
5
|
+
class Vector3 < Vector
|
6
|
+
ELEMENTS = { x: 0, y: 1, z: 2 }
|
7
|
+
DIMENSIONS = ELEMENTS.count
|
6
8
|
|
7
9
|
def initialize(x = 0, y = 0, z = 0)
|
8
|
-
|
9
|
-
@y = y.to_f
|
10
|
-
@z = z.to_f
|
11
|
-
end
|
12
|
-
|
13
|
-
def x=(value)
|
14
|
-
@x = value.to_f
|
15
|
-
end
|
16
|
-
|
17
|
-
def y=(value)
|
18
|
-
@y = value.to_f
|
19
|
-
end
|
20
|
-
|
21
|
-
def z=(value)
|
22
|
-
@z = value.to_f
|
10
|
+
super [x.to_f, y.to_f, z.to_f]
|
23
11
|
end
|
24
12
|
|
25
13
|
def set(x, y, z)
|
26
|
-
|
27
|
-
@y = y.to_f
|
28
|
-
@z = z.to_f
|
29
|
-
self
|
30
|
-
end
|
31
|
-
|
32
|
-
def []=(index, value)
|
33
|
-
return @x = value.to_f if index == 0 || index == :x
|
34
|
-
return @y = value.to_f if index == 1 || index == :y
|
35
|
-
return @z = value.to_f if index == 2 || index == :z
|
36
|
-
raise IndexError
|
37
|
-
end
|
38
|
-
|
39
|
-
def [](index)
|
40
|
-
return @x if index == 0 || index == :x
|
41
|
-
return @y if index == 1 || index == :y
|
42
|
-
return @z if index == 2 || index == :z
|
43
|
-
raise IndexError
|
44
|
-
end
|
45
|
-
|
46
|
-
def copy(v)
|
47
|
-
@x = v.x
|
48
|
-
@y = v.y
|
49
|
-
@z = v.z
|
50
|
-
self
|
51
|
-
end
|
52
|
-
|
53
|
-
def add(v)
|
54
|
-
@x += v.x
|
55
|
-
@y += v.y
|
56
|
-
@z += v.z
|
57
|
-
self
|
58
|
-
end
|
59
|
-
|
60
|
-
def add_scalar(s)
|
61
|
-
@x += s
|
62
|
-
@y += s
|
63
|
-
@z += s
|
64
|
-
self
|
14
|
+
super [x.to_f, y.to_f, z.to_f]
|
65
15
|
end
|
66
16
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
@z = a.z + b.z
|
71
|
-
self
|
72
|
-
end
|
17
|
+
def x; @elements[0]; end
|
18
|
+
def y; @elements[1]; end
|
19
|
+
def z; @elements[2]; end
|
73
20
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
-
@z -= v.z
|
78
|
-
self
|
79
|
-
end
|
80
|
-
|
81
|
-
def sub_scalar(s)
|
82
|
-
@x -= s
|
83
|
-
@y -= s
|
84
|
-
@z -= s
|
85
|
-
self
|
86
|
-
end
|
87
|
-
|
88
|
-
def sub_vectors(a, b)
|
89
|
-
@x = a.x - b.x
|
90
|
-
@y = a.y - b.y
|
91
|
-
@z = a.z - b.z
|
92
|
-
self
|
93
|
-
end
|
94
|
-
|
95
|
-
def multiply(v)
|
96
|
-
@x *= v.x
|
97
|
-
@y *= v.y
|
98
|
-
@z *= v.z
|
99
|
-
self
|
100
|
-
end
|
101
|
-
|
102
|
-
def multiply_scalar(scalar)
|
103
|
-
@x *= scalar
|
104
|
-
@y *= scalar
|
105
|
-
@z *= scalar
|
106
|
-
self
|
107
|
-
end
|
108
|
-
|
109
|
-
def multiply_vectors(a, b)
|
110
|
-
@x = a.x * b.x
|
111
|
-
@y = a.y * b.y
|
112
|
-
@z = a.z * b.z
|
113
|
-
self
|
114
|
-
end
|
21
|
+
def x=(value); @elements[0] = value.to_f; end
|
22
|
+
def y=(value); @elements[1] = value.to_f; end
|
23
|
+
def z=(value); @elements[2] = value.to_f; end
|
115
24
|
|
116
25
|
def apply_euler(euler)
|
117
26
|
quaternion = Mittsu::Quaternion.new
|
@@ -126,52 +35,46 @@ module Mittsu
|
|
126
35
|
end
|
127
36
|
|
128
37
|
def apply_matrix3(m)
|
129
|
-
|
130
|
-
y = @y
|
131
|
-
z = @z
|
38
|
+
_x, _y, _z = *@elements
|
132
39
|
|
133
40
|
e = m.elements
|
134
41
|
|
135
|
-
@
|
136
|
-
@
|
137
|
-
@
|
42
|
+
@elements[0] = e[0] * _x + e[3] * _y + e[6] * _z
|
43
|
+
@elements[1] = e[1] * _x + e[4] * _y + e[7] * _z
|
44
|
+
@elements[2] = e[2] * _x + e[5] * _y + e[8] * _z
|
138
45
|
|
139
46
|
self
|
140
47
|
end
|
141
48
|
|
142
49
|
def apply_matrix4(m)
|
143
50
|
# input: THREE.Matrix4 affine matrix
|
144
|
-
|
145
|
-
xx, yy, zz = @x, @y, @z
|
51
|
+
_x, _y, _z = *@elements
|
146
52
|
|
147
53
|
e = m.elements
|
148
54
|
|
149
|
-
@
|
150
|
-
@
|
151
|
-
@
|
55
|
+
@elements[0] = e[0] * _x + e[4] * _y + e[8] * _z + e[12]
|
56
|
+
@elements[1] = e[1] * _x + e[5] * _y + e[9] * _z + e[13]
|
57
|
+
@elements[2] = e[2] * _x + e[6] * _y + e[10] * _z + e[14]
|
152
58
|
|
153
59
|
self
|
154
60
|
end
|
155
61
|
|
156
62
|
def apply_projection(m)
|
157
63
|
# input: THREE.Matrix4 projection matrix
|
158
|
-
|
159
|
-
_x, _y, _z = @x, @y, @z
|
64
|
+
_x, _y, _z = *@elements
|
160
65
|
|
161
66
|
e = m.elements
|
162
67
|
d = 1.0 / (e[3] * _x + e[7] * _y + e[11] * _z + e[15]) # perspective divide
|
163
68
|
|
164
|
-
@
|
165
|
-
@
|
166
|
-
@
|
69
|
+
@elements[0] = (e[0] * _x + e[4] * _y + e[8] * _z + e[12]) * d
|
70
|
+
@elements[1] = (e[1] * _x + e[5] * _y + e[9] * _z + e[13]) * d
|
71
|
+
@elements[2] = (e[2] * _x + e[6] * _y + e[10] * _z + e[14]) * d
|
167
72
|
|
168
73
|
self
|
169
74
|
end
|
170
75
|
|
171
76
|
def apply_quaternion(q)
|
172
|
-
|
173
|
-
y = @y
|
174
|
-
z = @z
|
77
|
+
_x, _y, _z = *@elements
|
175
78
|
|
176
79
|
qx = q.x
|
177
80
|
qy = q.y
|
@@ -179,17 +82,15 @@ module Mittsu
|
|
179
82
|
qw = q.w
|
180
83
|
|
181
84
|
# calculate quat * vector
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
iw = - qx * x - qy * y - qz * z
|
85
|
+
ix = qw * _x + qy * _z - qz * _y
|
86
|
+
iy = qw * _y + qz * _x - qx * _z
|
87
|
+
iz = qw * _z + qx * _y - qy * _x
|
88
|
+
iw = -qx * _x - qy * _y - qz * _z
|
187
89
|
|
188
90
|
# calculate result * inverse quat
|
189
|
-
|
190
|
-
@
|
191
|
-
@
|
192
|
-
@z = iz * qw + iw * - qz + ix * - qy - iy * - qx
|
91
|
+
@elements[0] = ix * qw + iw * - qx + iy * - qz - iz * - qy
|
92
|
+
@elements[1] = iy * qw + iw * - qy + iz * - qx - ix * - qz
|
93
|
+
@elements[2] = iz * qw + iw * - qz + ix * - qy - iy * - qx
|
193
94
|
|
194
95
|
self
|
195
96
|
end
|
@@ -209,161 +110,32 @@ module Mittsu
|
|
209
110
|
def transform_direction(m)
|
210
111
|
# input: THREE.Matrix4 affine matrix
|
211
112
|
# vector interpreted as a direction
|
212
|
-
|
213
|
-
x = @x, y = @y, z = @z
|
113
|
+
_x, _y, _z = *@elements
|
214
114
|
|
215
115
|
e = m.elements
|
216
116
|
|
217
|
-
@
|
218
|
-
@
|
219
|
-
@
|
117
|
+
@elements[0] = e[0] * _x + e[4] * _y + e[8] * _z
|
118
|
+
@elements[1] = e[1] * _x + e[5] * _y + e[9] * _z
|
119
|
+
@elements[2] = e[2] * _x + e[6] * _y + e[10] * _z
|
220
120
|
|
221
121
|
self.normalize
|
222
122
|
|
223
123
|
self
|
224
124
|
end
|
225
125
|
|
226
|
-
def divide(v)
|
227
|
-
@x /= v.x
|
228
|
-
@y /= v.y
|
229
|
-
@z /= v.z
|
230
|
-
self
|
231
|
-
end
|
232
|
-
|
233
|
-
def divide_scalar(scalar)
|
234
|
-
if scalar != 0
|
235
|
-
invScalar = 1.0 / scalar
|
236
|
-
@x *= invScalar
|
237
|
-
@y *= invScalar
|
238
|
-
@z *= invScalar
|
239
|
-
else
|
240
|
-
@x = 0
|
241
|
-
@y = 0
|
242
|
-
@z = 0
|
243
|
-
end
|
244
|
-
self
|
245
|
-
end
|
246
|
-
|
247
|
-
def min(v)
|
248
|
-
if @x > v.x
|
249
|
-
@x = v.x
|
250
|
-
end
|
251
|
-
if @y > v.y
|
252
|
-
@y = v.y
|
253
|
-
end
|
254
|
-
if @z > v.z
|
255
|
-
@z = v.z
|
256
|
-
end
|
257
|
-
self
|
258
|
-
end
|
259
|
-
|
260
|
-
def max(v)
|
261
|
-
if @x < v.x
|
262
|
-
@x = v.x
|
263
|
-
end
|
264
|
-
if @y < v.y
|
265
|
-
@y = v.y
|
266
|
-
end
|
267
|
-
if @z < v.z
|
268
|
-
@z = v.z
|
269
|
-
end
|
270
|
-
self
|
271
|
-
end
|
272
|
-
|
273
|
-
def clamp(min, max)
|
274
|
-
@x = Math.clamp(@x, min.x, max.x)
|
275
|
-
@y = Math.clamp(@y, min.y, max.y)
|
276
|
-
@z = Math.clamp(@z, min.z, max.z)
|
277
|
-
self
|
278
|
-
end
|
279
|
-
|
280
|
-
def clamp_scalar(min, max)
|
281
|
-
@x = Math.clamp(@x, min, max)
|
282
|
-
@y = Math.clamp(@y, min, max)
|
283
|
-
@z = Math.clamp(@z, min, max)
|
284
|
-
self
|
285
|
-
end
|
286
|
-
|
287
|
-
def floor
|
288
|
-
@x = @x.floor.to_f
|
289
|
-
@y = @y.floor.to_f
|
290
|
-
@z = @z.floor.to_f
|
291
|
-
self
|
292
|
-
end
|
293
|
-
|
294
|
-
def ceil
|
295
|
-
@x = @x.ceil.to_f
|
296
|
-
@y = @y.ceil.to_f
|
297
|
-
@z = @z.ceil.to_f
|
298
|
-
self
|
299
|
-
end
|
300
|
-
|
301
|
-
def round
|
302
|
-
@x = @x.round.to_f
|
303
|
-
@y = @y.round.to_f
|
304
|
-
@z = @z.round.to_f
|
305
|
-
self
|
306
|
-
end
|
307
|
-
|
308
|
-
def round_to_zero
|
309
|
-
@x = (@x < 0) ? @x.ceil.to_f : @x.floor.to_f
|
310
|
-
@y = (@y < 0) ? @y.ceil.to_f : @y.floor.to_f
|
311
|
-
@z = (@z < 0) ? @z.ceil.to_f : @z.floor.to_f
|
312
|
-
self
|
313
|
-
end
|
314
|
-
|
315
|
-
def negate
|
316
|
-
@x = - @x
|
317
|
-
@y = - @y
|
318
|
-
@z = - @z
|
319
|
-
self
|
320
|
-
end
|
321
|
-
|
322
126
|
def dot(v)
|
323
|
-
|
324
|
-
end
|
325
|
-
|
326
|
-
def length_sq
|
327
|
-
self.dot(self)
|
328
|
-
end
|
329
|
-
|
330
|
-
def length
|
331
|
-
Math.sqrt(length_sq)
|
127
|
+
x * v.x + y * v.y + z * v.z
|
332
128
|
end
|
333
129
|
|
334
130
|
def length_manhattan
|
335
|
-
|
336
|
-
end
|
337
|
-
|
338
|
-
def normalize
|
339
|
-
self.divide_scalar(self.length)
|
340
|
-
end
|
341
|
-
|
342
|
-
def set_length(l)
|
343
|
-
old_length = self.length
|
344
|
-
if old_length != 0 && l != old_length
|
345
|
-
self.multiply_scalar(l / old_length)
|
346
|
-
end
|
347
|
-
self
|
348
|
-
end
|
349
|
-
|
350
|
-
def lerp(v, alpha)
|
351
|
-
@x += (v.x - @x) * alpha
|
352
|
-
@y += (v.y - @y) * alpha
|
353
|
-
@z += (v.z - @z) * alpha
|
354
|
-
self
|
355
|
-
end
|
356
|
-
|
357
|
-
def lerp_vectors(v1, v2, alpha)
|
358
|
-
self.sub_vectors(v2, v1).multiply_scalar(alpha).add(v1)
|
359
|
-
self
|
131
|
+
x.abs + y.abs + z.abs
|
360
132
|
end
|
361
133
|
|
362
134
|
def cross(v)
|
363
|
-
|
364
|
-
@
|
365
|
-
@
|
366
|
-
@
|
135
|
+
_x, _y, _z = *@elements
|
136
|
+
@elements[0] = _y * v.z - _z * v.y
|
137
|
+
@elements[1] = _z * v.x - _x * v.z
|
138
|
+
@elements[2] = _x * v.y - _y * v.x
|
367
139
|
self
|
368
140
|
end
|
369
141
|
|
@@ -371,55 +143,24 @@ module Mittsu
|
|
371
143
|
ax, ay, az = a.x, a.y, a.z
|
372
144
|
bx, by, bz = b.x, b.y, b.z
|
373
145
|
|
374
|
-
@
|
375
|
-
@
|
376
|
-
@
|
146
|
+
@elements[0] = ay * bz - az * by
|
147
|
+
@elements[1] = az * bx - ax * bz
|
148
|
+
@elements[2] = ax * by - ay * bx
|
377
149
|
|
378
150
|
self
|
379
151
|
end
|
380
152
|
|
381
|
-
def project_on_vector(vector)
|
382
|
-
v1 = Mittsu::Vector3.new
|
383
|
-
v1.copy(vector).normalize
|
384
|
-
dot = self.dot(v1)
|
385
|
-
self.copy(v1).multiply_scalar(dot)
|
386
|
-
end
|
387
|
-
|
388
|
-
def project_on_plane(plane_normal)
|
389
|
-
v1 = Mittsu::Vector3.new
|
390
|
-
v1.copy(self).project_on_vector(plane_normal)
|
391
|
-
self.sub(v1)
|
392
|
-
end
|
393
|
-
|
394
|
-
def reflect(normal)
|
395
|
-
# reflect incident vector off plane orthogonal to normal
|
396
|
-
# normal is assumed to have unit length
|
397
|
-
v1 = Mittsu::Vector3.new
|
398
|
-
self.sub(v1.copy(normal).multiply_scalar(2.0 * self.dot(normal)))
|
399
|
-
end
|
400
|
-
|
401
|
-
def angle_to(v)
|
402
|
-
theta = self.dot(v) / (self.length * v.length)
|
403
|
-
|
404
|
-
# clamp, to handle numerical problems
|
405
|
-
Math.acos(Math.clamp(theta, -1.0, 1.0))
|
406
|
-
end
|
407
|
-
|
408
|
-
def distance_to(v)
|
409
|
-
Math.sqrt(self.distance_to_squared(v))
|
410
|
-
end
|
411
|
-
|
412
153
|
def distance_to_squared(v)
|
413
|
-
dx =
|
414
|
-
dy =
|
415
|
-
dz =
|
154
|
+
dx = x - v.x
|
155
|
+
dy = y - v.y
|
156
|
+
dz = z - v.z
|
416
157
|
dx * dx + dy * dy + dz * dz
|
417
158
|
end
|
418
159
|
|
419
160
|
def set_from_matrix_position(m)
|
420
|
-
@
|
421
|
-
@
|
422
|
-
@
|
161
|
+
@elements[0] = m.elements[12]
|
162
|
+
@elements[1] = m.elements[13]
|
163
|
+
@elements[2] = m.elements[14]
|
423
164
|
self
|
424
165
|
end
|
425
166
|
|
@@ -428,9 +169,9 @@ module Mittsu
|
|
428
169
|
sy = self.set(m.elements[4], m.elements[5], m.elements[ 6]).length
|
429
170
|
sz = self.set(m.elements[8], m.elements[9], m.elements[10]).length
|
430
171
|
|
431
|
-
@
|
432
|
-
@
|
433
|
-
@
|
172
|
+
@elements[0] = sx
|
173
|
+
@elements[1] = sy
|
174
|
+
@elements[2] = sz
|
434
175
|
|
435
176
|
self
|
436
177
|
end
|
@@ -440,52 +181,21 @@ module Mittsu
|
|
440
181
|
|
441
182
|
me = matrix.elements
|
442
183
|
|
443
|
-
@
|
444
|
-
@
|
445
|
-
@
|
184
|
+
@elements[0] = me[offset]
|
185
|
+
@elements[1] = me[offset + 1]
|
186
|
+
@elements[2] = me[offset + 2]
|
446
187
|
|
447
188
|
self
|
448
189
|
end
|
449
190
|
|
450
|
-
def
|
451
|
-
((v.x == @x) && (v.y == @y) && (v.z == @z))
|
452
|
-
end
|
453
|
-
|
454
|
-
def fromArray(array, offset = 0)
|
455
|
-
@x = array[offset]
|
456
|
-
@y = array[offset + 1]
|
457
|
-
@z = array[offset + 2]
|
458
|
-
self
|
459
|
-
end
|
460
|
-
|
461
|
-
def to_array(array = [], offset = 0)
|
462
|
-
array[offset] = @x
|
463
|
-
array[offset + 1] = @y
|
464
|
-
array[offset + 2] = @z
|
465
|
-
|
466
|
-
array
|
467
|
-
end
|
468
|
-
|
469
|
-
def to_a
|
470
|
-
self.to_array
|
471
|
-
end
|
472
|
-
|
473
|
-
def from_attribute(attribute, index, offse = 0)
|
191
|
+
def from_attribute(attribute, index, offset = 0)
|
474
192
|
index = index * attribute.itemSize + offset
|
475
193
|
|
476
|
-
@
|
477
|
-
@
|
478
|
-
@
|
194
|
+
@elements[0] = attribute.array[index]
|
195
|
+
@elements[1] = attribute.array[index + 1]
|
196
|
+
@elements[2] = attribute.array[index + 2]
|
479
197
|
|
480
198
|
self
|
481
199
|
end
|
482
|
-
|
483
|
-
def clone
|
484
|
-
Mittsu::Vector3.new(@x, @y, @z)
|
485
|
-
end
|
486
|
-
|
487
|
-
def to_s
|
488
|
-
"[#{x}, #{y}, #{z}]"
|
489
|
-
end
|
490
200
|
end
|
491
201
|
end
|