rgss 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.clang-format +6 -0
  3. data/.gitignore +167 -0
  4. data/.yardopts +6 -0
  5. data/CHANGELOG.md +4 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/Rakefile +9 -0
  9. data/ext/rgss/cglm-v0.7.9.tar.gz +0 -0
  10. data/ext/rgss/color.c +599 -0
  11. data/ext/rgss/entity.c +373 -0
  12. data/ext/rgss/extconf.rb +53 -0
  13. data/ext/rgss/font.c +135 -0
  14. data/ext/rgss/game.c +469 -0
  15. data/ext/rgss/game.h +99 -0
  16. data/ext/rgss/gl.c +3217 -0
  17. data/ext/rgss/glad.c +1140 -0
  18. data/ext/rgss/glad.h +2129 -0
  19. data/ext/rgss/glfw.c +1453 -0
  20. data/ext/rgss/graphics.c +324 -0
  21. data/ext/rgss/image.c +274 -0
  22. data/ext/rgss/input.c +745 -0
  23. data/ext/rgss/khrplatform.h +290 -0
  24. data/ext/rgss/mat4.c +279 -0
  25. data/ext/rgss/pax_global_header +1 -0
  26. data/ext/rgss/point.c +253 -0
  27. data/ext/rgss/rect.c +449 -0
  28. data/ext/rgss/rgss.c +56 -0
  29. data/ext/rgss/rgss.h +241 -0
  30. data/ext/rgss/stb_image.h +7762 -0
  31. data/ext/rgss/stb_image_write.h +1690 -0
  32. data/ext/rgss/stb_rect_pack.h +628 -0
  33. data/ext/rgss/stb_truetype.h +5011 -0
  34. data/ext/rgss/utf8.h +1652 -0
  35. data/ext/rgss/uthash.h +1133 -0
  36. data/ext/rgss/vec.c +114 -0
  37. data/ext/rgss/vec.h +192 -0
  38. data/ext/rgss/vec2.c +489 -0
  39. data/ext/rgss/vec3.c +751 -0
  40. data/ext/rgss/vec4.c +681 -0
  41. data/lib/rgss.rb +140 -0
  42. data/lib/rgss/batch.rb +57 -0
  43. data/lib/rgss/blend.rb +47 -0
  44. data/lib/rgss/game_object.rb +28 -0
  45. data/lib/rgss/plane.rb +95 -0
  46. data/lib/rgss/renderable.rb +158 -0
  47. data/lib/rgss/rgss.so +0 -0
  48. data/lib/rgss/shader.rb +94 -0
  49. data/lib/rgss/shaders/sprite-frag.glsl +40 -0
  50. data/lib/rgss/shaders/sprite-vert.glsl +17 -0
  51. data/lib/rgss/sprite.rb +139 -0
  52. data/lib/rgss/stubs/color.rb +318 -0
  53. data/lib/rgss/stubs/gl.rb +1999 -0
  54. data/lib/rgss/stubs/glfw.rb +626 -0
  55. data/lib/rgss/stubs/rect.rb +324 -0
  56. data/lib/rgss/stubs/rpg.rb +267 -0
  57. data/lib/rgss/stubs/tone.rb +65 -0
  58. data/lib/rgss/texture.rb +132 -0
  59. data/lib/rgss/tilemap.rb +116 -0
  60. data/lib/rgss/version.rb +3 -0
  61. data/lib/rgss/viewport.rb +67 -0
  62. data/rgss.gemspec +44 -0
  63. data/test.png +0 -0
  64. metadata +178 -0
