raylib-bindings 0.5.8pre1-x64-mingw → 0.6.1-x64-mingw

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.
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 to_a
80
- [x, y]
81
- end
82
- end
83
-
84
- class Vector3
85
- def self.create(x = 0, y = 0, z = 0)
86
- Vector3.new.set(x, y, z)
87
- end
88
-
89
- def self.copy_from(vec)
90
- Vector3.create(vec[:x], vec[:y], vec[:z])
91
- end
92
-
93
- def set(x, y, z)
94
- self[:x] = x
95
- self[:y] = y
96
- self[:z] = z
97
- self
98
- end
99
-
100
- def to_a
101
- [x, y, z]
102
- end
103
- end
104
-
105
- class Vector4
106
- def self.create(x = 0, y = 0, z = 0, w = 0)
107
- Vector4.new.set(x, y, z, w)
108
- end
109
-
110
- def self.copy_from(vec)
111
- Vector4.create(vec[:x], vec[:y], vec[:z], vec[:w])
112
- end
113
-
114
- def set(x, y, z, w)
115
- self[:x] = x
116
- self[:y] = y
117
- self[:z] = z
118
- self[:w] = w
119
- self
120
- end
121
-
122
- def to_a
123
- [x, y, z, w]
124
- end
125
- end
126
-
127
- class Quaternion
128
- def self.create(x = 0, y = 0, z = 0, w = 0)
129
- Quaternion.new.set(x, y, z, w)
130
- end
131
-
132
- def self.copy_from(quat)
133
- Quaternion.create(quat[:x], quat[:y], quat[:z], quat[:w])
134
- end
135
-
136
- def set(x, y, z, w)
137
- self[:x] = x
138
- self[:y] = y
139
- self[:z] = z
140
- self[:w] = w
141
- self
142
- end
143
-
144
- def to_a
145
- [x, y, z, w]
146
- end
147
- end
148
-
149
- class Rectangle
150
- def self.create(x = 0, y = 0, width = 0, height = 0)
151
- Rectangle.new.set(x, y, width, height)
152
- end
153
-
154
- def set(x, y, width, height)
155
- self[:x] = x
156
- self[:y] = y
157
- self[:width] = width
158
- self[:height] = height
159
- self
160
- end
161
- end
162
-
163
- class BoundingBox
164
- def self.create(*args)
165
- case args.size
166
- when 2
167
- instance = BoundingBox.new
168
- instance[:min] = args[0] # min
169
- instance[:max] = args[1] # max
170
- instance
171
- when 6
172
- instance = BoundingBox.new
173
- instance[:min] = Vector3.create(args[0], args[1], args[2]) # min_x, min_y, min_z
174
- instance[:max] = Vector3.create(args[3], args[4], args[5]) # max_x, max_y, max_z
175
- instance
176
- else
177
- raise ArgumentError.new 'BoundingBox.create : Number of arguments must be 2 or 6'
178
- end
179
- end
180
-
181
- def with_min(x, y, z)
182
- self[:min].set(x, y, z)
183
- self
184
- end
185
-
186
- def with_max(x, y, z)
187
- self[:max].set(x, y, z)
188
- self
189
- end
190
- end
191
-
192
- def Vector3ToFloat(vec)
193
- Vector3ToFloatV(vec)[:v].to_a
194
- end
195
-
196
- def MatrixToFloat(mat)
197
- MatrixToFloatV(mat)[:v].to_a
198
- end
199
-
200
- #
201
- # Camera helper
202
- #
203
-
204
- class Camera3D
205
- def with_position(x, y, z)
206
- self[:position].set(x, y, z)
207
- self
208
- end
209
-
210
- def with_target(x, y, z)
211
- self[:target].set(x, y, z)
212
- self
213
- end
214
-
215
- def with_up(x, y, z)
216
- self[:up].set(x, y, z)
217
- self
218
- end
219
-
220
- def with_fovy(fovy)
221
- self[:fovy] = fovy
222
- self
223
- end
224
-
225
- def with_projection(projection)
226
- self[:projection] = projection
227
- self
228
- end
229
- end
230
-
231
- class Camera2D
232
- def with_offset(x, y)
233
- self[:offset].set(x, y)
234
- self
235
- end
236
-
237
- def with_target(x, y)
238
- self[:target].set(x, y)
239
- self
240
- end
241
-
242
- def with_rotation(rotation)
243
- self[:rotation] = rotation
244
- self
245
- end
246
-
247
- def with_zoom(zoom)
248
- self[:zoom] = zoom
249
- self
250
- end
251
- end
252
-
253
- #
254
- # Transform helper
255
- #
256
-
257
- class Transform
258
- def t = self[:translation]
259
- def r = self[:rotation]
260
- def s = self[:scale]
261
- end
262
-
263
- #
264
- # Model helper
265
- #
266
-
267
- # DrawModelEx : Draw a model with extended parameters
268
- # @param model [Model]
269
- # @param position [Vector3]
270
- # @param rotationAxis [Vector3]
271
- # @param rotationAngle [float]
272
- # @param scale [Vector3]
273
- # @param tint [Color]
274
- # @return [void]
275
- def DrawModelEx(model, position, rotationAxis, rotationAngle, scale, tint)
276
- # [NOTE] Fixing unintended matrix modification
277
- # - In C, DrawModelEx uses the whole copy of `model` on stack, which will never affect the content of original `model`.
278
- # 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).
279
- # So here I copy the transform into `mtx_clone` and copy back this to the original after finished calling DrawModelEx.
280
- # - Other DrawXXX members (DrawModel, DrawModelWires, DrawModelWiresEx) are free from this problem.
281
- # - They call DrawModelEx in C layer, which will use the copy of `model` on stack.
282
- mtx_clone = model[:transform].clone
283
- internalDrawModelEx(model, position, rotationAxis, rotationAngle, scale, tint)
284
- model[:transform] = mtx_clone
285
- end
286
-
287
- class Model
288
- # GetModelMaterial (ruby raylib original)
289
- # @param index [int] 0 ~ materialCount
290
- # @return [Material]
291
- def material(index = 0)
292
- Material.new(self[:materials] + index * Material.size)
293
- end
294
-
295
- # GetModelMaterialCount (ruby raylib original)
296
- # @return [int]
297
- def material_count
298
- self[:materialCount]
299
- end
300
-
301
- # GetModelBoneCount (ruby raylib original)
302
- # @return [int]
303
- def bone_count
304
- self[:boneCount]
305
- end
306
-
307
- # @return BoneInfo
308
- def bone_info(index)
309
- BoneInfo.new(self[:bones] + index * BoneInfo.size)
310
- end
311
-
312
- # @return Transform
313
- def bind_pose_transform(index)
314
- Transform.new(self[:bindPose] + index * Transform.size)
315
- end
316
- end
317
-
318
- class BoneInfo
319
- def parent_bone_index
320
- self[:parent]
321
- end
322
- end
323
-
324
- #
325
- # ModelAnimation helper
326
- #
327
-
328
- # Manages a set of ModelAnimation (ruby raylib original)
329
- class ModelAnimations
330
- attr_reader :anims, :anim_ptrs
331
-
332
- def initialize
333
- @anims = nil
334
- @anim_ptrs = nil
335
- @framePoses = nil # array of Transform**
336
- end
337
-
338
- def anim(index) = @anims[index]
339
- def anims_count = @anims.length
340
- def frame_count(index) = @anims[index][:frameCount]
341
-
342
- # @return BoneInfo
343
- def bone_info(anim_index, bone_index)
344
- BoneInfo.new(@anims[anim_index][:bones] + bone_index * BoneInfo.size)
345
- end
346
-
347
- # @return Transform*
348
- def frame_pose(index, frame)
349
- @framePoses[index] + frame * FFI::NativeType::POINTER.size # Transform*
350
- end
351
-
352
- # @return Transform
353
- def bone_transform(frame_pose, bone_index)
354
- Transform.new(frame_pose.read_pointer + bone_index * Transform.size)
355
- end
356
-
357
- # @return Transform
358
- def bone_transform_of_frame_pose(anim_index, frame, bone_index)
359
- bone_transform(frame_pose(anim_index, frame), bone_index)
360
- end
361
-
362
- # @return self
363
- def setup(fileName)
364
- @anims, @anim_ptrs = LoadAndAllocateModelAnimations(fileName)
365
- @framePoses = []
366
- @anims.each do |anim|
367
- @framePoses << anim[:framePoses]
368
- end
369
- self
370
- end
371
-
372
- def cleanup
373
- UnloadAndFreeModelAnimations(@anims, @anim_ptrs)
374
- end
375
- end
376
-
377
- # LoadAndAllocateModelAnimations : (ruby raylib original)
378
- # @param fileName [const char *]
379
- # @return array of ModelAnimation and pointer to loaded memory
380
- def LoadAndAllocateModelAnimations(fileName)
381
- animsCount_buf = FFI::MemoryPointer.new(:uint, 1)
382
- anim_ptrs = LoadModelAnimations(fileName, animsCount_buf)
383
- animsCount = animsCount_buf.read_uint
384
- anims = animsCount.times.map do |i|
385
- ModelAnimation.new(anim_ptrs + i * ModelAnimation.size)
386
- end
387
- return anims, anim_ptrs
388
- end
389
-
390
- # UnloadAndFreeModelAnimations : (ruby raylib original)
391
- # @param anims [array of ModelAnimation]
392
- # @param anim_ptrs [pointer to loaded memory]
393
- def UnloadAndFreeModelAnimations(anims, anim_ptrs)
394
- anims.each do |anim|
395
- UnloadModelAnimation(anim)
396
- end
397
- MemFree(anim_ptrs)
398
- end
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