cyberarm_engine 0.24.4 → 0.24.5
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/.gitignore +8 -8
- data/.rubocop.yml +7 -7
- data/.travis.yml +5 -5
- data/Gemfile +6 -6
- data/Gemfile.lock +24 -0
- data/LICENSE.txt +21 -21
- data/README.md +74 -74
- data/Rakefile +10 -10
- data/assets/shaders/fragment/g_buffer.glsl +30 -30
- data/assets/shaders/fragment/lighting.glsl +115 -69
- data/assets/shaders/include/light_struct.glsl +11 -11
- data/assets/shaders/include/material_struct.glsl +16 -16
- data/assets/shaders/vertex/g_buffer.glsl +28 -28
- data/assets/shaders/vertex/lighting.glsl +24 -24
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/cyberarm_engine.gemspec +36 -36
- data/lib/cyberarm_engine/animator.rb +219 -219
- data/lib/cyberarm_engine/background.rb +180 -179
- data/lib/cyberarm_engine/background_image.rb +93 -93
- data/lib/cyberarm_engine/background_nine_slice.rb +142 -142
- data/lib/cyberarm_engine/bounding_box.rb +150 -150
- data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
- data/lib/cyberarm_engine/cache/download_manager.rb +123 -123
- data/lib/cyberarm_engine/cache.rb +4 -4
- data/lib/cyberarm_engine/common.rb +128 -128
- data/lib/cyberarm_engine/config_file.rb +46 -46
- data/lib/cyberarm_engine/console/command.rb +157 -157
- data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
- data/lib/cyberarm_engine/console/subcommand.rb +99 -99
- data/lib/cyberarm_engine/console.rb +248 -248
- data/lib/cyberarm_engine/game_object.rb +244 -244
- data/lib/cyberarm_engine/game_state.rb +124 -124
- data/lib/cyberarm_engine/gosu_ext/draw_arc.rb +97 -97
- data/lib/cyberarm_engine/gosu_ext/draw_circle.rb +30 -30
- data/lib/cyberarm_engine/gosu_ext/draw_path.rb +17 -17
- data/lib/cyberarm_engine/model/material.rb +21 -21
- data/lib/cyberarm_engine/model/{model_object.rb → mesh.rb} +131 -131
- data/lib/cyberarm_engine/model/parser.rb +74 -74
- data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
- data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
- data/lib/cyberarm_engine/model.rb +216 -213
- data/lib/cyberarm_engine/model_cache.rb +31 -31
- data/lib/cyberarm_engine/notification.rb +82 -82
- data/lib/cyberarm_engine/notification_manager.rb +241 -241
- data/lib/cyberarm_engine/opengl/light.rb +52 -50
- data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +41 -38
- data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
- data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +167 -165
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +307 -304
- data/lib/cyberarm_engine/opengl/renderer/renderer.rb +33 -33
- data/lib/cyberarm_engine/opengl/shader.rb +408 -406
- data/lib/cyberarm_engine/opengl/texture.rb +69 -69
- data/lib/cyberarm_engine/opengl.rb +53 -40
- data/lib/cyberarm_engine/ray.rb +56 -56
- data/lib/cyberarm_engine/stats.rb +200 -200
- data/lib/cyberarm_engine/text.rb +260 -260
- data/lib/cyberarm_engine/timer.rb +23 -23
- data/lib/cyberarm_engine/transform.rb +296 -296
- data/lib/cyberarm_engine/trees/aabb_node.rb +126 -0
- data/lib/cyberarm_engine/trees/aabb_tree.rb +55 -0
- data/lib/cyberarm_engine/trees/aabb_tree_debug.rb +29 -0
- data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
- data/lib/cyberarm_engine/ui/dsl.rb +142 -142
- data/lib/cyberarm_engine/ui/element.rb +662 -662
- data/lib/cyberarm_engine/ui/elements/button.rb +100 -100
- data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
- data/lib/cyberarm_engine/ui/elements/container.rb +404 -404
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +297 -297
- data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
- data/lib/cyberarm_engine/ui/elements/image.rb +72 -72
- data/lib/cyberarm_engine/ui/elements/list_box.rb +79 -79
- data/lib/cyberarm_engine/ui/elements/menu.rb +27 -27
- data/lib/cyberarm_engine/ui/elements/menu_item.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/progress.rb +93 -93
- data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/slider.rb +107 -107
- data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
- data/lib/cyberarm_engine/ui/elements/text_block.rb +216 -216
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +67 -67
- data/lib/cyberarm_engine/ui/event.rb +54 -54
- data/lib/cyberarm_engine/ui/gui_state.rb +321 -321
- data/lib/cyberarm_engine/ui/style.rb +50 -50
- data/lib/cyberarm_engine/ui/theme.rb +225 -225
- data/lib/cyberarm_engine/vector.rb +312 -312
- data/lib/cyberarm_engine/version.rb +4 -4
- data/lib/cyberarm_engine/window.rb +195 -195
- data/lib/cyberarm_engine.rb +70 -78
- data/mrbgem.rake +29 -29
- metadata +8 -7
@@ -1,312 +1,312 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Vector
|
3
|
-
##
|
4
|
-
# Creates a up vector
|
5
|
-
#
|
6
|
-
# Vector.new(0, 1, 0)
|
7
|
-
#
|
8
|
-
# @return [CyberarmEngine::Vector]
|
9
|
-
def self.up
|
10
|
-
Vector.new(0, 1, 0)
|
11
|
-
end
|
12
|
-
|
13
|
-
##
|
14
|
-
# Creates a down vector
|
15
|
-
#
|
16
|
-
# Vector.new(0, -1, 0)
|
17
|
-
#
|
18
|
-
# @return [CyberarmEngine::Vector]
|
19
|
-
def self.down
|
20
|
-
Vector.new(0, -1, 0)
|
21
|
-
end
|
22
|
-
|
23
|
-
##
|
24
|
-
# Creates a left vector
|
25
|
-
#
|
26
|
-
# Vector.new(-1, 0, 0)
|
27
|
-
#
|
28
|
-
# @return [CyberarmEngine::Vector]
|
29
|
-
def self.left
|
30
|
-
Vector.new(-1, 0, 0)
|
31
|
-
end
|
32
|
-
|
33
|
-
##
|
34
|
-
# Creates a right vector
|
35
|
-
#
|
36
|
-
# Vector.new(1, 0, 0)
|
37
|
-
#
|
38
|
-
# @return [CyberarmEngine::Vector]
|
39
|
-
def self.right
|
40
|
-
Vector.new(1, 0, 0)
|
41
|
-
end
|
42
|
-
|
43
|
-
##
|
44
|
-
# Creates a forward vector
|
45
|
-
#
|
46
|
-
# Vector.new(0, 0, 1)
|
47
|
-
#
|
48
|
-
# @return [CyberarmEngine::Vector]
|
49
|
-
def self.forward
|
50
|
-
Vector.new(0, 0, 1)
|
51
|
-
end
|
52
|
-
|
53
|
-
##
|
54
|
-
# Creates a backward vector
|
55
|
-
#
|
56
|
-
# Vector.new(0, 0, -1)
|
57
|
-
#
|
58
|
-
# @return [CyberarmEngine::Vector]
|
59
|
-
def self.backward
|
60
|
-
Vector.new(0, 0, -1)
|
61
|
-
end
|
62
|
-
|
63
|
-
attr_accessor :x, :y, :z, :weight
|
64
|
-
|
65
|
-
def initialize(x = 0, y = 0, z = 0, weight = 0)
|
66
|
-
@x = x
|
67
|
-
@y = y
|
68
|
-
@z = z
|
69
|
-
@weight = weight
|
70
|
-
end
|
71
|
-
|
72
|
-
alias w weight
|
73
|
-
alias w= weight=
|
74
|
-
|
75
|
-
# @return [Boolean]
|
76
|
-
def ==(other)
|
77
|
-
if other.is_a?(Numeric)
|
78
|
-
@x == other &&
|
79
|
-
@y == other &&
|
80
|
-
@z == other &&
|
81
|
-
@weight == other
|
82
|
-
elsif other.is_a?(Vector)
|
83
|
-
@x == other.x &&
|
84
|
-
@y == other.y &&
|
85
|
-
@z == other.z &&
|
86
|
-
@weight == other.weight
|
87
|
-
else
|
88
|
-
other == self
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# Create a new vector using {x} and {y} values
|
93
|
-
# @return [CyberarmEngine::Vector]
|
94
|
-
def xy
|
95
|
-
Vector.new(@x, @y)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Adds Vector and Numeric or Vector and Vector, excluding {weight}
|
99
|
-
# @return [CyberarmEngine::Vector]
|
100
|
-
def +(other)
|
101
|
-
if other.is_a?(Numeric)
|
102
|
-
Vector.new(
|
103
|
-
@x + other,
|
104
|
-
@y + other,
|
105
|
-
@z + other
|
106
|
-
)
|
107
|
-
else
|
108
|
-
Vector.new(
|
109
|
-
@x + other.x,
|
110
|
-
@y + other.y,
|
111
|
-
@z + other.z
|
112
|
-
)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
# Subtracts Vector and Numeric or Vector and Vector, excluding {weight}
|
117
|
-
# @return [CyberarmEngine::Vector]
|
118
|
-
def -(other)
|
119
|
-
if other.is_a?(Numeric)
|
120
|
-
Vector.new(
|
121
|
-
@x - other,
|
122
|
-
@y - other,
|
123
|
-
@z - other
|
124
|
-
)
|
125
|
-
else
|
126
|
-
Vector.new(
|
127
|
-
@x - other.x,
|
128
|
-
@y - other.y,
|
129
|
-
@z - other.z
|
130
|
-
)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
# Multiplies Vector and Numeric or Vector and Vector, excluding {weight}
|
135
|
-
# @return [CyberarmEngine::Vector]
|
136
|
-
def *(other)
|
137
|
-
if other.is_a?(Numeric)
|
138
|
-
Vector.new(
|
139
|
-
@x * other,
|
140
|
-
@y * other,
|
141
|
-
@z * other
|
142
|
-
)
|
143
|
-
else
|
144
|
-
Vector.new(
|
145
|
-
@x * other.x,
|
146
|
-
@y * other.y,
|
147
|
-
@z * other.z
|
148
|
-
)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def multiply_transform(transform)
|
153
|
-
e = transform.elements
|
154
|
-
|
155
|
-
x = @x * e[0] + @y * e[1] + @z * e[2] + 1 * e[3]
|
156
|
-
y = @x * e[4] + @y * e[5] + @z * e[6] + 1 * e[7]
|
157
|
-
z = @x * e[8] + @y * e[9] + @z * e[10] + 1 * e[11]
|
158
|
-
w = @x * e[12] + @y * e[13] + @z * e[14] + 1 * e[15]
|
159
|
-
|
160
|
-
Vector.new(x / 1, y / 1, z / 1, w / 1)
|
161
|
-
end
|
162
|
-
|
163
|
-
# Divides Vector and Numeric or Vector and Vector, excluding {weight}
|
164
|
-
# @return [CyberarmEngine::Vector]
|
165
|
-
def /(other)
|
166
|
-
# Duplicated to protect from DivideByZero
|
167
|
-
if other.is_a?(Numeric)
|
168
|
-
Vector.new(
|
169
|
-
(@x == 0 ? 0 : @x / other),
|
170
|
-
(@y == 0 ? 0 : @y / other),
|
171
|
-
(@z == 0 ? 0 : @z / other)
|
172
|
-
)
|
173
|
-
else
|
174
|
-
Vector.new(
|
175
|
-
(@x == 0 ? 0 : @x / other.x),
|
176
|
-
(@y == 0 ? 0 : @y / other.y),
|
177
|
-
(@z == 0 ? 0 : @z / other.z)
|
178
|
-
)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
# dot product of {Vector}
|
183
|
-
# @return [Integer|Float]
|
184
|
-
def dot(other)
|
185
|
-
product = 0
|
186
|
-
|
187
|
-
a = to_a
|
188
|
-
b = other.to_a
|
189
|
-
|
190
|
-
3.times do |i|
|
191
|
-
product += (a[i] * b[i])
|
192
|
-
end
|
193
|
-
|
194
|
-
product
|
195
|
-
end
|
196
|
-
|
197
|
-
# cross product of {Vector}
|
198
|
-
# @return [CyberarmEngine::Vector]
|
199
|
-
def cross(other)
|
200
|
-
a = to_a
|
201
|
-
b = other.to_a
|
202
|
-
|
203
|
-
Vector.new(
|
204
|
-
b[2] * a[1] - b[1] * a[2],
|
205
|
-
b[0] * a[2] - b[2] * a[0],
|
206
|
-
b[1] * a[0] - b[0] * a[1]
|
207
|
-
)
|
208
|
-
end
|
209
|
-
|
210
|
-
# returns degrees
|
211
|
-
# @return [Float]
|
212
|
-
def angle(other)
|
213
|
-
Math.acos(normalized.dot(other.normalized)) * 180 / Math::PI
|
214
|
-
end
|
215
|
-
|
216
|
-
# returns magnitude of Vector, ignoring #weight
|
217
|
-
# @return [Float]
|
218
|
-
def magnitude
|
219
|
-
Math.sqrt((@x * @x) + (@y * @y) + (@z * @z))
|
220
|
-
end
|
221
|
-
|
222
|
-
##
|
223
|
-
# returns normalized {Vector}
|
224
|
-
#
|
225
|
-
# @example
|
226
|
-
# CyberarmEngine::Vector.new(50, 21.2, 45).normalized
|
227
|
-
# # => <CyberarmEngine::Vector:0x001 @x=0.7089... @y=0.3005... @z=0.6380... @weight=0>
|
228
|
-
#
|
229
|
-
# @return [CyberarmEngine::Vector]
|
230
|
-
def normalized
|
231
|
-
mag = magnitude
|
232
|
-
self / Vector.new(mag, mag, mag)
|
233
|
-
end
|
234
|
-
|
235
|
-
# returns a direction {Vector}
|
236
|
-
#
|
237
|
-
# z is pitch
|
238
|
-
#
|
239
|
-
# y is yaw
|
240
|
-
#
|
241
|
-
# x is roll
|
242
|
-
# @return [CyberarmEngine::Vector]
|
243
|
-
def direction
|
244
|
-
_x = -Math.sin(@y.degrees_to_radians) * Math.cos(@z.degrees_to_radians)
|
245
|
-
_y = Math.sin(@z.degrees_to_radians)
|
246
|
-
_z = Math.cos(@y.degrees_to_radians) * Math.cos(@z.degrees_to_radians)
|
247
|
-
|
248
|
-
Vector.new(_x, _y, _z)
|
249
|
-
end
|
250
|
-
|
251
|
-
# returns an inverse {Vector}
|
252
|
-
# @return [CyberarmEngine::Vector]
|
253
|
-
def inverse
|
254
|
-
Vector.new(1.0 / @x, 1.0 / @y, 1.0 / @z)
|
255
|
-
end
|
256
|
-
|
257
|
-
# Adds up values of {x}, {y}, and {z}
|
258
|
-
# @return [Integer|Float]
|
259
|
-
def sum
|
260
|
-
@x + @y + @z
|
261
|
-
end
|
262
|
-
|
263
|
-
##
|
264
|
-
# Linear interpolation: smoothly transition between two {Vector}
|
265
|
-
#
|
266
|
-
# CyberarmEngine::Vector.new(100, 100, 100).lerp( CyberarmEngine::Vector.new(0, 0, 0), 0.75 )
|
267
|
-
# # => <CyberarmEngine::Vector:0x0001 @x=75.0, @y=75.0, @z=75.0, @weight=0>
|
268
|
-
#
|
269
|
-
# @param other [CyberarmEngine::Vector | Integer | Float] value to subtract from
|
270
|
-
# @param factor [Float] how complete transition to _other_ is, in range [0.0..1.0]
|
271
|
-
# @return [CyberarmEngine::Vector]
|
272
|
-
def lerp(other, factor)
|
273
|
-
(self - other) * factor.clamp(0.0, 1.0)
|
274
|
-
end
|
275
|
-
|
276
|
-
# 2D distance using X and Y
|
277
|
-
# @return [Float]
|
278
|
-
def distance(other)
|
279
|
-
Math.sqrt((@x - other.x)**2 + (@y - other.y)**2)
|
280
|
-
end
|
281
|
-
|
282
|
-
# 2D distance using X and Z
|
283
|
-
# @return [Float]
|
284
|
-
def gl_distance2d(other)
|
285
|
-
Math.sqrt((@x - other.x)**2 + (@z - other.z)**2)
|
286
|
-
end
|
287
|
-
|
288
|
-
# 3D distance using X, Y, and Z
|
289
|
-
# @return [Float]
|
290
|
-
def distance3d(other)
|
291
|
-
Math.sqrt((@x - other.x)**2 + (@y - other.y)**2 + (@z - other.z)**2)
|
292
|
-
end
|
293
|
-
|
294
|
-
# Converts {Vector} to Array
|
295
|
-
# @return [Array]
|
296
|
-
def to_a
|
297
|
-
[@x, @y, @z, @weight]
|
298
|
-
end
|
299
|
-
|
300
|
-
# Converts {Vector} to String
|
301
|
-
# @return [String]
|
302
|
-
def to_s
|
303
|
-
"X: #{@x}, Y: #{@y}, Z: #{@z}, Weight: #{@weight}"
|
304
|
-
end
|
305
|
-
|
306
|
-
# Converts {Vector} to Hash
|
307
|
-
# @return [Hash]
|
308
|
-
def to_h
|
309
|
-
{ x: @x, y: @y, z: @z, weight: @weight }
|
310
|
-
end
|
311
|
-
end
|
312
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class Vector
|
3
|
+
##
|
4
|
+
# Creates a up vector
|
5
|
+
#
|
6
|
+
# Vector.new(0, 1, 0)
|
7
|
+
#
|
8
|
+
# @return [CyberarmEngine::Vector]
|
9
|
+
def self.up
|
10
|
+
Vector.new(0, 1, 0)
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# Creates a down vector
|
15
|
+
#
|
16
|
+
# Vector.new(0, -1, 0)
|
17
|
+
#
|
18
|
+
# @return [CyberarmEngine::Vector]
|
19
|
+
def self.down
|
20
|
+
Vector.new(0, -1, 0)
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Creates a left vector
|
25
|
+
#
|
26
|
+
# Vector.new(-1, 0, 0)
|
27
|
+
#
|
28
|
+
# @return [CyberarmEngine::Vector]
|
29
|
+
def self.left
|
30
|
+
Vector.new(-1, 0, 0)
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Creates a right vector
|
35
|
+
#
|
36
|
+
# Vector.new(1, 0, 0)
|
37
|
+
#
|
38
|
+
# @return [CyberarmEngine::Vector]
|
39
|
+
def self.right
|
40
|
+
Vector.new(1, 0, 0)
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Creates a forward vector
|
45
|
+
#
|
46
|
+
# Vector.new(0, 0, 1)
|
47
|
+
#
|
48
|
+
# @return [CyberarmEngine::Vector]
|
49
|
+
def self.forward
|
50
|
+
Vector.new(0, 0, 1)
|
51
|
+
end
|
52
|
+
|
53
|
+
##
|
54
|
+
# Creates a backward vector
|
55
|
+
#
|
56
|
+
# Vector.new(0, 0, -1)
|
57
|
+
#
|
58
|
+
# @return [CyberarmEngine::Vector]
|
59
|
+
def self.backward
|
60
|
+
Vector.new(0, 0, -1)
|
61
|
+
end
|
62
|
+
|
63
|
+
attr_accessor :x, :y, :z, :weight
|
64
|
+
|
65
|
+
def initialize(x = 0, y = 0, z = 0, weight = 0)
|
66
|
+
@x = x
|
67
|
+
@y = y
|
68
|
+
@z = z
|
69
|
+
@weight = weight
|
70
|
+
end
|
71
|
+
|
72
|
+
alias w weight
|
73
|
+
alias w= weight=
|
74
|
+
|
75
|
+
# @return [Boolean]
|
76
|
+
def ==(other)
|
77
|
+
if other.is_a?(Numeric)
|
78
|
+
@x == other &&
|
79
|
+
@y == other &&
|
80
|
+
@z == other &&
|
81
|
+
@weight == other
|
82
|
+
elsif other.is_a?(Vector)
|
83
|
+
@x == other.x &&
|
84
|
+
@y == other.y &&
|
85
|
+
@z == other.z &&
|
86
|
+
@weight == other.weight
|
87
|
+
else
|
88
|
+
other == self
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Create a new vector using {x} and {y} values
|
93
|
+
# @return [CyberarmEngine::Vector]
|
94
|
+
def xy
|
95
|
+
Vector.new(@x, @y)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Adds Vector and Numeric or Vector and Vector, excluding {weight}
|
99
|
+
# @return [CyberarmEngine::Vector]
|
100
|
+
def +(other)
|
101
|
+
if other.is_a?(Numeric)
|
102
|
+
Vector.new(
|
103
|
+
@x + other,
|
104
|
+
@y + other,
|
105
|
+
@z + other
|
106
|
+
)
|
107
|
+
else
|
108
|
+
Vector.new(
|
109
|
+
@x + other.x,
|
110
|
+
@y + other.y,
|
111
|
+
@z + other.z
|
112
|
+
)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Subtracts Vector and Numeric or Vector and Vector, excluding {weight}
|
117
|
+
# @return [CyberarmEngine::Vector]
|
118
|
+
def -(other)
|
119
|
+
if other.is_a?(Numeric)
|
120
|
+
Vector.new(
|
121
|
+
@x - other,
|
122
|
+
@y - other,
|
123
|
+
@z - other
|
124
|
+
)
|
125
|
+
else
|
126
|
+
Vector.new(
|
127
|
+
@x - other.x,
|
128
|
+
@y - other.y,
|
129
|
+
@z - other.z
|
130
|
+
)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# Multiplies Vector and Numeric or Vector and Vector, excluding {weight}
|
135
|
+
# @return [CyberarmEngine::Vector]
|
136
|
+
def *(other)
|
137
|
+
if other.is_a?(Numeric)
|
138
|
+
Vector.new(
|
139
|
+
@x * other,
|
140
|
+
@y * other,
|
141
|
+
@z * other
|
142
|
+
)
|
143
|
+
else
|
144
|
+
Vector.new(
|
145
|
+
@x * other.x,
|
146
|
+
@y * other.y,
|
147
|
+
@z * other.z
|
148
|
+
)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def multiply_transform(transform)
|
153
|
+
e = transform.elements
|
154
|
+
|
155
|
+
x = @x * e[0] + @y * e[1] + @z * e[2] + 1 * e[3]
|
156
|
+
y = @x * e[4] + @y * e[5] + @z * e[6] + 1 * e[7]
|
157
|
+
z = @x * e[8] + @y * e[9] + @z * e[10] + 1 * e[11]
|
158
|
+
w = @x * e[12] + @y * e[13] + @z * e[14] + 1 * e[15]
|
159
|
+
|
160
|
+
Vector.new(x / 1, y / 1, z / 1, w / 1)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Divides Vector and Numeric or Vector and Vector, excluding {weight}
|
164
|
+
# @return [CyberarmEngine::Vector]
|
165
|
+
def /(other)
|
166
|
+
# Duplicated to protect from DivideByZero
|
167
|
+
if other.is_a?(Numeric)
|
168
|
+
Vector.new(
|
169
|
+
(@x == 0 ? 0 : @x / other),
|
170
|
+
(@y == 0 ? 0 : @y / other),
|
171
|
+
(@z == 0 ? 0 : @z / other)
|
172
|
+
)
|
173
|
+
else
|
174
|
+
Vector.new(
|
175
|
+
(@x == 0 ? 0 : @x / other.x),
|
176
|
+
(@y == 0 ? 0 : @y / other.y),
|
177
|
+
(@z == 0 ? 0 : @z / other.z)
|
178
|
+
)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
# dot product of {Vector}
|
183
|
+
# @return [Integer|Float]
|
184
|
+
def dot(other)
|
185
|
+
product = 0
|
186
|
+
|
187
|
+
a = to_a
|
188
|
+
b = other.to_a
|
189
|
+
|
190
|
+
3.times do |i|
|
191
|
+
product += (a[i] * b[i])
|
192
|
+
end
|
193
|
+
|
194
|
+
product
|
195
|
+
end
|
196
|
+
|
197
|
+
# cross product of {Vector}
|
198
|
+
# @return [CyberarmEngine::Vector]
|
199
|
+
def cross(other)
|
200
|
+
a = to_a
|
201
|
+
b = other.to_a
|
202
|
+
|
203
|
+
Vector.new(
|
204
|
+
b[2] * a[1] - b[1] * a[2],
|
205
|
+
b[0] * a[2] - b[2] * a[0],
|
206
|
+
b[1] * a[0] - b[0] * a[1]
|
207
|
+
)
|
208
|
+
end
|
209
|
+
|
210
|
+
# returns degrees
|
211
|
+
# @return [Float]
|
212
|
+
def angle(other)
|
213
|
+
Math.acos(normalized.dot(other.normalized)) * 180 / Math::PI
|
214
|
+
end
|
215
|
+
|
216
|
+
# returns magnitude of Vector, ignoring #weight
|
217
|
+
# @return [Float]
|
218
|
+
def magnitude
|
219
|
+
Math.sqrt((@x * @x) + (@y * @y) + (@z * @z))
|
220
|
+
end
|
221
|
+
|
222
|
+
##
|
223
|
+
# returns normalized {Vector}
|
224
|
+
#
|
225
|
+
# @example
|
226
|
+
# CyberarmEngine::Vector.new(50, 21.2, 45).normalized
|
227
|
+
# # => <CyberarmEngine::Vector:0x001 @x=0.7089... @y=0.3005... @z=0.6380... @weight=0>
|
228
|
+
#
|
229
|
+
# @return [CyberarmEngine::Vector]
|
230
|
+
def normalized
|
231
|
+
mag = magnitude
|
232
|
+
self / Vector.new(mag, mag, mag)
|
233
|
+
end
|
234
|
+
|
235
|
+
# returns a direction {Vector}
|
236
|
+
#
|
237
|
+
# z is pitch
|
238
|
+
#
|
239
|
+
# y is yaw
|
240
|
+
#
|
241
|
+
# x is roll
|
242
|
+
# @return [CyberarmEngine::Vector]
|
243
|
+
def direction
|
244
|
+
_x = -Math.sin(@y.degrees_to_radians) * Math.cos(@z.degrees_to_radians)
|
245
|
+
_y = Math.sin(@z.degrees_to_radians)
|
246
|
+
_z = Math.cos(@y.degrees_to_radians) * Math.cos(@z.degrees_to_radians)
|
247
|
+
|
248
|
+
Vector.new(_x, _y, _z)
|
249
|
+
end
|
250
|
+
|
251
|
+
# returns an inverse {Vector}
|
252
|
+
# @return [CyberarmEngine::Vector]
|
253
|
+
def inverse
|
254
|
+
Vector.new(1.0 / @x, 1.0 / @y, 1.0 / @z)
|
255
|
+
end
|
256
|
+
|
257
|
+
# Adds up values of {x}, {y}, and {z}
|
258
|
+
# @return [Integer|Float]
|
259
|
+
def sum
|
260
|
+
@x + @y + @z
|
261
|
+
end
|
262
|
+
|
263
|
+
##
|
264
|
+
# Linear interpolation: smoothly transition between two {Vector}
|
265
|
+
#
|
266
|
+
# CyberarmEngine::Vector.new(100, 100, 100).lerp( CyberarmEngine::Vector.new(0, 0, 0), 0.75 )
|
267
|
+
# # => <CyberarmEngine::Vector:0x0001 @x=75.0, @y=75.0, @z=75.0, @weight=0>
|
268
|
+
#
|
269
|
+
# @param other [CyberarmEngine::Vector | Integer | Float] value to subtract from
|
270
|
+
# @param factor [Float] how complete transition to _other_ is, in range [0.0..1.0]
|
271
|
+
# @return [CyberarmEngine::Vector]
|
272
|
+
def lerp(other, factor)
|
273
|
+
(self - other) * factor.clamp(0.0, 1.0)
|
274
|
+
end
|
275
|
+
|
276
|
+
# 2D distance using X and Y
|
277
|
+
# @return [Float]
|
278
|
+
def distance(other)
|
279
|
+
Math.sqrt((@x - other.x)**2 + (@y - other.y)**2)
|
280
|
+
end
|
281
|
+
|
282
|
+
# 2D distance using X and Z
|
283
|
+
# @return [Float]
|
284
|
+
def gl_distance2d(other)
|
285
|
+
Math.sqrt((@x - other.x)**2 + (@z - other.z)**2)
|
286
|
+
end
|
287
|
+
|
288
|
+
# 3D distance using X, Y, and Z
|
289
|
+
# @return [Float]
|
290
|
+
def distance3d(other)
|
291
|
+
Math.sqrt((@x - other.x)**2 + (@y - other.y)**2 + (@z - other.z)**2)
|
292
|
+
end
|
293
|
+
|
294
|
+
# Converts {Vector} to Array
|
295
|
+
# @return [Array]
|
296
|
+
def to_a
|
297
|
+
[@x, @y, @z, @weight]
|
298
|
+
end
|
299
|
+
|
300
|
+
# Converts {Vector} to String
|
301
|
+
# @return [String]
|
302
|
+
def to_s
|
303
|
+
"X: #{@x}, Y: #{@y}, Z: #{@z}, Weight: #{@weight}"
|
304
|
+
end
|
305
|
+
|
306
|
+
# Converts {Vector} to Hash
|
307
|
+
# @return [Hash]
|
308
|
+
def to_h
|
309
|
+
{ x: @x, y: @y, z: @z, weight: @weight }
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
NAME = "InDev".freeze
|
3
|
-
VERSION = "0.24.
|
4
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
NAME = "InDev".freeze
|
3
|
+
VERSION = "0.24.5".freeze
|
4
|
+
end
|