@@ -0,0 +1,751 @@
1
+ #include "game.h"
2
+
3
+ VALUE rb_cVec3;
4
+
5
+ CREATE_ALLOC_FUNC(vec3, RGSS_VEC3_ALIGN, RGSS_VEC3_SIZE)
6
+ VEC_ATTR_ACCESSOR(vec3, x, 0)
7
+ VEC_ATTR_ACCESSOR(vec3, y, 1)
8
+ VEC_ATTR_ACCESSOR(vec3, z, 2)
9
+
10
+ static VALUE vec3_get(VALUE self, VALUE index)
11
+ {
12
+ int i = NUM2INT(index);
13
+ if (index < 0 || index > 2)
14
+ rb_raise(rb_eArgError, "index of of range (must be 0..2)");
15
+ return DBL2NUM(((float*) DATA_PTR(self))[i]);
16
+ }
17
+
18
+ static VALUE vec3_set(VALUE self, VALUE index, VALUE value)
19
+ {
20
+ int i = NUM2INT(index);
21
+ if (index < 0 || index > 2)
22
+ rb_raise(rb_eArgError, "index of of range (must be 0..2)");
23
+ ((float*) DATA_PTR(self))[i] = NUM2FLT(value);
24
+ return value;
25
+ }
26
+
27
+ static VALUE vec3_copy(VALUE self)
28
+ {
29
+ float *d = RGSS_VEC3_NEW;
30
+ glm_vec3_copy(DATA_PTR(self), d);
31
+ return VEC3_WRAP(d);
32
+ }
33
+
34
+ static VALUE vec3_zero(VALUE klass)
35
+ {
36
+ float *d = RGSS_VEC3_NEW;
37
+ glm_vec3_zero(d);
38
+ return VEC3_WRAP(d);
39
+ }
40
+
41
+ static VALUE vec3_one(VALUE klass)
42
+ {
43
+ float *d = RGSS_VEC3_NEW;
44
+ glm_vec3_one(d);
45
+ return VEC3_WRAP(d);
46
+ }
47
+
48
+ static VALUE vec3_dot(VALUE self, VALUE other)
49
+ {
50
+ return DBL2NUM(glm_vec3_dot(DATA_PTR(self), DATA_PTR(other)));
51
+ }
52
+
53
+ static VALUE vec3_length(VALUE self)
54
+ {
55
+ return DBL2NUM(glm_vec3_norm(DATA_PTR(self)));
56
+ }
57
+
58
+ static VALUE vec3_length_squared(VALUE self)
59
+ {
60
+ return DBL2NUM(glm_vec3_norm2(DATA_PTR(self)));
61
+ }
62
+
63
+ static VALUE vec3_manhattan_distance(VALUE self)
64
+ {
65
+ return DBL2NUM(glm_vec3_norm_one(DATA_PTR(self)));
66
+ }
67
+
68
+ static VALUE vec3_norm_inf(VALUE self)
69
+ {
70
+ return DBL2NUM(glm_vec3_norm_inf(DATA_PTR(self)));
71
+ }
72
+
73
+ static VALUE vec3_add(VALUE self, VALUE other)
74
+ {
75
+ float *d = RGSS_VEC3_NEW;
76
+ float *v = DATA_PTR(self);
77
+
78
+ if (RB_TYPE_P(other, T_DATA))
79
+ {
80
+ glm_vec3_add(v, DATA_PTR(other), d);
81
+ }
82
+ else
83
+ {
84
+ glm_vec3_adds(v, NUM2FLT(other), d);
85
+ }
86
+ return VEC3_WRAP(d);
87
+ }
88
+
89
+ static VALUE vec3_sub(VALUE self, VALUE other)
90
+ {
91
+ float *d = RGSS_VEC3_NEW;
92
+ float *v = DATA_PTR(self);
93
+
94
+ if (RB_TYPE_P(other, T_DATA))
95
+ {
96
+ glm_vec3_sub(v, DATA_PTR(other), d);
97
+ }
98
+ else
99
+ {
100
+ glm_vec3_subs(v, NUM2FLT(other), d);
101
+ }
102
+ return VEC3_WRAP(d);
103
+ }
104
+
105
+ static VALUE vec3_mul(VALUE self, VALUE other)
106
+ {
107
+ float *d = RGSS_VEC3_NEW;
108
+ float *v = DATA_PTR(self);
109
+
110
+ if (RB_TYPE_P(other, T_DATA))
111
+ {
112
+ glm_vec3_mul(v, DATA_PTR(other), d);
113
+ }
114
+ else
115
+ {
116
+ glm_vec3_scale(v, NUM2FLT(other), d);
117
+ }
118
+ return VEC3_WRAP(d);
119
+ }
120
+
121
+ static VALUE vec3_div(VALUE self, VALUE other)
122
+ {
123
+ float *d = RGSS_VEC3_NEW;
124
+ float *v = DATA_PTR(self);
125
+
126
+ if (RB_TYPE_P(other, T_DATA))
127
+ {
128
+ glm_vec3_div(v, DATA_PTR(other), d);
129
+ }
130
+ else
131
+ {
132
+ glm_vec3_divs(v, NUM2FLT(other), d);
133
+ }
134
+ return VEC3_WRAP(d);
135
+ }
136
+
137
+ static VALUE vec3_norm_scale(VALUE self, VALUE value)
138
+ {
139
+ float *d = RGSS_VEC3_NEW;
140
+ glm_vec3_scale_as(DATA_PTR(self), NUM2FLT(value), d);
141
+ return VEC3_WRAP(d);
142
+ }
143
+
144
+ static VALUE vec3_add_add(VALUE self, VALUE other)
145
+ {
146
+ float *d = RGSS_VEC3_NEW;
147
+ glm_vec3_addadd(DATA_PTR(self), DATA_PTR(other), d);
148
+ return VEC3_WRAP(d);
149
+ }
150
+
151
+ static VALUE vec3_sub_add(VALUE self, VALUE other)
152
+ {
153
+ float *d = RGSS_VEC3_NEW;
154
+ glm_vec3_subadd(DATA_PTR(self), DATA_PTR(other), d);
155
+ return VEC3_WRAP(d);
156
+ }
157
+
158
+ static VALUE vec3_mul_add(VALUE self, VALUE other)
159
+ {
160
+ float *d = RGSS_VEC3_NEW;
161
+ float *v = DATA_PTR(self);
162
+
163
+ if (RB_TYPE_P(other, T_DATA))
164
+ {
165
+ glm_vec3_muladd(v, DATA_PTR(other), d);
166
+ }
167
+ else
168
+ {
169
+ glm_vec3_muladds(v, NUM2FLT(other), d);
170
+ }
171
+
172
+ return VEC3_WRAP(d);
173
+ }
174
+
175
+ static VALUE vec3_max_add(VALUE self, VALUE other)
176
+ {
177
+ float *d = RGSS_VEC3_NEW;
178
+ glm_vec3_maxadd(DATA_PTR(self), DATA_PTR(other), d);
179
+ return VEC3_WRAP(d);
180
+ }
181
+
182
+ static VALUE vec3_min_add(VALUE self, VALUE other)
183
+ {
184
+ float *d = RGSS_VEC3_NEW;
185
+ glm_vec3_minadd(DATA_PTR(self), DATA_PTR(other), d);
186
+ return VEC3_WRAP(d);
187
+ }
188
+
189
+ static VALUE vec3_negate(VALUE self)
190
+ {
191
+ float *d = RGSS_VEC3_NEW;
192
+ glm_vec3_negate_to(DATA_PTR(self), d);
193
+ return VEC3_WRAP(d);
194
+ }
195
+
196
+ static VALUE vec3_negate_bang(VALUE self)
197
+ {
198
+ glm_vec3_negate(DATA_PTR(self));
199
+ return self;
200
+ }
201
+
202
+ static VALUE vec3_normalize(VALUE self)
203
+ {
204
+ float *d = RGSS_VEC3_NEW;
205
+ glm_vec3_normalize_to(DATA_PTR(self), d);
206
+ return VEC3_WRAP(d);
207
+ }
208
+
209
+ static VALUE vec3_normalize_bang(VALUE self)
210
+ {
211
+ glm_vec3_normalize(DATA_PTR(self));
212
+ return self;
213
+ }
214
+
215
+ static VALUE vec3_cross(VALUE self, VALUE other)
216
+ {
217
+ float *d = RGSS_VEC3_NEW;
218
+ glm_vec3_cross(DATA_PTR(self), DATA_PTR(other), d);
219
+ return VEC3_WRAP(d);
220
+ }
221
+
222
+ static VALUE vec3_cross_norm(VALUE self, VALUE other)
223
+ {
224
+ float *d = RGSS_VEC3_NEW;
225
+ glm_vec3_crossn(DATA_PTR(self), DATA_PTR(other), d);
226
+ return VEC3_WRAP(d);
227
+ }
228
+
229
+ static VALUE vec3_angle(VALUE self, VALUE other)
230
+ {
231
+ return DBL2NUM(glm_vec3_angle(DATA_PTR(self), DATA_PTR(other)));
232
+ }
233
+
234
+ static VALUE vec3_rotate_bang(int argc, VALUE *argv, VALUE self)
235
+ {
236
+ VALUE a1, a2;
237
+ rb_scan_args(argc, argv, "11", &a1, &a2);
238
+
239
+ vec3 d;
240
+ float *v = DATA_PTR(self);
241
+
242
+ switch (argc)
243
+ {
244
+ case 2:
245
+ {
246
+ glm_vec3_rotate(v, NUM2FLT(a1), DATA_PTR(a2));
247
+ break;
248
+ }
249
+ case 1:
250
+ {
251
+ VALUE klass = CLASS_OF(a1);
252
+ if (klass == rb_cMat4)
253
+ {
254
+ glm_vec3_rotate_m4(DATA_PTR(a1), v, d);
255
+ }
256
+ else if (klass == rb_cMat3)
257
+ {
258
+ glm_vec3_rotate_m3(DATA_PTR(a1), v, d);
259
+ }
260
+ else
261
+ {
262
+ rb_raise(rb_eTypeError, "expected Mat3 or Mat4, recieved %s", CLASS_NAME(a1));
263
+ }
264
+ glm_vec3_copy(d, v);
265
+ }
266
+ }
267
+
268
+ return self;
269
+ }
270
+
271
+ static VALUE vec3_rotate(int argc, VALUE *argv, VALUE self)
272
+ {
273
+ VALUE a1, a2;
274
+ rb_scan_args(argc, argv, "11", &a1, &a2);
275
+
276
+ float *d = RGSS_VEC3_NEW;
277
+ float *v = DATA_PTR(self);
278
+
279
+ switch (argc)
280
+ {
281
+ case 2:
282
+ {
283
+ glm_vec3_copy(v, d);
284
+ glm_vec3_rotate(d, NUM2FLT(a1), DATA_PTR(a2));
285
+ break;
286
+ }
287
+ case 1:
288
+ {
289
+ VALUE klass = CLASS_OF(a1);
290
+ if (klass == rb_cMat4)
291
+ {
292
+ glm_vec3_rotate_m4(DATA_PTR(a1), v, d);
293
+ }
294
+ else if (klass == rb_cMat3)
295
+ {
296
+ glm_vec3_rotate_m3(DATA_PTR(a1), v, d);
297
+ }
298
+ else
299
+ {
300
+ rb_raise(rb_eTypeError, "expected Mat3 or Mat4, recieved %s", CLASS_NAME(a1));
301
+ }
302
+ }
303
+ }
304
+ return VEC3_WRAP(d);
305
+ }
306
+
307
+ static VALUE vec3_project(VALUE self, VALUE other)
308
+ {
309
+ float *d = RGSS_VEC3_NEW;
310
+ glm_vec3_proj(DATA_PTR(self), DATA_PTR(other), d);
311
+ return VEC3_WRAP(d);
312
+ }
313
+
314
+ static VALUE vec3_center(VALUE self, VALUE other)
315
+ {
316
+ float *d = RGSS_VEC3_NEW;
317
+ glm_vec3_center(DATA_PTR(self), DATA_PTR(other), d);
318
+ return VEC3_WRAP(d);
319
+ }
320
+
321
+ static VALUE vec3_distance(VALUE self, VALUE other)
322
+ {
323
+ return DBL2NUM(glm_vec3_distance(DATA_PTR(self), DATA_PTR(other)));
324
+ }
325
+
326
+ static VALUE vec3_distance_squared(VALUE self, VALUE other)
327
+ {
328
+ return DBL2NUM(glm_vec3_distance2(DATA_PTR(self), DATA_PTR(other)));
329
+ }
330
+
331
+ static VALUE vec3_maxv(VALUE self, VALUE other)
332
+ {
333
+ float *d = RGSS_VEC3_NEW;
334
+ glm_vec3_maxv(DATA_PTR(self), DATA_PTR(other), d);
335
+ return VEC3_WRAP(d);
336
+ }
337
+
338
+ static VALUE vec3_minv(VALUE self, VALUE other)
339
+ {
340
+ float *d = RGSS_VEC3_NEW;
341
+ glm_vec3_minv(DATA_PTR(self), DATA_PTR(other), d);
342
+ return VEC3_WRAP(d);
343
+ }
344
+
345
+ static VALUE vec3_ortho(VALUE self)
346
+ {
347
+ float *d = RGSS_VEC3_NEW;
348
+ glm_vec3_ortho(DATA_PTR(self), d);
349
+ return VEC3_WRAP(d);
350
+ }
351
+
352
+ static VALUE vec3_clamp_bang(VALUE self, VALUE min, VALUE max)
353
+ {
354
+ glm_vec3_clamp(DATA_PTR(self), NUM2FLT(min), NUM2FLT(max));
355
+ return self;
356
+ }
357
+
358
+ static VALUE vec3_clamp(VALUE self, VALUE min, VALUE max)
359
+ {
360
+ return vec3_clamp(vec3_copy(self), min, max);
361
+ }
362
+
363
+ static VALUE vec3_lerp_bang(int argc, VALUE *argv, VALUE self)
364
+ {
365
+ VALUE other, weight, clamped;
366
+ rb_scan_args(argc, argv, "21", &other, &weight, &clamped);
367
+
368
+ float *v = DATA_PTR(self);
369
+
370
+ if (RTEST(clamped))
371
+ {
372
+ glm_vec3_lerpc(v, DATA_PTR(other), NUM2FLT(weight), v);
373
+ }
374
+ else
375
+ {
376
+ glm_vec3_lerp(v, DATA_PTR(other), NUM2FLT(weight), v);
377
+ }
378
+ return self;
379
+ }
380
+
381
+ static VALUE vec3_lerp(int argc, VALUE *argv, VALUE self)
382
+ {
383
+ VALUE other, weight, clamped;
384
+ rb_scan_args(argc, argv, "21", &other, &weight, &clamped);
385
+
386
+ float *d = RGSS_VEC3_NEW;
387
+ float *v = DATA_PTR(self);
388
+
389
+ if (RTEST(clamped))
390
+ {
391
+ glm_vec3_lerpc(v, DATA_PTR(other), NUM2FLT(weight), d);
392
+ }
393
+ else
394
+ {
395
+ glm_vec3_lerp(v, DATA_PTR(other), NUM2FLT(weight), d);
396
+ }
397
+ return VEC3_WRAP(d);
398
+ }
399
+
400
+ static VALUE vec3_step(VALUE self, VALUE edge)
401
+ {
402
+ float *d = RGSS_VEC3_NEW;
403
+ float *v = DATA_PTR(self);
404
+
405
+ if (RB_TYPE_P(edge, T_DATA))
406
+ {
407
+ glm_vec3_step(DATA_PTR(edge), v, d);
408
+ }
409
+ else
410
+ {
411
+ glm_vec3_step_uni(NUM2FLT(edge), v, d);
412
+ }
413
+
414
+ return VEC3_WRAP(d);
415
+ }
416
+
417
+ static VALUE vec3_smoothstep(VALUE self, VALUE low, VALUE high)
418
+ {
419
+ float *v = DATA_PTR(self);
420
+ float *d = RGSS_VEC3_NEW;
421
+
422
+ if (RB_TYPE_P(low, T_DATA) && RB_TYPE_P(high, T_DATA))
423
+ {
424
+ glm_vec3_smoothstep(v, DATA_PTR(low), DATA_PTR(high), d);
425
+ }
426
+ else
427
+ {
428
+ glm_vec3_smoothstep_uni(NUM2FLT(low), NUM2FLT(high), v, d);
429
+ }
430
+
431
+ return VEC3_WRAP(d);
432
+ }
433
+
434
+ static VALUE vec3_smoothinterp(int argc, VALUE *argv, VALUE self)
435
+ {
436
+ VALUE other, weight, clamped;
437
+ rb_scan_args(argc, argv, "21", &other, &weight, &clamped);
438
+
439
+ float *from = DATA_PTR(self), *to = DATA_PTR(other);
440
+ float w = NUM2FLT(weight);
441
+ float *d = RGSS_VEC3_NEW;
442
+
443
+ if (RTEST(clamped))
444
+ {
445
+ glm_vec3_smoothinterpc(from, to, w, d);
446
+ }
447
+ else
448
+ {
449
+ glm_vec3_smoothinterp(from, to, w, d);
450
+ }
451
+ return VEC3_WRAP(d);
452
+ }
453
+
454
+ static VALUE vec3_swizzle(VALUE self, VALUE mask)
455
+ {
456
+ float *d = RGSS_VEC3_NEW;
457
+ glm_vec3_swizzle(DATA_PTR(self), NUM2INT(mask), d);
458
+ return VEC3_WRAP(d);
459
+ }
460
+
461
+ static VALUE vec3_swizzle_bang(VALUE self, VALUE mask)
462
+ {
463
+ vec3 temp;
464
+ glm_vec3_swizzle(DATA_PTR(self), NUM2INT(mask), temp);
465
+ glm_vec3_copy(temp, DATA_PTR(self));
466
+ return self;
467
+ }
468
+
469
+ static VALUE vec3_equal(int argc, VALUE *argv, VALUE self)
470
+ {
471
+ VALUE other, epsilon;
472
+ rb_scan_args(argc, argv, "11", &other, &epsilon);
473
+
474
+ if (CLASS_OF(self) != CLASS_OF(other))
475
+ return Qfalse;
476
+
477
+ float *v1 = DATA_PTR(self), *v2 = DATA_PTR(other);
478
+ bool result = RTEST(epsilon) ? glm_vec3_eqv_eps(v1, v2) : glm_vec3_eqv(v1, v2);
479
+
480
+ return RB_BOOL(result);
481
+ }
482
+
483
+ static VALUE vec3_max_value(VALUE self)
484
+ {
485
+ return DBL2NUM(glm_vec3_max(DATA_PTR(self)));
486
+ }
487
+
488
+ static VALUE vec3_min_value(VALUE self)
489
+ {
490
+ return DBL2NUM(glm_vec3_min(DATA_PTR(self)));
491
+ }
492
+
493
+ static VALUE vec3_infinite_p(VALUE self)
494
+ {
495
+ return RB_BOOL(glm_vec3_isinf(DATA_PTR(self)));
496
+ }
497
+
498
+ static VALUE vec3_nan_p(VALUE self)
499
+ {
500
+ return RB_BOOL(glm_vec3_isnan(DATA_PTR(self)));
501
+ }
502
+
503
+ static VALUE vec3_sqrt(VALUE self)
504
+ {
505
+ float *d = RGSS_VEC3_NEW;
506
+ glm_vec3_sqrt(DATA_PTR(self), d);
507
+ return VEC3_WRAP(d);
508
+ }
509
+
510
+ static VALUE vec3_abs(VALUE self)
511
+ {
512
+ float *d = RGSS_VEC3_NEW;
513
+ glm_vec3_abs(DATA_PTR(self), d);
514
+ return VEC3_WRAP(d);
515
+ }
516
+
517
+ static VALUE vec3_sum(VALUE self)
518
+ {
519
+ return DBL2NUM(glm_vec3_hadd(DATA_PTR(self)));
520
+ }
521
+
522
+ static VALUE vec3_sign(VALUE self)
523
+ {
524
+ float *d = RGSS_VEC3_NEW;
525
+ glm_vec3_sign(DATA_PTR(self), d);
526
+ return VEC3_WRAP(d);
527
+ }
528
+
529
+ static VALUE vec3_fract(VALUE self)
530
+ {
531
+ float *d = RGSS_VEC3_NEW;
532
+ glm_vec3_fract(DATA_PTR(self), d);
533
+ return VEC3_WRAP(d);
534
+ }
535
+
536
+ static VALUE vec3_all_p(int argc, VALUE *argv, VALUE self)
537
+ {
538
+ VALUE value, epsilon;
539
+ rb_scan_args(argc, argv, "11", &value, &epsilon);
540
+
541
+ float *v1 = DATA_PTR(self), v2 = NUM2FLT(value);
542
+ bool result = RTEST(epsilon) ? glm_vec3_eq_eps(v1, v2) : glm_vec3_eq(v1, v2);
543
+
544
+ return RB_BOOL(result);
545
+ }
546
+
547
+ static VALUE vec3_unitx(VALUE klass)
548
+ {
549
+ return RGSS_Vec3_New(1.0f, 0.0f, 0.0f);
550
+ }
551
+
552
+ static VALUE vec3_unity(VALUE klass)
553
+ {
554
+ return RGSS_Vec3_New(0.0f, 1.0f, 0.0f);
555
+ }
556
+
557
+ static VALUE vec3_unitz(VALUE klass)
558
+ {
559
+ return RGSS_Vec3_New(0.0f, 0.0f, 1.0f);
560
+ }
561
+
562
+ static VALUE vec3_inspect(VALUE self)
563
+ {
564
+ float *v = DATA_PTR(self);
565
+ return rb_sprintf("<%f, %f, %f>", v[0], v[1], v[2]);
566
+ }
567
+
568
+ static inline void vec3_create(int argc, VALUE *argv, vec3 v)
569
+ {
570
+ VALUE x, y, z;
571
+ rb_scan_args(argc, argv, "03", &x, &y, &z);
572
+
573
+ switch (argc)
574
+ {
575
+
576
+ case 0:
577
+ {
578
+ // vec3()
579
+ glm_vec3_zero(v);
580
+ break;
581
+ }
582
+
583
+ case 1:
584
+ {
585
+ if (CLASS_OF(x) == rb_cVec4)
586
+ {
587
+ // vec3(v4)
588
+ glm_vec3(DATA_PTR(x), v);
589
+ }
590
+ else if (CLASS_OF(x) == rb_cVec3)
591
+ {
592
+ // vec3(v3)
593
+ glm_vec3_copy(DATA_PTR(x), v);
594
+ }
595
+ else
596
+ {
597
+ // vec3(float)
598
+ glm_vec3_fill(v, NUM2FLT(x));
599
+ }
600
+ break;
601
+ }
602
+ case 2:
603
+ {
604
+ float *v2;
605
+ if (CLASS_OF(x) == rb_cVec2)
606
+ {
607
+ // vec3(v2, float)
608
+ v2 = DATA_PTR(x);
609
+ v[0] = v2[0];
610
+ v[1] = v2[1];
611
+ v[3] = NUM2FLT(y);
612
+ }
613
+ else
614
+ {
615
+ v2 = DATA_PTR(y);
616
+ v[0] = NUM2FLT(x);
617
+ v[1] = v2[0];
618
+ v[2] = v2[1];
619
+ }
620
+ break;
621
+ }
622
+ case 3:
623
+ {
624
+ // vec3(float, float, float)
625
+ v[0] = NUM2FLT(x);
626
+ v[1] = NUM2FLT(y);
627
+ v[2] = NUM2FLT(z);
628
+ break;
629
+ }
630
+ }
631
+ }
632
+
633
+ static VALUE vec3_initialize(int argc, VALUE *argv, VALUE self)
634
+ {
635
+ if (CLASS_OF(self) != rb_cVec3)
636
+ rb_warn("inheriting from %s may result in undefined behavior", rb_class2name(rb_cVec3));
637
+
638
+ vec3_create(argc, argv, DATA_PTR(self));
639
+ return Qnil;
640
+ }
641
+
642
+ static VALUE vec3_kernel_create(int argc, VALUE *argv, VALUE module)
643
+ {
644
+ float *v = RGSS_VEC3_NEW;
645
+ vec3_create(argc, argv, v);
646
+ return VEC3_WRAP(v);
647
+ }
648
+
649
+ void RGSS_Init_Vec3(VALUE parent)
650
+ {
651
+ rb_cVec3 = rb_define_class_under(parent, "Vec3", rb_cObject);
652
+ rb_define_alloc_func(rb_cVec3, vec3_alloc);
653
+ rb_define_methodm1(rb_cVec3, "initialize", vec3_initialize, -1);
654
+ rb_define_methodm1(rb_mKernel, "vec3", vec3_kernel_create, -1);
655
+
656
+ rb_define_const(rb_cVec3, "SIZE", SIZET2NUM(RGSS_VEC3_SIZE));
657
+ rb_define_const(rb_cVec3, "ALIGN", SIZET2NUM(RGSS_VEC3_ALIGN));
658
+ rb_define_const(rb_cVec3, "MASK_XXX", INT2NUM(GLM_XXX));
659
+ rb_define_const(rb_cVec3, "MASK_YYY", INT2NUM(GLM_YYY));
660
+ rb_define_const(rb_cVec3, "MASK_ZZZ", INT2NUM(GLM_ZZZ));
661
+ rb_define_const(rb_cVec3, "MASK_ZYX", INT2NUM(GLM_ZYX));
662
+
663
+ rb_define_method1(rb_cVec3, "[]", vec3_get, 1);
664
+ rb_define_method2(rb_cVec3, "[]=", vec3_set, 2);
665
+ rb_define_method0(rb_cVec3, "copy", vec3_copy, 0);
666
+ rb_define_method1(rb_cVec3, "dot", vec3_dot, 1);
667
+ rb_define_method0(rb_cVec3, "length", vec3_length, 0);
668
+ rb_define_method0(rb_cVec3, "length_squared", vec3_length_squared, 0);
669
+ rb_define_method0(rb_cVec3, "manhattan_distance", vec3_manhattan_distance, 0);
670
+ rb_define_method0(rb_cVec3, "norm_inf", vec3_norm_inf, 0);
671
+ rb_define_method1(rb_cVec3, "add", vec3_add, 1);
672
+ rb_define_method1(rb_cVec3, "subtract", vec3_sub, 1);
673
+ rb_define_method1(rb_cVec3, "multiply", vec3_mul, 1);
674
+ rb_define_method1(rb_cVec3, "norm_scale", vec3_norm_scale, 1);
675
+ rb_define_method1(rb_cVec3, "divide", vec3_div, 1);
676
+ rb_define_method1(rb_cVec3, "add_add", vec3_add_add, 1);
677
+ rb_define_method1(rb_cVec3, "sub_add", vec3_sub_add, 1);
678
+ rb_define_method1(rb_cVec3, "mul_add", vec3_mul_add, 1);
679
+ rb_define_method1(rb_cVec3, "max_add", vec3_max_add, 1);
680
+ rb_define_method1(rb_cVec3, "min_add", vec3_min_add, 1);
681
+ rb_define_method0(rb_cVec3, "negate", vec3_negate, 0);
682
+ rb_define_method0(rb_cVec3, "negate!", vec3_negate_bang, 0);
683
+ rb_define_method0(rb_cVec3, "normalize", vec3_normalize, 0);
684
+ rb_define_method0(rb_cVec3, "normalize!", vec3_normalize_bang, 0);
685
+ rb_define_method1(rb_cVec3, "cross", vec3_cross, 1);
686
+ rb_define_method1(rb_cVec3, "cross_norm", vec3_cross_norm, 1);
687
+ rb_define_method1(rb_cVec3, "angle", vec3_angle, 1);
688
+ rb_define_method1(rb_cVec3, "project", vec3_project, 1);
689
+ rb_define_method1(rb_cVec3, "center", vec3_center, 1);
690
+ rb_define_method1(rb_cVec3, "distance", vec3_distance, 1);
691
+ rb_define_method1(rb_cVec3, "distance_squared", vec3_distance_squared, 1);
692
+ rb_define_method1(rb_cVec3, "max", vec3_maxv, 1);
693
+ rb_define_method1(rb_cVec3, "min", vec3_minv, 1);
694
+ rb_define_method2(rb_cVec3, "clamp", vec3_clamp, 2);
695
+ rb_define_method2(rb_cVec3, "clamp!", vec3_clamp_bang, 2);
696
+ rb_define_methodm1(rb_cVec3, "rotate", vec3_rotate, -1);
697
+ rb_define_methodm1(rb_cVec3, "rotate!", vec3_rotate_bang, -1);
698
+ rb_define_methodm1(rb_cVec3, "lerp", vec3_lerp, -1);
699
+ rb_define_methodm1(rb_cVec3, "lerp!", vec3_lerp_bang, -1);
700
+ rb_define_methodm1(rb_cVec3, "smoothinterp", vec3_smoothinterp, -1);
701
+ rb_define_methodm1(rb_cVec3, "eql?", vec3_equal, -1);
702
+ rb_define_methodm1(rb_cVec3, "all?", vec3_all_p, -1);
703
+ rb_define_method1(rb_cVec3, "swizzle", vec3_swizzle, 1);
704
+ rb_define_method1(rb_cVec3, "swizzle!", vec3_swizzle_bang, 1);
705
+ rb_define_method0(rb_cVec3, "max_value", vec3_max_value, 0);
706
+ rb_define_method0(rb_cVec3, "min_value", vec3_min_value, 0);
707
+ rb_define_method0(rb_cVec3, "infinite?", vec3_infinite_p, 0);
708
+ rb_define_method0(rb_cVec3, "nan?", vec3_nan_p, 0);
709
+ rb_define_method1(rb_cVec3, "step", vec3_step, 1);
710
+ rb_define_method2(rb_cVec3, "smoothstep", vec3_smoothstep, 2);
711
+ rb_define_method0(rb_cVec3, "ortho", vec3_ortho, 0);
712
+ rb_define_method0(rb_cVec3, "sqrt", vec3_sqrt, 0);
713
+ rb_define_method0(rb_cVec3, "abs", vec3_abs, 0);
714
+ rb_define_method0(rb_cVec3, "sum", vec3_sum, 0);
715
+ rb_define_method0(rb_cVec3, "sign", vec3_sign, 0);
716
+ rb_define_method0(rb_cVec3, "fract", vec3_fract, 0);
717
+ rb_define_method0(rb_cVec3, "inspect", vec3_inspect, 0);
718
+ rb_define_method0(rb_cVec3, "to_s", vec3_inspect, 0);
719
+ rb_define_method0(rb_cVec3, "to_str", vec3_inspect, 0);
720
+
721
+ rb_define_method0(rb_cVec3, "x", vec3_get_x, 0);
722
+ rb_define_method0(rb_cVec3, "y", vec3_get_y, 0);
723
+ rb_define_method0(rb_cVec3, "z", vec3_get_z, 0);
724
+ rb_define_method1(rb_cVec3, "x=", vec3_set_x, 1);
725
+ rb_define_method1(rb_cVec3, "y=", vec3_set_y, 1);
726
+ rb_define_method1(rb_cVec3, "z=", vec3_set_z, 1);
727
+
728
+ rb_define_singleton_method0(rb_cVec3, "zero", vec3_zero, 0);
729
+ rb_define_singleton_method0(rb_cVec3, "one", vec3_one, 0);
730
+ rb_define_singleton_method0(rb_cVec3, "unit_x", vec3_unitx, 0);
731
+ rb_define_singleton_method0(rb_cVec3, "unit_y", vec3_unity, 0);
732
+ rb_define_singleton_method0(rb_cVec3, "unit_z", vec3_unitz, 0);
733
+
734
+ rb_define_alias(rb_cVec3, "dup", "copy");
735
+ rb_define_alias(rb_cVec3, "magnitude", "length");
736
+ rb_define_alias(rb_cVec3, "magnitude_squared", "length_squared");
737
+ rb_define_alias(rb_cVec3, "norm", "length");
738
+ rb_define_alias(rb_cVec3, "norm2", "length_squared");
739
+ rb_define_alias(rb_cVec3, "norm_one", "manhattan_distance");
740
+ rb_define_alias(rb_cVec3, "taxicab_norm", "manhattan_distance");
741
+ rb_define_alias(rb_cVec3, "max_norm", "norm_inf");
742
+ rb_define_alias(rb_cVec3, "+", "add");
743
+ rb_define_alias(rb_cVec3, "-", "subtract");
744
+ rb_define_alias(rb_cVec3, "*", "multiply");
745
+ rb_define_alias(rb_cVec3, "/", "divide");
746
+ rb_define_alias(rb_cVec3, "scale", "multiply");
747
+ rb_define_alias(rb_cVec3, "-@", "negate");
748
+ rb_define_alias(rb_cVec3, "==", "eql?");
749
+ rb_define_alias(rb_cVec3, "mix", "lerp");
750
+ rb_define_alias(rb_cVec3, "mix!", "lerp!");
751
+ }