cyberarm_engine 0.19.0 → 0.19.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -8
- data/.rubocop.yml +7 -7
- data/.travis.yml +5 -5
- data/Gemfile +6 -6
- data/LICENSE.txt +21 -21
- data/README.md +74 -74
- data/Rakefile +10 -10
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/cyberarm_engine.gemspec +39 -39
- data/lib/cyberarm_engine/animator.rb +219 -219
- data/lib/cyberarm_engine/background.rb +179 -179
- 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 +121 -121
- data/lib/cyberarm_engine/cache.rb +4 -4
- data/lib/cyberarm_engine/common.rb +113 -113
- 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 +248 -248
- data/lib/cyberarm_engine/game_state.rb +97 -97
- data/lib/cyberarm_engine/model/material.rb +21 -21
- data/lib/cyberarm_engine/model/model_object.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 +212 -212
- data/lib/cyberarm_engine/model_cache.rb +31 -31
- data/lib/cyberarm_engine/opengl/light.rb +50 -50
- data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +38 -38
- data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
- data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +164 -164
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +298 -298
- data/lib/cyberarm_engine/opengl/renderer/renderer.rb +22 -22
- data/lib/cyberarm_engine/opengl/shader.rb +406 -406
- data/lib/cyberarm_engine/opengl/texture.rb +69 -69
- data/lib/cyberarm_engine/opengl.rb +28 -28
- data/lib/cyberarm_engine/ray.rb +56 -56
- data/lib/cyberarm_engine/stats.rb +21 -21
- data/lib/cyberarm_engine/text.rb +197 -197
- data/lib/cyberarm_engine/timer.rb +23 -23
- data/lib/cyberarm_engine/transform.rb +296 -296
- data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
- data/lib/cyberarm_engine/ui/dsl.rb +139 -139
- data/lib/cyberarm_engine/ui/element.rb +488 -488
- data/lib/cyberarm_engine/ui/elements/button.rb +97 -97
- data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
- data/lib/cyberarm_engine/ui/elements/container.rb +256 -256
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +263 -263
- 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 +88 -82
- data/lib/cyberarm_engine/ui/elements/progress.rb +51 -51
- data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/slider.rb +104 -104
- data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
- data/lib/cyberarm_engine/ui/elements/text_block.rb +162 -162
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +65 -65
- data/lib/cyberarm_engine/ui/event.rb +54 -54
- data/lib/cyberarm_engine/ui/gui_state.rb +256 -256
- data/lib/cyberarm_engine/ui/style.rb +49 -49
- data/lib/cyberarm_engine/ui/theme.rb +207 -207
- data/lib/cyberarm_engine/vector.rb +293 -293
- data/lib/cyberarm_engine/version.rb +4 -4
- data/lib/cyberarm_engine/window.rb +120 -120
- data/lib/cyberarm_engine.rb +71 -71
- metadata +3 -3
@@ -1,293 +1,293 @@
|
|
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
|
-
# Performs math operation, excluding {weight}
|
99
|
-
private def operator(function, other)
|
100
|
-
if other.is_a?(Numeric)
|
101
|
-
Vector.new(
|
102
|
-
@x.send(:"#{function}", other),
|
103
|
-
@y.send(:"#{function}", other),
|
104
|
-
@z.send(:"#{function}", other)
|
105
|
-
)
|
106
|
-
else
|
107
|
-
Vector.new(
|
108
|
-
@x.send(:"#{function}", other.x),
|
109
|
-
@y.send(:"#{function}", other.y),
|
110
|
-
@z.send(:"#{function}", other.z)
|
111
|
-
)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# Adds Vector and Numeric or Vector and Vector, excluding {weight}
|
116
|
-
# @return [CyberarmEngine::Vector]
|
117
|
-
def +(other)
|
118
|
-
operator("+", other)
|
119
|
-
end
|
120
|
-
|
121
|
-
# Subtracts Vector and Numeric or Vector and Vector, excluding {weight}
|
122
|
-
# @return [CyberarmEngine::Vector]
|
123
|
-
def -(other)
|
124
|
-
operator("-", other)
|
125
|
-
end
|
126
|
-
|
127
|
-
# Multiplies Vector and Numeric or Vector and Vector, excluding {weight}
|
128
|
-
# @return [CyberarmEngine::Vector]
|
129
|
-
def *(other)
|
130
|
-
operator("*", other)
|
131
|
-
end
|
132
|
-
|
133
|
-
def multiply_transform(transform)
|
134
|
-
e = transform.elements
|
135
|
-
|
136
|
-
x = @x * e[0] + @y * e[1] + @z * e[2] + 1 * e[3]
|
137
|
-
y = @x * e[4] + @y * e[5] + @z * e[6] + 1 * e[7]
|
138
|
-
z = @x * e[8] + @y * e[9] + @z * e[10] + 1 * e[11]
|
139
|
-
w = @x * e[12] + @y * e[13] + @z * e[14] + 1 * e[15]
|
140
|
-
|
141
|
-
Vector.new(x / 1, y / 1, z / 1, w / 1)
|
142
|
-
end
|
143
|
-
|
144
|
-
# Divides Vector and Numeric or Vector and Vector, excluding {weight}
|
145
|
-
# @return [CyberarmEngine::Vector]
|
146
|
-
def /(other)
|
147
|
-
# Duplicated to protect from DivideByZero
|
148
|
-
if other.is_a?(Numeric)
|
149
|
-
Vector.new(
|
150
|
-
(@x == 0 ? 0 : @x / other),
|
151
|
-
(@y == 0 ? 0 : @y / other),
|
152
|
-
(@z == 0 ? 0 : @z / other)
|
153
|
-
)
|
154
|
-
else
|
155
|
-
Vector.new(
|
156
|
-
(@x == 0 ? 0 : @x / other.x),
|
157
|
-
(@y == 0 ? 0 : @y / other.y),
|
158
|
-
(@z == 0 ? 0 : @z / other.z)
|
159
|
-
)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
# dot product of {Vector}
|
164
|
-
# @return [Integer|Float]
|
165
|
-
def dot(other)
|
166
|
-
product = 0
|
167
|
-
|
168
|
-
a = to_a
|
169
|
-
b = other.to_a
|
170
|
-
|
171
|
-
3.times do |i|
|
172
|
-
product += (a[i] * b[i])
|
173
|
-
end
|
174
|
-
|
175
|
-
product
|
176
|
-
end
|
177
|
-
|
178
|
-
# cross product of {Vector}
|
179
|
-
# @return [CyberarmEngine::Vector]
|
180
|
-
def cross(other)
|
181
|
-
a = to_a
|
182
|
-
b = other.to_a
|
183
|
-
|
184
|
-
Vector.new(
|
185
|
-
b[2] * a[1] - b[1] * a[2],
|
186
|
-
b[0] * a[2] - b[2] * a[0],
|
187
|
-
b[1] * a[0] - b[0] * a[1]
|
188
|
-
)
|
189
|
-
end
|
190
|
-
|
191
|
-
# returns degrees
|
192
|
-
# @return [Float]
|
193
|
-
def angle(other)
|
194
|
-
Math.acos(normalized.dot(other.normalized)) * 180 / Math::PI
|
195
|
-
end
|
196
|
-
|
197
|
-
# returns magnitude of Vector, ignoring #weight
|
198
|
-
# @return [Float]
|
199
|
-
def magnitude
|
200
|
-
Math.sqrt((@x * @x) + (@y * @y) + (@z * @z))
|
201
|
-
end
|
202
|
-
|
203
|
-
##
|
204
|
-
# returns normalized {Vector}
|
205
|
-
#
|
206
|
-
# @example
|
207
|
-
# CyberarmEngine::Vector.new(50, 21.2, 45).normalized
|
208
|
-
# # => <CyberarmEngine::Vector:0x001 @x=0.7089... @y=0.3005... @z=0.6380... @weight=0>
|
209
|
-
#
|
210
|
-
# @return [CyberarmEngine::Vector]
|
211
|
-
def normalized
|
212
|
-
mag = magnitude
|
213
|
-
self / Vector.new(mag, mag, mag)
|
214
|
-
end
|
215
|
-
|
216
|
-
# returns a direction {Vector}
|
217
|
-
#
|
218
|
-
# z is pitch
|
219
|
-
#
|
220
|
-
# y is yaw
|
221
|
-
#
|
222
|
-
# x is roll
|
223
|
-
# @return [CyberarmEngine::Vector]
|
224
|
-
def direction
|
225
|
-
_x = -Math.sin(@y.degrees_to_radians) * Math.cos(@z.degrees_to_radians)
|
226
|
-
_y = Math.sin(@z.degrees_to_radians)
|
227
|
-
_z = Math.cos(@y.degrees_to_radians) * Math.cos(@z.degrees_to_radians)
|
228
|
-
|
229
|
-
Vector.new(_x, _y, _z)
|
230
|
-
end
|
231
|
-
|
232
|
-
# returns an inverse {Vector}
|
233
|
-
# @return [CyberarmEngine::Vector]
|
234
|
-
def inverse
|
235
|
-
Vector.new(1.0 / @x, 1.0 / @y, 1.0 / @z)
|
236
|
-
end
|
237
|
-
|
238
|
-
# Adds up values of {x}, {y}, and {z}
|
239
|
-
# @return [Integer|Float]
|
240
|
-
def sum
|
241
|
-
@x + @y + @z
|
242
|
-
end
|
243
|
-
|
244
|
-
##
|
245
|
-
# Linear interpolation: smoothly transition between two {Vector}
|
246
|
-
#
|
247
|
-
# CyberarmEngine::Vector.new(100, 100, 100).lerp( CyberarmEngine::Vector.new(0, 0, 0), 0.75 )
|
248
|
-
# # => <CyberarmEngine::Vector:0x0001 @x=75.0, @y=75.0, @z=75.0, @weight=0>
|
249
|
-
#
|
250
|
-
# @param other [CyberarmEngine::Vector | Integer | Float] value to subtract from
|
251
|
-
# @param factor [Float] how complete transition to _other_ is, in range [0.0..1.0]
|
252
|
-
# @return [CyberarmEngine::Vector]
|
253
|
-
def lerp(other, factor)
|
254
|
-
(self - other) * factor.clamp(0.0, 1.0)
|
255
|
-
end
|
256
|
-
|
257
|
-
# 2D distance using X and Y
|
258
|
-
# @return [Float]
|
259
|
-
def distance(other)
|
260
|
-
Math.sqrt((@x - other.x)**2 + (@y - other.y)**2)
|
261
|
-
end
|
262
|
-
|
263
|
-
# 2D distance using X and Z
|
264
|
-
# @return [Float]
|
265
|
-
def gl_distance2d(other)
|
266
|
-
Math.sqrt((@x - other.x)**2 + (@z - other.z)**2)
|
267
|
-
end
|
268
|
-
|
269
|
-
# 3D distance using X, Y, and Z
|
270
|
-
# @return [Float]
|
271
|
-
def distance3d(other)
|
272
|
-
Math.sqrt((@x - other.x)**2 + (@y - other.y)**2 + (@z - other.z)**2)
|
273
|
-
end
|
274
|
-
|
275
|
-
# Converts {Vector} to Array
|
276
|
-
# @return [Array]
|
277
|
-
def to_a
|
278
|
-
[@x, @y, @z, @weight]
|
279
|
-
end
|
280
|
-
|
281
|
-
# Converts {Vector} to String
|
282
|
-
# @return [String]
|
283
|
-
def to_s
|
284
|
-
"X: #{@x}, Y: #{@y}, Z: #{@z}, Weight: #{@weight}"
|
285
|
-
end
|
286
|
-
|
287
|
-
# Converts {Vector} to Hash
|
288
|
-
# @return [Hash]
|
289
|
-
def to_h
|
290
|
-
{ x: @x, y: @y, z: @z, weight: @weight }
|
291
|
-
end
|
292
|
-
end
|
293
|
-
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
|
+
# Performs math operation, excluding {weight}
|
99
|
+
private def operator(function, other)
|
100
|
+
if other.is_a?(Numeric)
|
101
|
+
Vector.new(
|
102
|
+
@x.send(:"#{function}", other),
|
103
|
+
@y.send(:"#{function}", other),
|
104
|
+
@z.send(:"#{function}", other)
|
105
|
+
)
|
106
|
+
else
|
107
|
+
Vector.new(
|
108
|
+
@x.send(:"#{function}", other.x),
|
109
|
+
@y.send(:"#{function}", other.y),
|
110
|
+
@z.send(:"#{function}", other.z)
|
111
|
+
)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Adds Vector and Numeric or Vector and Vector, excluding {weight}
|
116
|
+
# @return [CyberarmEngine::Vector]
|
117
|
+
def +(other)
|
118
|
+
operator("+", other)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Subtracts Vector and Numeric or Vector and Vector, excluding {weight}
|
122
|
+
# @return [CyberarmEngine::Vector]
|
123
|
+
def -(other)
|
124
|
+
operator("-", other)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Multiplies Vector and Numeric or Vector and Vector, excluding {weight}
|
128
|
+
# @return [CyberarmEngine::Vector]
|
129
|
+
def *(other)
|
130
|
+
operator("*", other)
|
131
|
+
end
|
132
|
+
|
133
|
+
def multiply_transform(transform)
|
134
|
+
e = transform.elements
|
135
|
+
|
136
|
+
x = @x * e[0] + @y * e[1] + @z * e[2] + 1 * e[3]
|
137
|
+
y = @x * e[4] + @y * e[5] + @z * e[6] + 1 * e[7]
|
138
|
+
z = @x * e[8] + @y * e[9] + @z * e[10] + 1 * e[11]
|
139
|
+
w = @x * e[12] + @y * e[13] + @z * e[14] + 1 * e[15]
|
140
|
+
|
141
|
+
Vector.new(x / 1, y / 1, z / 1, w / 1)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Divides Vector and Numeric or Vector and Vector, excluding {weight}
|
145
|
+
# @return [CyberarmEngine::Vector]
|
146
|
+
def /(other)
|
147
|
+
# Duplicated to protect from DivideByZero
|
148
|
+
if other.is_a?(Numeric)
|
149
|
+
Vector.new(
|
150
|
+
(@x == 0 ? 0 : @x / other),
|
151
|
+
(@y == 0 ? 0 : @y / other),
|
152
|
+
(@z == 0 ? 0 : @z / other)
|
153
|
+
)
|
154
|
+
else
|
155
|
+
Vector.new(
|
156
|
+
(@x == 0 ? 0 : @x / other.x),
|
157
|
+
(@y == 0 ? 0 : @y / other.y),
|
158
|
+
(@z == 0 ? 0 : @z / other.z)
|
159
|
+
)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# dot product of {Vector}
|
164
|
+
# @return [Integer|Float]
|
165
|
+
def dot(other)
|
166
|
+
product = 0
|
167
|
+
|
168
|
+
a = to_a
|
169
|
+
b = other.to_a
|
170
|
+
|
171
|
+
3.times do |i|
|
172
|
+
product += (a[i] * b[i])
|
173
|
+
end
|
174
|
+
|
175
|
+
product
|
176
|
+
end
|
177
|
+
|
178
|
+
# cross product of {Vector}
|
179
|
+
# @return [CyberarmEngine::Vector]
|
180
|
+
def cross(other)
|
181
|
+
a = to_a
|
182
|
+
b = other.to_a
|
183
|
+
|
184
|
+
Vector.new(
|
185
|
+
b[2] * a[1] - b[1] * a[2],
|
186
|
+
b[0] * a[2] - b[2] * a[0],
|
187
|
+
b[1] * a[0] - b[0] * a[1]
|
188
|
+
)
|
189
|
+
end
|
190
|
+
|
191
|
+
# returns degrees
|
192
|
+
# @return [Float]
|
193
|
+
def angle(other)
|
194
|
+
Math.acos(normalized.dot(other.normalized)) * 180 / Math::PI
|
195
|
+
end
|
196
|
+
|
197
|
+
# returns magnitude of Vector, ignoring #weight
|
198
|
+
# @return [Float]
|
199
|
+
def magnitude
|
200
|
+
Math.sqrt((@x * @x) + (@y * @y) + (@z * @z))
|
201
|
+
end
|
202
|
+
|
203
|
+
##
|
204
|
+
# returns normalized {Vector}
|
205
|
+
#
|
206
|
+
# @example
|
207
|
+
# CyberarmEngine::Vector.new(50, 21.2, 45).normalized
|
208
|
+
# # => <CyberarmEngine::Vector:0x001 @x=0.7089... @y=0.3005... @z=0.6380... @weight=0>
|
209
|
+
#
|
210
|
+
# @return [CyberarmEngine::Vector]
|
211
|
+
def normalized
|
212
|
+
mag = magnitude
|
213
|
+
self / Vector.new(mag, mag, mag)
|
214
|
+
end
|
215
|
+
|
216
|
+
# returns a direction {Vector}
|
217
|
+
#
|
218
|
+
# z is pitch
|
219
|
+
#
|
220
|
+
# y is yaw
|
221
|
+
#
|
222
|
+
# x is roll
|
223
|
+
# @return [CyberarmEngine::Vector]
|
224
|
+
def direction
|
225
|
+
_x = -Math.sin(@y.degrees_to_radians) * Math.cos(@z.degrees_to_radians)
|
226
|
+
_y = Math.sin(@z.degrees_to_radians)
|
227
|
+
_z = Math.cos(@y.degrees_to_radians) * Math.cos(@z.degrees_to_radians)
|
228
|
+
|
229
|
+
Vector.new(_x, _y, _z)
|
230
|
+
end
|
231
|
+
|
232
|
+
# returns an inverse {Vector}
|
233
|
+
# @return [CyberarmEngine::Vector]
|
234
|
+
def inverse
|
235
|
+
Vector.new(1.0 / @x, 1.0 / @y, 1.0 / @z)
|
236
|
+
end
|
237
|
+
|
238
|
+
# Adds up values of {x}, {y}, and {z}
|
239
|
+
# @return [Integer|Float]
|
240
|
+
def sum
|
241
|
+
@x + @y + @z
|
242
|
+
end
|
243
|
+
|
244
|
+
##
|
245
|
+
# Linear interpolation: smoothly transition between two {Vector}
|
246
|
+
#
|
247
|
+
# CyberarmEngine::Vector.new(100, 100, 100).lerp( CyberarmEngine::Vector.new(0, 0, 0), 0.75 )
|
248
|
+
# # => <CyberarmEngine::Vector:0x0001 @x=75.0, @y=75.0, @z=75.0, @weight=0>
|
249
|
+
#
|
250
|
+
# @param other [CyberarmEngine::Vector | Integer | Float] value to subtract from
|
251
|
+
# @param factor [Float] how complete transition to _other_ is, in range [0.0..1.0]
|
252
|
+
# @return [CyberarmEngine::Vector]
|
253
|
+
def lerp(other, factor)
|
254
|
+
(self - other) * factor.clamp(0.0, 1.0)
|
255
|
+
end
|
256
|
+
|
257
|
+
# 2D distance using X and Y
|
258
|
+
# @return [Float]
|
259
|
+
def distance(other)
|
260
|
+
Math.sqrt((@x - other.x)**2 + (@y - other.y)**2)
|
261
|
+
end
|
262
|
+
|
263
|
+
# 2D distance using X and Z
|
264
|
+
# @return [Float]
|
265
|
+
def gl_distance2d(other)
|
266
|
+
Math.sqrt((@x - other.x)**2 + (@z - other.z)**2)
|
267
|
+
end
|
268
|
+
|
269
|
+
# 3D distance using X, Y, and Z
|
270
|
+
# @return [Float]
|
271
|
+
def distance3d(other)
|
272
|
+
Math.sqrt((@x - other.x)**2 + (@y - other.y)**2 + (@z - other.z)**2)
|
273
|
+
end
|
274
|
+
|
275
|
+
# Converts {Vector} to Array
|
276
|
+
# @return [Array]
|
277
|
+
def to_a
|
278
|
+
[@x, @y, @z, @weight]
|
279
|
+
end
|
280
|
+
|
281
|
+
# Converts {Vector} to String
|
282
|
+
# @return [String]
|
283
|
+
def to_s
|
284
|
+
"X: #{@x}, Y: #{@y}, Z: #{@z}, Weight: #{@weight}"
|
285
|
+
end
|
286
|
+
|
287
|
+
# Converts {Vector} to Hash
|
288
|
+
# @return [Hash]
|
289
|
+
def to_h
|
290
|
+
{ x: @x, y: @y, z: @z, weight: @weight }
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
NAME = "InDev".freeze
|
3
|
-
VERSION = "0.19.
|
4
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
NAME = "InDev".freeze
|
3
|
+
VERSION = "0.19.1".freeze
|
4
|
+
end
|