raylib-bindings 0.5.8pre1-arm64-darwin → 0.6.1-arm64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +436 -399
- data/LICENSE.txt +1 -1
- data/README.md +191 -176
- data/examples/template.rb +144 -143
- data/lib/config.rb +103 -103
- data/lib/libraylib.arm64.dylib +0 -0
- data/lib/physac.arm64.dylib +0 -0
- data/lib/physac.rb +322 -322
- data/lib/raygui.arm64.dylib +0 -0
- data/lib/raygui_helper.rb +127 -127
- data/lib/raygui_main.rb +890 -890
- data/lib/raylib.rb +62 -62
- data/lib/raylib_helper.rb +412 -400
- data/lib/raylib_main.rb +5125 -5088
- data/lib/raymath.rb +845 -845
- data/lib/rcamera.rb +117 -117
- data/lib/rlgl.rb +1327 -1311
- metadata +5 -19
data/lib/raylib_helper.rb
CHANGED
@@ -1,400 +1,412 @@
|
|
1
|
-
# Yet another raylib wrapper for Ruby
|
2
|
-
#
|
3
|
-
# * https://github.com/vaiorabbit/raylib-bindings
|
4
|
-
|
5
|
-
module Raylib
|
6
|
-
#
|
7
|
-
# Color helper
|
8
|
-
#
|
9
|
-
|
10
|
-
class Color
|
11
|
-
def self.from_u8(r = 0, g = 0, b = 0, a = 255)
|
12
|
-
Color.new.set(r, g, b, a)
|
13
|
-
end
|
14
|
-
|
15
|
-
def set(r, g, b, a)
|
16
|
-
self[:r] = r
|
17
|
-
self[:g] = g
|
18
|
-
self[:b] = b
|
19
|
-
self[:a] = a
|
20
|
-
self
|
21
|
-
end
|
22
|
-
|
23
|
-
def copy(other)
|
24
|
-
self[:r] = other.r
|
25
|
-
self[:g] = other.g
|
26
|
-
self[:b] = other.b
|
27
|
-
self[:a] = other.a
|
28
|
-
self
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
LIGHTGRAY = Color.from_u8(200, 200, 200, 255)
|
33
|
-
GRAY = Color.from_u8(130, 130, 130, 255)
|
34
|
-
DARKGRAY = Color.from_u8(80, 80, 80, 255)
|
35
|
-
YELLOW = Color.from_u8(253, 249, 0, 255)
|
36
|
-
GOLD = Color.from_u8(255, 203, 0, 255)
|
37
|
-
ORANGE = Color.from_u8(255, 161, 0, 255)
|
38
|
-
PINK = Color.from_u8(255, 109, 194, 255)
|
39
|
-
RED = Color.from_u8(230, 41, 55, 255)
|
40
|
-
MAROON = Color.from_u8(190, 33, 55, 255)
|
41
|
-
GREEN = Color.from_u8(0, 228, 48, 255)
|
42
|
-
LIME = Color.from_u8(0, 158, 47, 255)
|
43
|
-
DARKGREEN = Color.from_u8(0, 117, 44, 255)
|
44
|
-
SKYBLUE = Color.from_u8(102, 191, 255, 255)
|
45
|
-
BLUE = Color.from_u8(0, 121, 241, 255)
|
46
|
-
DARKBLUE = Color.from_u8(0, 82, 172, 255)
|
47
|
-
PURPLE = Color.from_u8(200, 122, 255, 255)
|
48
|
-
VIOLET = Color.from_u8(135, 60, 190, 255)
|
49
|
-
DARKPURPLE = Color.from_u8(112, 31, 126, 255)
|
50
|
-
BEIGE = Color.from_u8(211, 176, 131, 255)
|
51
|
-
BROWN = Color.from_u8(127, 106, 79, 255)
|
52
|
-
DARKBROWN = Color.from_u8(76, 63, 47, 255)
|
53
|
-
|
54
|
-
WHITE = Color.from_u8(255, 255, 255, 255)
|
55
|
-
BLACK = Color.from_u8(0, 0, 0, 255)
|
56
|
-
BLANK = Color.from_u8(0, 0, 0, 0)
|
57
|
-
MAGENTA = Color.from_u8(255, 0, 255, 255)
|
58
|
-
RAYWHITE = Color.from_u8(245, 245, 245, 255)
|
59
|
-
|
60
|
-
#
|
61
|
-
# Math helper
|
62
|
-
#
|
63
|
-
|
64
|
-
class Vector2
|
65
|
-
def self.create(x = 0, y = 0)
|
66
|
-
Vector2.new.set(x, y)
|
67
|
-
end
|
68
|
-
|
69
|
-
def self.copy_from(vec)
|
70
|
-
Vector2.create(vec[:x], vec[:y])
|
71
|
-
end
|
72
|
-
|
73
|
-
def set(x, y)
|
74
|
-
self[:x] = x
|
75
|
-
self[:y] = y
|
76
|
-
self
|
77
|
-
end
|
78
|
-
|
79
|
-
def
|
80
|
-
[x
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
def
|
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
|
-
end
|
121
|
-
|
122
|
-
def
|
123
|
-
[x, y, z, w]
|
124
|
-
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
end
|
143
|
-
|
144
|
-
def
|
145
|
-
[x, y, z, w]
|
146
|
-
end
|
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
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
def
|
233
|
-
self[:
|
234
|
-
self
|
235
|
-
end
|
236
|
-
|
237
|
-
def
|
238
|
-
self[:
|
239
|
-
self
|
240
|
-
end
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
def
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
#
|
266
|
-
|
267
|
-
#
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
#
|
289
|
-
#
|
290
|
-
#
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
#
|
302
|
-
# @return [
|
303
|
-
def
|
304
|
-
self[:
|
305
|
-
end
|
306
|
-
|
307
|
-
#
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
end
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
#
|
391
|
-
# @
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
end
|
1
|
+
# Yet another raylib wrapper for Ruby
|
2
|
+
#
|
3
|
+
# * https://github.com/vaiorabbit/raylib-bindings
|
4
|
+
|
5
|
+
module Raylib
|
6
|
+
#
|
7
|
+
# Color helper
|
8
|
+
#
|
9
|
+
|
10
|
+
class Color
|
11
|
+
def self.from_u8(r = 0, g = 0, b = 0, a = 255)
|
12
|
+
Color.new.set(r, g, b, a)
|
13
|
+
end
|
14
|
+
|
15
|
+
def set(r, g, b, a)
|
16
|
+
self[:r] = r
|
17
|
+
self[:g] = g
|
18
|
+
self[:b] = b
|
19
|
+
self[:a] = a
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def copy(other)
|
24
|
+
self[:r] = other.r
|
25
|
+
self[:g] = other.g
|
26
|
+
self[:b] = other.b
|
27
|
+
self[:a] = other.a
|
28
|
+
self
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
LIGHTGRAY = Color.from_u8(200, 200, 200, 255)
|
33
|
+
GRAY = Color.from_u8(130, 130, 130, 255)
|
34
|
+
DARKGRAY = Color.from_u8(80, 80, 80, 255)
|
35
|
+
YELLOW = Color.from_u8(253, 249, 0, 255)
|
36
|
+
GOLD = Color.from_u8(255, 203, 0, 255)
|
37
|
+
ORANGE = Color.from_u8(255, 161, 0, 255)
|
38
|
+
PINK = Color.from_u8(255, 109, 194, 255)
|
39
|
+
RED = Color.from_u8(230, 41, 55, 255)
|
40
|
+
MAROON = Color.from_u8(190, 33, 55, 255)
|
41
|
+
GREEN = Color.from_u8(0, 228, 48, 255)
|
42
|
+
LIME = Color.from_u8(0, 158, 47, 255)
|
43
|
+
DARKGREEN = Color.from_u8(0, 117, 44, 255)
|
44
|
+
SKYBLUE = Color.from_u8(102, 191, 255, 255)
|
45
|
+
BLUE = Color.from_u8(0, 121, 241, 255)
|
46
|
+
DARKBLUE = Color.from_u8(0, 82, 172, 255)
|
47
|
+
PURPLE = Color.from_u8(200, 122, 255, 255)
|
48
|
+
VIOLET = Color.from_u8(135, 60, 190, 255)
|
49
|
+
DARKPURPLE = Color.from_u8(112, 31, 126, 255)
|
50
|
+
BEIGE = Color.from_u8(211, 176, 131, 255)
|
51
|
+
BROWN = Color.from_u8(127, 106, 79, 255)
|
52
|
+
DARKBROWN = Color.from_u8(76, 63, 47, 255)
|
53
|
+
|
54
|
+
WHITE = Color.from_u8(255, 255, 255, 255)
|
55
|
+
BLACK = Color.from_u8(0, 0, 0, 255)
|
56
|
+
BLANK = Color.from_u8(0, 0, 0, 0)
|
57
|
+
MAGENTA = Color.from_u8(255, 0, 255, 255)
|
58
|
+
RAYWHITE = Color.from_u8(245, 245, 245, 255)
|
59
|
+
|
60
|
+
#
|
61
|
+
# Math helper
|
62
|
+
#
|
63
|
+
|
64
|
+
class Vector2
|
65
|
+
def self.create(x = 0, y = 0)
|
66
|
+
Vector2.new.set(x, y)
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.copy_from(vec)
|
70
|
+
Vector2.create(vec[:x], vec[:y])
|
71
|
+
end
|
72
|
+
|
73
|
+
def set(x, y)
|
74
|
+
self[:x] = x
|
75
|
+
self[:y] = y
|
76
|
+
self
|
77
|
+
end
|
78
|
+
|
79
|
+
def add(x, y)
|
80
|
+
self[:x] = self[:x] + x
|
81
|
+
self[:y] = self[:y] + y
|
82
|
+
self
|
83
|
+
end
|
84
|
+
|
85
|
+
def add_vector(v)
|
86
|
+
self[:x] = self[:x] + v[:x]
|
87
|
+
self[:y] = self[:y] + v[:y]
|
88
|
+
self
|
89
|
+
end
|
90
|
+
|
91
|
+
def to_a
|
92
|
+
[x, y]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class Vector3
|
97
|
+
def self.create(x = 0, y = 0, z = 0)
|
98
|
+
Vector3.new.set(x, y, z)
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.copy_from(vec)
|
102
|
+
Vector3.create(vec[:x], vec[:y], vec[:z])
|
103
|
+
end
|
104
|
+
|
105
|
+
def set(x, y, z)
|
106
|
+
self[:x] = x
|
107
|
+
self[:y] = y
|
108
|
+
self[:z] = z
|
109
|
+
self
|
110
|
+
end
|
111
|
+
|
112
|
+
def to_a
|
113
|
+
[x, y, z]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
class Vector4
|
118
|
+
def self.create(x = 0, y = 0, z = 0, w = 0)
|
119
|
+
Vector4.new.set(x, y, z, w)
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.copy_from(vec)
|
123
|
+
Vector4.create(vec[:x], vec[:y], vec[:z], vec[:w])
|
124
|
+
end
|
125
|
+
|
126
|
+
def set(x, y, z, w)
|
127
|
+
self[:x] = x
|
128
|
+
self[:y] = y
|
129
|
+
self[:z] = z
|
130
|
+
self[:w] = w
|
131
|
+
self
|
132
|
+
end
|
133
|
+
|
134
|
+
def to_a
|
135
|
+
[x, y, z, w]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
class Quaternion
|
140
|
+
def self.create(x = 0, y = 0, z = 0, w = 0)
|
141
|
+
Quaternion.new.set(x, y, z, w)
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.copy_from(quat)
|
145
|
+
Quaternion.create(quat[:x], quat[:y], quat[:z], quat[:w])
|
146
|
+
end
|
147
|
+
|
148
|
+
def set(x, y, z, w)
|
149
|
+
self[:x] = x
|
150
|
+
self[:y] = y
|
151
|
+
self[:z] = z
|
152
|
+
self[:w] = w
|
153
|
+
self
|
154
|
+
end
|
155
|
+
|
156
|
+
def to_a
|
157
|
+
[x, y, z, w]
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
class Rectangle
|
162
|
+
def self.create(x = 0, y = 0, width = 0, height = 0)
|
163
|
+
Rectangle.new.set(x, y, width, height)
|
164
|
+
end
|
165
|
+
|
166
|
+
def set(x, y, width, height)
|
167
|
+
self[:x] = x
|
168
|
+
self[:y] = y
|
169
|
+
self[:width] = width
|
170
|
+
self[:height] = height
|
171
|
+
self
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
class BoundingBox
|
176
|
+
def self.create(*args)
|
177
|
+
case args.size
|
178
|
+
when 2
|
179
|
+
instance = BoundingBox.new
|
180
|
+
instance[:min] = args[0] # min
|
181
|
+
instance[:max] = args[1] # max
|
182
|
+
instance
|
183
|
+
when 6
|
184
|
+
instance = BoundingBox.new
|
185
|
+
instance[:min] = Vector3.create(args[0], args[1], args[2]) # min_x, min_y, min_z
|
186
|
+
instance[:max] = Vector3.create(args[3], args[4], args[5]) # max_x, max_y, max_z
|
187
|
+
instance
|
188
|
+
else
|
189
|
+
raise ArgumentError.new 'BoundingBox.create : Number of arguments must be 2 or 6'
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def with_min(x, y, z)
|
194
|
+
self[:min].set(x, y, z)
|
195
|
+
self
|
196
|
+
end
|
197
|
+
|
198
|
+
def with_max(x, y, z)
|
199
|
+
self[:max].set(x, y, z)
|
200
|
+
self
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def Vector3ToFloat(vec)
|
205
|
+
Vector3ToFloatV(vec)[:v].to_a
|
206
|
+
end
|
207
|
+
|
208
|
+
def MatrixToFloat(mat)
|
209
|
+
MatrixToFloatV(mat)[:v].to_a
|
210
|
+
end
|
211
|
+
|
212
|
+
#
|
213
|
+
# Camera helper
|
214
|
+
#
|
215
|
+
|
216
|
+
class Camera3D
|
217
|
+
def with_position(x, y, z)
|
218
|
+
self[:position].set(x, y, z)
|
219
|
+
self
|
220
|
+
end
|
221
|
+
|
222
|
+
def with_target(x, y, z)
|
223
|
+
self[:target].set(x, y, z)
|
224
|
+
self
|
225
|
+
end
|
226
|
+
|
227
|
+
def with_up(x, y, z)
|
228
|
+
self[:up].set(x, y, z)
|
229
|
+
self
|
230
|
+
end
|
231
|
+
|
232
|
+
def with_fovy(fovy)
|
233
|
+
self[:fovy] = fovy
|
234
|
+
self
|
235
|
+
end
|
236
|
+
|
237
|
+
def with_projection(projection)
|
238
|
+
self[:projection] = projection
|
239
|
+
self
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
class Camera2D
|
244
|
+
def with_offset(x, y)
|
245
|
+
self[:offset].set(x, y)
|
246
|
+
self
|
247
|
+
end
|
248
|
+
|
249
|
+
def with_target(x, y)
|
250
|
+
self[:target].set(x, y)
|
251
|
+
self
|
252
|
+
end
|
253
|
+
|
254
|
+
def with_rotation(rotation)
|
255
|
+
self[:rotation] = rotation
|
256
|
+
self
|
257
|
+
end
|
258
|
+
|
259
|
+
def with_zoom(zoom)
|
260
|
+
self[:zoom] = zoom
|
261
|
+
self
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
#
|
266
|
+
# Transform helper
|
267
|
+
#
|
268
|
+
|
269
|
+
class Transform
|
270
|
+
def t = self[:translation]
|
271
|
+
def r = self[:rotation]
|
272
|
+
def s = self[:scale]
|
273
|
+
end
|
274
|
+
|
275
|
+
#
|
276
|
+
# Model helper
|
277
|
+
#
|
278
|
+
|
279
|
+
# DrawModelEx : Draw a model with extended parameters
|
280
|
+
# @param model [Model]
|
281
|
+
# @param position [Vector3]
|
282
|
+
# @param rotationAxis [Vector3]
|
283
|
+
# @param rotationAngle [float]
|
284
|
+
# @param scale [Vector3]
|
285
|
+
# @param tint [Color]
|
286
|
+
# @return [void]
|
287
|
+
def DrawModelEx(model, position, rotationAxis, rotationAngle, scale, tint)
|
288
|
+
# [NOTE] Fixing unintended matrix modification
|
289
|
+
# - In C, DrawModelEx uses the whole copy of `model` on stack, which will never affect the content of original `model`.
|
290
|
+
# But Ruby FFI seems to pass the reference of `model` to DrawModelEx, which results in transform accumulation (e.g.:`model` get rotated by `rotationAngle` around `rotationAxis` every frame).
|
291
|
+
# So here I copy the transform into `mtx_clone` and copy back this to the original after finished calling DrawModelEx.
|
292
|
+
# - Other DrawXXX members (DrawModel, DrawModelWires, DrawModelWiresEx) are free from this problem.
|
293
|
+
# - They call DrawModelEx in C layer, which will use the copy of `model` on stack.
|
294
|
+
mtx_clone = model[:transform].clone
|
295
|
+
internalDrawModelEx(model, position, rotationAxis, rotationAngle, scale, tint)
|
296
|
+
model[:transform] = mtx_clone
|
297
|
+
end
|
298
|
+
|
299
|
+
class Model
|
300
|
+
# GetModelMaterial (ruby raylib original)
|
301
|
+
# @param index [int] 0 ~ materialCount
|
302
|
+
# @return [Material]
|
303
|
+
def material(index = 0)
|
304
|
+
Material.new(self[:materials] + index * Material.size)
|
305
|
+
end
|
306
|
+
|
307
|
+
# GetModelMaterialCount (ruby raylib original)
|
308
|
+
# @return [int]
|
309
|
+
def material_count
|
310
|
+
self[:materialCount]
|
311
|
+
end
|
312
|
+
|
313
|
+
# GetModelBoneCount (ruby raylib original)
|
314
|
+
# @return [int]
|
315
|
+
def bone_count
|
316
|
+
self[:boneCount]
|
317
|
+
end
|
318
|
+
|
319
|
+
# @return BoneInfo
|
320
|
+
def bone_info(index)
|
321
|
+
BoneInfo.new(self[:bones] + index * BoneInfo.size)
|
322
|
+
end
|
323
|
+
|
324
|
+
# @return Transform
|
325
|
+
def bind_pose_transform(index)
|
326
|
+
Transform.new(self[:bindPose] + index * Transform.size)
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
class BoneInfo
|
331
|
+
def parent_bone_index
|
332
|
+
self[:parent]
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
#
|
337
|
+
# ModelAnimation helper
|
338
|
+
#
|
339
|
+
|
340
|
+
# Manages a set of ModelAnimation (ruby raylib original)
|
341
|
+
class ModelAnimations
|
342
|
+
attr_reader :anims, :anim_ptrs
|
343
|
+
|
344
|
+
def initialize
|
345
|
+
@anims = nil
|
346
|
+
@anim_ptrs = nil
|
347
|
+
@framePoses = nil # array of Transform**
|
348
|
+
end
|
349
|
+
|
350
|
+
def anim(index) = @anims[index]
|
351
|
+
def anims_count = @anims.length
|
352
|
+
def frame_count(index) = @anims[index][:frameCount]
|
353
|
+
|
354
|
+
# @return BoneInfo
|
355
|
+
def bone_info(anim_index, bone_index)
|
356
|
+
BoneInfo.new(@anims[anim_index][:bones] + bone_index * BoneInfo.size)
|
357
|
+
end
|
358
|
+
|
359
|
+
# @return Transform*
|
360
|
+
def frame_pose(index, frame)
|
361
|
+
@framePoses[index] + frame * FFI::NativeType::POINTER.size # Transform*
|
362
|
+
end
|
363
|
+
|
364
|
+
# @return Transform
|
365
|
+
def bone_transform(frame_pose, bone_index)
|
366
|
+
Transform.new(frame_pose.read_pointer + bone_index * Transform.size)
|
367
|
+
end
|
368
|
+
|
369
|
+
# @return Transform
|
370
|
+
def bone_transform_of_frame_pose(anim_index, frame, bone_index)
|
371
|
+
bone_transform(frame_pose(anim_index, frame), bone_index)
|
372
|
+
end
|
373
|
+
|
374
|
+
# @return self
|
375
|
+
def setup(fileName)
|
376
|
+
@anims, @anim_ptrs = LoadAndAllocateModelAnimations(fileName)
|
377
|
+
@framePoses = []
|
378
|
+
@anims.each do |anim|
|
379
|
+
@framePoses << anim[:framePoses]
|
380
|
+
end
|
381
|
+
self
|
382
|
+
end
|
383
|
+
|
384
|
+
def cleanup
|
385
|
+
UnloadAndFreeModelAnimations(@anims, @anim_ptrs)
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
# LoadAndAllocateModelAnimations : (ruby raylib original)
|
390
|
+
# @param fileName [const char *]
|
391
|
+
# @return array of ModelAnimation and pointer to loaded memory
|
392
|
+
def LoadAndAllocateModelAnimations(fileName)
|
393
|
+
animsCount_buf = FFI::MemoryPointer.new(:uint, 1)
|
394
|
+
anim_ptrs = LoadModelAnimations(fileName, animsCount_buf)
|
395
|
+
animsCount = animsCount_buf.read_uint
|
396
|
+
anims = animsCount.times.map do |i|
|
397
|
+
ModelAnimation.new(anim_ptrs + i * ModelAnimation.size)
|
398
|
+
end
|
399
|
+
return anims, anim_ptrs
|
400
|
+
end
|
401
|
+
|
402
|
+
# UnloadAndFreeModelAnimations : (ruby raylib original)
|
403
|
+
# @param anims [array of ModelAnimation]
|
404
|
+
# @param anim_ptrs [pointer to loaded memory]
|
405
|
+
def UnloadAndFreeModelAnimations(anims, anim_ptrs)
|
406
|
+
anims.each do |anim|
|
407
|
+
UnloadModelAnimation(anim)
|
408
|
+
end
|
409
|
+
MemFree(anim_ptrs)
|
410
|
+
end
|
411
|
+
|
412
|
+
end
|