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,681 @@
1
+ #include "game.h"
2
+
3
+ VALUE rb_cVec4;
4
+
5
+ CREATE_ALLOC_FUNC(vec4, RGSS_VEC4_ALIGN, RGSS_VEC4_SIZE)
6
+ VEC_ATTR_ACCESSOR(vec4, x, 0)
7
+ VEC_ATTR_ACCESSOR(vec4, y, 1)
8
+ VEC_ATTR_ACCESSOR(vec4, z, 2)
9
+ VEC_ATTR_ACCESSOR(vec4, w, 3)
10
+
11
+ static VALUE vec4_get(VALUE self, VALUE index)
12
+ {
13
+ int i = NUM2INT(index);
14
+ if (index < 0 || index > 3)
15
+ rb_raise(rb_eArgError, "index of of range (must be 0..3)");
16
+ return DBL2NUM(((float*) DATA_PTR(self))[i]);
17
+ }
18
+
19
+ static VALUE vec4_set(VALUE self, VALUE index, VALUE value)
20
+ {
21
+ int i = NUM2INT(index);
22
+ if (index < 0 || index > 3)
23
+ rb_raise(rb_eArgError, "index of of range (must be 0..3)");
24
+ ((float*) DATA_PTR(self))[i] = NUM2FLT(value);
25
+ return value;
26
+ }
27
+
28
+ static VALUE vec4_copy(VALUE self)
29
+ {
30
+ float *d = RGSS_VEC4_NEW;
31
+ glm_vec4_copy(DATA_PTR(self), d);
32
+ return VEC4_WRAP(d);
33
+ }
34
+
35
+ static VALUE vec4_zero(VALUE klass)
36
+ {
37
+ float *d = RGSS_VEC4_NEW;
38
+ glm_vec4_zero(d);
39
+ return VEC4_WRAP(d);
40
+ }
41
+
42
+ static VALUE vec4_one(VALUE klass)
43
+ {
44
+ float *d = RGSS_VEC4_NEW;
45
+ glm_vec4_one(d);
46
+ return VEC4_WRAP(d);
47
+ }
48
+
49
+ static VALUE vec4_unitx(VALUE klass)
50
+ {
51
+ return RGSS_Vec4_New(1.0f, 0.0f, 0.0f, 0.0f);
52
+ }
53
+
54
+ static VALUE vec4_unity(VALUE klass)
55
+ {
56
+ return RGSS_Vec4_New(0.0f, 1.0f, 0.0f, 0.0f);
57
+ }
58
+
59
+ static VALUE vec4_unitz(VALUE klass)
60
+ {
61
+ return RGSS_Vec4_New(0.0f, 0.0f, 1.0f, 0.0f);
62
+ }
63
+
64
+ static VALUE vec4_unitw(VALUE klass)
65
+ {
66
+ return RGSS_Vec4_New(0.0f, 0.0f, 0.0f, 1.0f);
67
+ }
68
+
69
+ static VALUE vec4_dot(VALUE self, VALUE other)
70
+ {
71
+ return DBL2NUM(glm_vec4_dot(DATA_PTR(self), DATA_PTR(other)));
72
+ }
73
+
74
+ static VALUE vec4_add(VALUE self, VALUE other)
75
+ {
76
+ float *d = RGSS_VEC4_NEW;
77
+ float *v = DATA_PTR(self);
78
+
79
+ if (RB_TYPE_P(other, T_DATA))
80
+ {
81
+ glm_vec4_add(v, DATA_PTR(other), d);
82
+ }
83
+ else
84
+ {
85
+ glm_vec4_adds(v, NUM2FLT(other), d);
86
+ }
87
+ return VEC4_WRAP(d);
88
+ }
89
+
90
+ static VALUE vec4_sub(VALUE self, VALUE other)
91
+ {
92
+ float *d = RGSS_VEC4_NEW;
93
+ float *v = DATA_PTR(self);
94
+
95
+ if (RB_TYPE_P(other, T_DATA))
96
+ {
97
+ glm_vec4_sub(v, DATA_PTR(other), d);
98
+ }
99
+ else
100
+ {
101
+ glm_vec4_subs(v, NUM2FLT(other), d);
102
+ }
103
+ return VEC4_WRAP(d);
104
+ }
105
+
106
+ static VALUE vec4_mul(VALUE self, VALUE other)
107
+ {
108
+ float *d = RGSS_VEC4_NEW;
109
+ float *v = DATA_PTR(self);
110
+
111
+ if (RB_TYPE_P(other, T_DATA))
112
+ {
113
+ glm_vec4_mul(v, DATA_PTR(other), d);
114
+ }
115
+ else
116
+ {
117
+ glm_vec4_scale(v, NUM2FLT(other), d);
118
+ }
119
+ return VEC4_WRAP(d);
120
+ }
121
+
122
+ static VALUE vec4_div(VALUE self, VALUE other)
123
+ {
124
+ float *d = RGSS_VEC4_NEW;
125
+ float *v = DATA_PTR(self);
126
+
127
+ if (RB_TYPE_P(other, T_DATA))
128
+ {
129
+ glm_vec4_div(v, DATA_PTR(other), d);
130
+ }
131
+ else
132
+ {
133
+ glm_vec4_divs(v, NUM2FLT(other), d);
134
+ }
135
+ return VEC4_WRAP(d);
136
+ }
137
+
138
+ static VALUE vec4_add_add(VALUE self, VALUE other)
139
+ {
140
+ float *d = RGSS_VEC4_NEW;
141
+ glm_vec4_addadd(DATA_PTR(self), DATA_PTR(other), d);
142
+ return VEC4_WRAP(d);
143
+ }
144
+
145
+ static VALUE vec4_sub_add(VALUE self, VALUE other)
146
+ {
147
+ float *d = RGSS_VEC4_NEW;
148
+ glm_vec4_subadd(DATA_PTR(self), DATA_PTR(other), d);
149
+ return VEC4_WRAP(d);
150
+ }
151
+
152
+ static VALUE vec4_mul_add(VALUE self, VALUE other)
153
+ {
154
+ float *d = RGSS_VEC4_NEW;
155
+ float *v = DATA_PTR(self);
156
+
157
+ if (RB_TYPE_P(other, T_DATA))
158
+ {
159
+ glm_vec4_muladd(v, DATA_PTR(other), d);
160
+ }
161
+ else
162
+ {
163
+ glm_vec4_muladds(v, NUM2FLT(other), d);
164
+ }
165
+
166
+ return VEC4_WRAP(d);
167
+ }
168
+
169
+ static VALUE vec4_max_add(VALUE self, VALUE other)
170
+ {
171
+ float *d = RGSS_VEC4_NEW;
172
+ glm_vec4_maxadd(DATA_PTR(self), DATA_PTR(other), d);
173
+ return VEC4_WRAP(d);
174
+ }
175
+
176
+ static VALUE vec4_min_add(VALUE self, VALUE other)
177
+ {
178
+ float *d = RGSS_VEC4_NEW;
179
+ glm_vec4_minadd(DATA_PTR(self), DATA_PTR(other), d);
180
+ return VEC4_WRAP(d);
181
+ }
182
+
183
+ static VALUE vec4_length(VALUE self)
184
+ {
185
+ return DBL2NUM(glm_vec4_norm(DATA_PTR(self)));
186
+ }
187
+
188
+ static VALUE vec4_length_squared(VALUE self)
189
+ {
190
+ return DBL2NUM(glm_vec4_norm(DATA_PTR(self)));
191
+ }
192
+
193
+ static VALUE vec4_norm_scale(VALUE self, VALUE value)
194
+ {
195
+ float *d = RGSS_VEC4_NEW;
196
+ glm_vec4_scale_as(DATA_PTR(self), NUM2FLT(value), d);
197
+ return VEC4_WRAP(d);
198
+ }
199
+
200
+ static VALUE vec4_negate(VALUE self)
201
+ {
202
+ float *d = RGSS_VEC4_NEW;
203
+ glm_vec4_negate_to(DATA_PTR(self), d);
204
+ return VEC4_WRAP(d);
205
+ }
206
+
207
+ static VALUE vec4_negate_bang(VALUE self)
208
+ {
209
+ glm_vec4_negate(DATA_PTR(self));
210
+ return self;
211
+ }
212
+
213
+ static VALUE vec4_manhattan_distance(VALUE self)
214
+ {
215
+ return DBL2NUM(glm_vec4_norm_one(DATA_PTR(self)));
216
+ }
217
+
218
+ static VALUE vec4_norm_inf(VALUE self)
219
+ {
220
+ return DBL2NUM(glm_vec4_norm_inf(DATA_PTR(self)));
221
+ }
222
+
223
+ static VALUE vec4_normalize(VALUE self)
224
+ {
225
+ float *d = RGSS_VEC4_NEW;
226
+ glm_vec4_normalize_to(DATA_PTR(self), d);
227
+ return VEC4_WRAP(d);
228
+ }
229
+
230
+ static VALUE vec4_normalize_bang(VALUE self)
231
+ {
232
+ glm_vec4_normalize(DATA_PTR(self));
233
+ return self;
234
+ }
235
+
236
+ static VALUE vec4_distance(VALUE self, VALUE other)
237
+ {
238
+ return DBL2NUM(glm_vec4_distance(DATA_PTR(self), DATA_PTR(other)));
239
+ }
240
+
241
+ static VALUE vec4_distance_squared(VALUE self, VALUE other)
242
+ {
243
+ return DBL2NUM(glm_vec4_distance2(DATA_PTR(self), DATA_PTR(other)));
244
+ }
245
+
246
+ static VALUE vec4_maxv(VALUE self, VALUE other)
247
+ {
248
+ float *d = RGSS_VEC4_NEW;
249
+ glm_vec4_maxv(DATA_PTR(self), DATA_PTR(other), d);
250
+ return VEC4_WRAP(d);
251
+ }
252
+
253
+ static VALUE vec4_minv(VALUE self, VALUE other)
254
+ {
255
+ float *d = RGSS_VEC4_NEW;
256
+ glm_vec4_minv(DATA_PTR(self), DATA_PTR(other), d);
257
+ return VEC4_WRAP(d);
258
+ }
259
+
260
+ static VALUE vec4_clamp_bang(VALUE self, VALUE min, VALUE max)
261
+ {
262
+ glm_vec4_clamp(DATA_PTR(self), NUM2FLT(min), NUM2FLT(max));
263
+ return self;
264
+ }
265
+
266
+ static VALUE vec4_clamp(VALUE self, VALUE min, VALUE max)
267
+ {
268
+ return vec4_clamp(vec4_copy(self), min, max);
269
+ }
270
+
271
+ static VALUE vec4_lerp_bang(int argc, VALUE *argv, VALUE self)
272
+ {
273
+ VALUE other, weight, clamped;
274
+ rb_scan_args(argc, argv, "21", &other, &weight, &clamped);
275
+
276
+ float *v = DATA_PTR(self);
277
+
278
+ if (RTEST(clamped))
279
+ {
280
+ glm_vec4_lerpc(v, DATA_PTR(other), NUM2FLT(weight), v);
281
+ }
282
+ else
283
+ {
284
+ glm_vec4_lerp(v, DATA_PTR(other), NUM2FLT(weight), v);
285
+ }
286
+ return self;
287
+ }
288
+
289
+ static VALUE vec4_lerp(int argc, VALUE *argv, VALUE self)
290
+ {
291
+ VALUE other, weight, clamped;
292
+ rb_scan_args(argc, argv, "21", &other, &weight, &clamped);
293
+
294
+ float *d = RGSS_VEC4_NEW;
295
+ float *v = DATA_PTR(self);
296
+
297
+ if (RTEST(clamped))
298
+ {
299
+ glm_vec4_lerpc(v, DATA_PTR(other), NUM2FLT(weight), d);
300
+ }
301
+ else
302
+ {
303
+ glm_vec4_lerp(v, DATA_PTR(other), NUM2FLT(weight), d);
304
+ }
305
+ return VEC4_WRAP(d);
306
+ }
307
+
308
+ static VALUE vec4_step(VALUE self, VALUE edge)
309
+ {
310
+ float *d = RGSS_VEC4_NEW;
311
+ float *v = DATA_PTR(self);
312
+
313
+ if (RB_TYPE_P(edge, T_DATA))
314
+ {
315
+ glm_vec4_step(DATA_PTR(edge), v, d);
316
+ }
317
+ else
318
+ {
319
+ glm_vec4_step_uni(NUM2FLT(edge), v, d);
320
+ }
321
+
322
+ return VEC4_WRAP(d);
323
+ }
324
+
325
+ static VALUE vec4_smoothstep(VALUE self, VALUE low, VALUE high)
326
+ {
327
+ float *v = DATA_PTR(self);
328
+ float *d = RGSS_VEC4_NEW;
329
+
330
+ if (RB_TYPE_P(low, T_DATA) && RB_TYPE_P(high, T_DATA))
331
+ {
332
+ glm_vec4_smoothstep(v, DATA_PTR(low), DATA_PTR(high), d);
333
+ }
334
+ else
335
+ {
336
+ glm_vec4_smoothstep_uni(NUM2FLT(low), NUM2FLT(high), v, d);
337
+ }
338
+
339
+ return VEC4_WRAP(d);
340
+ }
341
+
342
+ static VALUE vec4_smoothinterp(int argc, VALUE *argv, VALUE self)
343
+ {
344
+ VALUE other, weight, clamped;
345
+ rb_scan_args(argc, argv, "21", &other, &weight, &clamped);
346
+
347
+ float *from = DATA_PTR(self), *to = DATA_PTR(other);
348
+ float w = NUM2FLT(weight);
349
+ float *d = RGSS_VEC4_NEW;
350
+
351
+ if (RTEST(clamped))
352
+ {
353
+ glm_vec4_smoothinterpc(from, to, w, d);
354
+ }
355
+ else
356
+ {
357
+ glm_vec4_smoothinterp(from, to, w, d);
358
+ }
359
+ return VEC4_WRAP(d);
360
+ }
361
+
362
+ static VALUE vec4_swizzle(VALUE self, VALUE mask)
363
+ {
364
+ float *d = RGSS_VEC4_NEW;
365
+ glm_vec4_swizzle(DATA_PTR(self), NUM2INT(mask), d);
366
+ return VEC4_WRAP(d);
367
+ }
368
+
369
+ static VALUE vec4_swizzle_bang(VALUE self, VALUE mask)
370
+ {
371
+ vec4 temp;
372
+ glm_vec4_swizzle(DATA_PTR(self), NUM2INT(mask), temp);
373
+ glm_vec4_copy(temp, DATA_PTR(self));
374
+ return self;
375
+ }
376
+
377
+ static VALUE vec4_inspect(VALUE self)
378
+ {
379
+ float *v = DATA_PTR(self);
380
+ return rb_sprintf("<%f, %f, %f, %f>", v[0], v[1], v[2], v[3]);
381
+ }
382
+
383
+ static VALUE vec4_cubic(VALUE klass, VALUE parameter)
384
+ {
385
+ float *d = RGSS_VEC4_NEW;
386
+ glm_vec4_cubic(NUM2FLT(parameter), d);
387
+ return VEC4_WRAP(d);
388
+ }
389
+
390
+ static VALUE vec4_equal(int argc, VALUE *argv, VALUE self)
391
+ {
392
+ VALUE other, epsilon;
393
+ rb_scan_args(argc, argv, "11", &other, &epsilon);
394
+
395
+ if (CLASS_OF(self) != CLASS_OF(other))
396
+ return Qfalse;
397
+
398
+ float *v1 = DATA_PTR(self), *v2 = DATA_PTR(other);
399
+ bool result = RTEST(epsilon) ? glm_vec4_eqv_eps(v1, v2) : glm_vec4_eqv(v1, v2);
400
+
401
+ return RB_BOOL(result);
402
+ }
403
+
404
+ static VALUE vec4_all_p(int argc, VALUE *argv, VALUE self)
405
+ {
406
+ VALUE value, epsilon;
407
+ rb_scan_args(argc, argv, "11", &value, &epsilon);
408
+
409
+ float *v1 = DATA_PTR(self), v2 = NUM2FLT(value);
410
+ bool result = RTEST(epsilon) ? glm_vec4_eq_eps(v1, v2) : glm_vec4_eq(v1, v2);
411
+
412
+ return RB_BOOL(result);
413
+ }
414
+
415
+ static VALUE vec4_max_value(VALUE self)
416
+ {
417
+ return DBL2NUM(glm_vec4_max(DATA_PTR(self)));
418
+ }
419
+
420
+ static VALUE vec4_min_value(VALUE self)
421
+ {
422
+ return DBL2NUM(glm_vec4_min(DATA_PTR(self)));
423
+ }
424
+
425
+ static VALUE vec4_infinite_p(VALUE self)
426
+ {
427
+ return RB_BOOL(glm_vec4_isinf(DATA_PTR(self)));
428
+ }
429
+
430
+ static VALUE vec4_nan_p(VALUE self)
431
+ {
432
+ return RB_BOOL(glm_vec4_isnan(DATA_PTR(self)));
433
+ }
434
+
435
+ static VALUE vec4_sqrt(VALUE self)
436
+ {
437
+ float *d = RGSS_VEC4_NEW;
438
+ glm_vec4_sqrt(DATA_PTR(self), d);
439
+ return VEC4_WRAP(d);
440
+ }
441
+
442
+ static VALUE vec4_abs(VALUE self)
443
+ {
444
+ float *d = RGSS_VEC4_NEW;
445
+ glm_vec4_abs(DATA_PTR(self), d);
446
+ return VEC4_WRAP(d);
447
+ }
448
+
449
+ static VALUE vec4_sum(VALUE self)
450
+ {
451
+ return DBL2NUM(glm_vec4_hadd(DATA_PTR(self)));
452
+ }
453
+
454
+ static VALUE vec4_sign(VALUE self)
455
+ {
456
+ float *d = RGSS_VEC4_NEW;
457
+ glm_vec4_sign(DATA_PTR(self), d);
458
+ return VEC4_WRAP(d);
459
+ }
460
+
461
+ static VALUE vec4_fract(VALUE self)
462
+ {
463
+ float *d = RGSS_VEC4_NEW;
464
+ glm_vec4_fract(DATA_PTR(self), d);
465
+ return VEC4_WRAP(d);
466
+ }
467
+
468
+ static inline void vec4_create(int argc, VALUE *argv, vec4 v)
469
+ {
470
+ VALUE x, y, z, w;
471
+ rb_scan_args(argc, argv, "04", &x, &y, &z, &w);
472
+
473
+ switch (argc)
474
+ {
475
+ case 0:
476
+ {
477
+ // vec4()
478
+ glm_vec4_zero(v);
479
+ break;
480
+ }
481
+ case 1:
482
+ {
483
+ if (RB_TYPE_P(x, T_DATA))
484
+ {
485
+ // vec4(v4)
486
+ glm_vec4_copy(DATA_PTR(x), v);
487
+ }
488
+ else
489
+ {
490
+ // vec4(float)
491
+ glm_vec4_fill(v, NUM2FLT(x));
492
+ }
493
+ break;
494
+ }
495
+ case 2:
496
+ {
497
+ if (RB_TYPE_P(x, T_DATA))
498
+ {
499
+ if (RB_TYPE_P(y, T_DATA))
500
+ {
501
+ // vec4(vec2, vec2)
502
+ float *v1 = DATA_PTR(x), *v2 = DATA_PTR(y);
503
+ v[0] = v1[0];
504
+ v[1] = v1[1];
505
+ v[2] = v2[0];
506
+ v[3] = v2[1];
507
+ }
508
+ else
509
+ {
510
+ // vec4(vec3, float)
511
+ glm_vec4(DATA_PTR(x), NUM2FLT(y), v);
512
+ }
513
+ }
514
+ else
515
+ {
516
+ // vec4(float, vec3)
517
+ float *v3 = DATA_PTR(y);
518
+ v[0] = NUM2FLT(x);
519
+ v[1] = v3[0];
520
+ v[2] = v3[1];
521
+ v[3] = v3[2];
522
+ }
523
+ break;
524
+ }
525
+ case 3:
526
+ {
527
+ float *v2;
528
+ if (RB_TYPE_P(x, T_DATA))
529
+ {
530
+ // vec4(vec2, float, float)
531
+ v2 = DATA_PTR(x);
532
+ v[0] = v2[0];
533
+ v[1] = v2[1];
534
+ v[2] = NUM2FLT(y);
535
+ v[3] = NUM2FLT(z);
536
+ }
537
+ else if (RB_TYPE_P(y, T_DATA))
538
+ {
539
+ // vec4(float, vec2, float)
540
+ v2 = DATA_PTR(y);
541
+ v[0] = NUM2FLT(x);
542
+ v[1] = v2[0];
543
+ v[2] = v2[1];
544
+ v[3] = NUM2FLT(z);
545
+ }
546
+ else
547
+ {
548
+ // vec4(float, float, vec2)
549
+ v2 = DATA_PTR(z);
550
+ v[0] = NUM2FLT(x);
551
+ v[1] = NUM2FLT(y);
552
+ v[2] = v2[0];
553
+ v[3] = v2[1];
554
+ }
555
+ break;
556
+ }
557
+ case 4:
558
+ {
559
+ // vec3(float, float, float, float)
560
+ v[0] = NUM2FLT(x);
561
+ v[1] = NUM2FLT(y);
562
+ v[2] = NUM2FLT(z);
563
+ v[3] = NUM2FLT(w);
564
+ break;
565
+ }
566
+ }
567
+ }
568
+
569
+ static VALUE vec4_initialize(int argc, VALUE *argv, VALUE self)
570
+ {
571
+ if (CLASS_OF(self) != rb_cVec4)
572
+ rb_warn("inheriting from %s may result in undefined behavior", rb_class2name(rb_cVec4));
573
+
574
+ vec4_create(argc, argv, DATA_PTR(self));
575
+ return Qnil;
576
+ }
577
+
578
+ static VALUE vec4_kernel_create(int argc, VALUE *argv, VALUE module)
579
+ {
580
+ float *v = RGSS_VEC4_NEW;
581
+ vec4_create(argc, argv, v);
582
+ return VEC4_WRAP(v);
583
+ }
584
+
585
+ void RGSS_Init_Vec4(VALUE parent)
586
+ {
587
+ rb_cVec4 = rb_define_class_under(parent, "Vec4", rb_cObject);
588
+ rb_define_alloc_func(rb_cVec4, vec4_alloc);
589
+ rb_define_methodm1(rb_cVec4, "initialize", vec4_initialize, -1);
590
+ rb_define_methodm1(rb_mKernel, "vec4", vec4_kernel_create, -1);
591
+
592
+ rb_define_const(rb_cVec4, "SIZE", SIZET2NUM(RGSS_VEC4_SIZE));
593
+ rb_define_const(rb_cVec4, "ALIGN", SIZET2NUM(RGSS_VEC4_ALIGN));
594
+ rb_define_const(rb_cVec4, "MASK_XXXX", INT2NUM(GLM_XXXX));
595
+ rb_define_const(rb_cVec4, "MASK_YYYY", INT2NUM(GLM_YYYY));
596
+ rb_define_const(rb_cVec4, "MASK_ZZZZ", INT2NUM(GLM_ZZZZ));
597
+ rb_define_const(rb_cVec4, "MASK_WWWW", INT2NUM(GLM_WWWW));
598
+ rb_define_const(rb_cVec4, "MASK_WZYX", INT2NUM(GLM_WZYX));
599
+
600
+ rb_define_method1(rb_cVec4, "[]", vec4_get, 1);
601
+ rb_define_method2(rb_cVec4, "[]=", vec4_set, 2);
602
+ rb_define_method0(rb_cVec4, "x", vec4_get_x, 0);
603
+ rb_define_method0(rb_cVec4, "y", vec4_get_y, 0);
604
+ rb_define_method0(rb_cVec4, "z", vec4_get_z, 0);
605
+ rb_define_method0(rb_cVec4, "w", vec4_get_w, 0);
606
+ rb_define_method1(rb_cVec4, "x=", vec4_set_x, 1);
607
+ rb_define_method1(rb_cVec4, "y=", vec4_set_y, 1);
608
+ rb_define_method1(rb_cVec4, "z=", vec4_set_z, 1);
609
+ rb_define_method1(rb_cVec4, "w=", vec4_set_w, 1);
610
+ rb_define_method0(rb_cVec4, "copy", vec4_copy, 0);
611
+ rb_define_method1(rb_cVec4, "dot", vec4_dot, 1);
612
+ rb_define_method1(rb_cVec4, "add", vec4_add, 1);
613
+ rb_define_method1(rb_cVec4, "subtract", vec4_sub, 1);
614
+ rb_define_method1(rb_cVec4, "multiply", vec4_mul, 1);
615
+ rb_define_method1(rb_cVec4, "divide", vec4_div, 1);
616
+ rb_define_method1(rb_cVec4, "norm_scale", vec4_norm_scale, 1);
617
+ rb_define_method1(rb_cVec4, "add_add", vec4_add_add, 1);
618
+ rb_define_method1(rb_cVec4, "sub_add", vec4_sub_add, 1);
619
+ rb_define_method1(rb_cVec4, "mul_add", vec4_mul_add, 1);
620
+ rb_define_method1(rb_cVec4, "max_add", vec4_max_add, 1);
621
+ rb_define_method1(rb_cVec4, "min_add", vec4_min_add, 1);
622
+ rb_define_method0(rb_cVec4, "length", vec4_length, 0);
623
+ rb_define_method0(rb_cVec4, "length_squared", vec4_length_squared, 0);
624
+ rb_define_method0(rb_cVec4, "negate", vec4_negate, 0);
625
+ rb_define_method0(rb_cVec4, "negate!", vec4_negate_bang, 0);
626
+ rb_define_method0(rb_cVec4, "manhattan_distance", vec4_manhattan_distance, 0);
627
+ rb_define_method0(rb_cVec4, "norm_inf", vec4_norm_inf, 0);
628
+ rb_define_method0(rb_cVec4, "normalize", vec4_normalize, 0);
629
+ rb_define_method0(rb_cVec4, "normalize!", vec4_normalize_bang, 0);
630
+ rb_define_method1(rb_cVec4, "distance", vec4_distance, 1);
631
+ rb_define_method1(rb_cVec4, "distance_squared", vec4_distance_squared, 1);
632
+ rb_define_method1(rb_cVec4, "max", vec4_maxv, 1);
633
+ rb_define_method1(rb_cVec4, "min", vec4_minv, 1);
634
+ rb_define_method2(rb_cVec4, "clamp", vec4_clamp, 2);
635
+ rb_define_method2(rb_cVec4, "clamp!", vec4_clamp_bang, 2);
636
+ rb_define_methodm1(rb_cVec4, "lerp", vec4_lerp, -1);
637
+ rb_define_methodm1(rb_cVec4, "lerp!", vec4_lerp_bang, -1);
638
+ rb_define_methodm1(rb_cVec4, "smoothinterp", vec4_smoothinterp, -1);
639
+ rb_define_method1(rb_cVec4, "step", vec4_step, 1);
640
+ rb_define_method2(rb_cVec4, "smoothstep", vec4_smoothstep, 2);
641
+ rb_define_method1(rb_cVec4, "swizzle", vec4_swizzle, 1);
642
+ rb_define_method1(rb_cVec4, "swizzle!", vec4_swizzle_bang, 1);
643
+ rb_define_method0(rb_cVec4, "inspect", vec4_inspect, 0);
644
+ rb_define_method0(rb_cVec4, "to_s", vec4_inspect, 0);
645
+ rb_define_method0(rb_cVec4, "to_str", vec4_inspect, 0);
646
+ rb_define_methodm1(rb_cVec4, "eql?", vec4_equal, -1);
647
+ rb_define_methodm1(rb_cVec4, "all?", vec4_all_p, -1);
648
+ rb_define_method0(rb_cVec4, "max_value", vec4_max_value, 0);
649
+ rb_define_method0(rb_cVec4, "min_value", vec4_min_value, 0);
650
+ rb_define_method0(rb_cVec4, "infinite?", vec4_infinite_p, 0);
651
+ rb_define_method0(rb_cVec4, "nan?", vec4_nan_p, 0);
652
+ rb_define_method0(rb_cVec4, "sqrt", vec4_sqrt, 0);
653
+ rb_define_method0(rb_cVec4, "abs", vec4_abs, 0);
654
+ rb_define_method0(rb_cVec4, "sum", vec4_sum, 0);
655
+ rb_define_method0(rb_cVec4, "sign", vec4_sign, 0);
656
+ rb_define_method0(rb_cVec4, "fract", vec4_fract, 0);
657
+
658
+ rb_define_alias(rb_cVec4, "dup", "copy");
659
+ rb_define_alias(rb_cVec4, "+", "add");
660
+ rb_define_alias(rb_cVec4, "-", "subtract");
661
+ rb_define_alias(rb_cVec4, "*", "multiply");
662
+ rb_define_alias(rb_cVec4, "/", "divide");
663
+ rb_define_alias(rb_cVec4, "==", "eql?");
664
+ rb_define_alias(rb_cVec4, "norm", "length");
665
+ rb_define_alias(rb_cVec4, "norm2", "length_squared");
666
+ rb_define_alias(rb_cVec4, "scale", "multiply");
667
+ rb_define_alias(rb_cVec4, "-@", "negate");
668
+ rb_define_alias(rb_cVec4, "norm_one", "manhattan_distance");
669
+ rb_define_alias(rb_cVec4, "taxicab_norm", "manhattan_distance");
670
+ rb_define_alias(rb_cVec4, "max_norm", "norm_inf");
671
+ rb_define_alias(rb_cVec4, "mix", "lerp");
672
+ rb_define_alias(rb_cVec4, "mix!", "lerp!");
673
+
674
+ rb_define_singleton_method0(rb_cVec4, "zero", vec4_zero, 0);
675
+ rb_define_singleton_method0(rb_cVec4, "one", vec4_one, 0);
676
+ rb_define_singleton_method0(rb_cVec4, "unit_x", vec4_unitx, 0);
677
+ rb_define_singleton_method0(rb_cVec4, "unit_y", vec4_unity, 0);
678
+ rb_define_singleton_method0(rb_cVec4, "unit_z", vec4_unitz, 0);
679
+ rb_define_singleton_method0(rb_cVec4, "unit_w", vec4_unitw, 0);
680
+ rb_define_singleton_method1(rb_cVec4, "cubic", vec4_cubic, 1);
681
+ }