cyberarm_engine 0.13.0 → 0.17.0
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 +8 -0
- data/.travis.yml +5 -5
- data/Gemfile +6 -6
- data/LICENSE.txt +21 -21
- data/README.md +73 -43
- data/Rakefile +10 -10
- data/assets/textures/default.png +0 -0
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/cyberarm_engine.gemspec +39 -36
- data/lib/cyberarm_engine.rb +64 -47
- data/lib/cyberarm_engine/animator.rb +56 -54
- data/lib/cyberarm_engine/background.rb +179 -175
- data/lib/cyberarm_engine/background_nine_slice.rb +125 -0
- data/lib/cyberarm_engine/bounding_box.rb +150 -150
- data/lib/cyberarm_engine/cache.rb +4 -0
- data/lib/cyberarm_engine/cache/download_manager.rb +121 -0
- data/lib/cyberarm_engine/common.rb +96 -96
- data/lib/cyberarm_engine/config_file.rb +46 -0
- data/lib/cyberarm_engine/game_object.rb +248 -257
- data/lib/cyberarm_engine/game_state.rb +92 -89
- data/lib/cyberarm_engine/model.rb +207 -0
- data/lib/cyberarm_engine/model/material.rb +21 -0
- data/lib/cyberarm_engine/model/model_object.rb +131 -0
- data/lib/cyberarm_engine/model/parser.rb +74 -0
- data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -0
- data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -0
- data/lib/cyberarm_engine/model_cache.rb +31 -0
- data/lib/cyberarm_engine/opengl.rb +28 -0
- data/lib/cyberarm_engine/opengl/light.rb +50 -0
- data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -0
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +38 -0
- data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -0
- data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +164 -0
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +289 -0
- data/lib/cyberarm_engine/opengl/renderer/renderer.rb +22 -0
- data/lib/cyberarm_engine/opengl/shader.rb +406 -0
- data/lib/cyberarm_engine/opengl/texture.rb +69 -0
- data/lib/cyberarm_engine/ray.rb +56 -56
- data/lib/cyberarm_engine/stats.rb +21 -0
- data/lib/cyberarm_engine/text.rb +160 -146
- data/lib/cyberarm_engine/timer.rb +23 -23
- data/lib/cyberarm_engine/transform.rb +296 -273
- data/lib/cyberarm_engine/ui/border_canvas.rb +102 -101
- data/lib/cyberarm_engine/ui/dsl.rb +138 -99
- data/lib/cyberarm_engine/ui/element.rb +315 -276
- data/lib/cyberarm_engine/ui/elements/button.rb +160 -67
- data/lib/cyberarm_engine/ui/elements/check_box.rb +51 -59
- data/lib/cyberarm_engine/ui/elements/container.rb +256 -176
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -0
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +262 -172
- data/lib/cyberarm_engine/ui/elements/flow.rb +15 -17
- data/lib/cyberarm_engine/ui/elements/image.rb +72 -52
- data/lib/cyberarm_engine/ui/elements/label.rb +156 -50
- data/lib/cyberarm_engine/ui/elements/list_box.rb +82 -0
- data/lib/cyberarm_engine/ui/elements/progress.rb +51 -50
- data/lib/cyberarm_engine/ui/elements/radio.rb +6 -0
- data/lib/cyberarm_engine/ui/elements/slider.rb +104 -0
- data/lib/cyberarm_engine/ui/elements/stack.rb +11 -13
- data/lib/cyberarm_engine/ui/elements/text_block.rb +156 -0
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +65 -56
- data/lib/cyberarm_engine/ui/event.rb +47 -47
- data/lib/cyberarm_engine/ui/gui_state.rb +226 -135
- data/lib/cyberarm_engine/ui/style.rb +38 -37
- data/lib/cyberarm_engine/ui/theme.rb +182 -120
- data/lib/cyberarm_engine/vector.rb +293 -203
- data/lib/cyberarm_engine/version.rb +4 -4
- data/lib/cyberarm_engine/{engine.rb → window.rb} +114 -101
- metadata +88 -18
- data/lib/cyberarm_engine/gosu_ext/circle.rb +0 -9
- data/lib/cyberarm_engine/shader.rb +0 -262
@@ -1,203 +1,293 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Vector
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def self.
|
20
|
-
Vector.new(0,
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
(
|
103
|
-
(
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
(
|
109
|
-
(
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
end
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
def
|
200
|
-
|
201
|
-
end
|
202
|
-
|
203
|
-
|
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
|