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,290 @@
1
+ #ifndef __khrplatform_h_
2
+ #define __khrplatform_h_
3
+
4
+ /*
5
+ ** Copyright (c) 2008-2018 The Khronos Group Inc.
6
+ **
7
+ ** Permission is hereby granted, free of charge, to any person obtaining a
8
+ ** copy of this software and/or associated documentation files (the
9
+ ** "Materials"), to deal in the Materials without restriction, including
10
+ ** without limitation the rights to use, copy, modify, merge, publish,
11
+ ** distribute, sublicense, and/or sell copies of the Materials, and to
12
+ ** permit persons to whom the Materials are furnished to do so, subject to
13
+ ** the following conditions:
14
+ **
15
+ ** The above copyright notice and this permission notice shall be included
16
+ ** in all copies or substantial portions of the Materials.
17
+ **
18
+ ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
+ ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22
+ ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
+ ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
25
+ */
26
+
27
+ /* Khronos platform-specific types and definitions.
28
+ *
29
+ * The master copy of khrplatform.h is maintained in the Khronos EGL
30
+ * Registry repository at https://github.com/KhronosGroup/EGL-Registry
31
+ * The last semantic modification to khrplatform.h was at commit ID:
32
+ * 67a3e0864c2d75ea5287b9f3d2eb74a745936692
33
+ *
34
+ * Adopters may modify this file to suit their platform. Adopters are
35
+ * encouraged to submit platform specific modifications to the Khronos
36
+ * group so that they can be included in future versions of this file.
37
+ * Please submit changes by filing pull requests or issues on
38
+ * the EGL Registry repository linked above.
39
+ *
40
+ *
41
+ * See the Implementer's Guidelines for information about where this file
42
+ * should be located on your system and for more details of its use:
43
+ * http://www.khronos.org/registry/implementers_guide.pdf
44
+ *
45
+ * This file should be included as
46
+ * #include <KHR/khrplatform.h>
47
+ * by Khronos client API header files that use its types and defines.
48
+ *
49
+ * The types in khrplatform.h should only be used to define API-specific types.
50
+ *
51
+ * Types defined in khrplatform.h:
52
+ * khronos_int8_t signed 8 bit
53
+ * khronos_uint8_t unsigned 8 bit
54
+ * khronos_int16_t signed 16 bit
55
+ * khronos_uint16_t unsigned 16 bit
56
+ * khronos_int32_t signed 32 bit
57
+ * khronos_uint32_t unsigned 32 bit
58
+ * khronos_int64_t signed 64 bit
59
+ * khronos_uint64_t unsigned 64 bit
60
+ * khronos_intptr_t signed same number of bits as a pointer
61
+ * khronos_uintptr_t unsigned same number of bits as a pointer
62
+ * khronos_ssize_t signed size
63
+ * khronos_usize_t unsigned size
64
+ * khronos_float_t signed 32 bit floating point
65
+ * khronos_time_ns_t unsigned 64 bit time in nanoseconds
66
+ * khronos_utime_nanoseconds_t unsigned time interval or absolute time in
67
+ * nanoseconds
68
+ * khronos_stime_nanoseconds_t signed time interval in nanoseconds
69
+ * khronos_boolean_enum_t enumerated boolean type. This should
70
+ * only be used as a base type when a client API's boolean type is
71
+ * an enum. Client APIs which use an integer or other type for
72
+ * booleans cannot use this as the base type for their boolean.
73
+ *
74
+ * Tokens defined in khrplatform.h:
75
+ *
76
+ * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
77
+ *
78
+ * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
79
+ * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
80
+ *
81
+ * Calling convention macros defined in this file:
82
+ * KHRONOS_APICALL
83
+ * KHRONOS_APIENTRY
84
+ * KHRONOS_APIATTRIBUTES
85
+ *
86
+ * These may be used in function prototypes as:
87
+ *
88
+ * KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
89
+ * int arg1,
90
+ * int arg2) KHRONOS_APIATTRIBUTES;
91
+ */
92
+
93
+ #if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
94
+ # define KHRONOS_STATIC 1
95
+ #endif
96
+
97
+ /*-------------------------------------------------------------------------
98
+ * Definition of KHRONOS_APICALL
99
+ *-------------------------------------------------------------------------
100
+ * This precedes the return type of the function in the function prototype.
101
+ */
102
+ #if defined(KHRONOS_STATIC)
103
+ /* If the preprocessor constant KHRONOS_STATIC is defined, make the
104
+ * header compatible with static linking. */
105
+ # define KHRONOS_APICALL
106
+ #elif defined(_WIN32)
107
+ # define KHRONOS_APICALL __declspec(dllimport)
108
+ #elif defined (__SYMBIAN32__)
109
+ # define KHRONOS_APICALL IMPORT_C
110
+ #elif defined(__ANDROID__)
111
+ # define KHRONOS_APICALL __attribute__((visibility("default")))
112
+ #else
113
+ # define KHRONOS_APICALL
114
+ #endif
115
+
116
+ /*-------------------------------------------------------------------------
117
+ * Definition of KHRONOS_APIENTRY
118
+ *-------------------------------------------------------------------------
119
+ * This follows the return type of the function and precedes the function
120
+ * name in the function prototype.
121
+ */
122
+ #if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
123
+ /* Win32 but not WinCE */
124
+ # define KHRONOS_APIENTRY __stdcall
125
+ #else
126
+ # define KHRONOS_APIENTRY
127
+ #endif
128
+
129
+ /*-------------------------------------------------------------------------
130
+ * Definition of KHRONOS_APIATTRIBUTES
131
+ *-------------------------------------------------------------------------
132
+ * This follows the closing parenthesis of the function prototype arguments.
133
+ */
134
+ #if defined (__ARMCC_2__)
135
+ #define KHRONOS_APIATTRIBUTES __softfp
136
+ #else
137
+ #define KHRONOS_APIATTRIBUTES
138
+ #endif
139
+
140
+ /*-------------------------------------------------------------------------
141
+ * basic type definitions
142
+ *-----------------------------------------------------------------------*/
143
+ #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
144
+
145
+
146
+ /*
147
+ * Using <stdint.h>
148
+ */
149
+ #include <stdint.h>
150
+ typedef int32_t khronos_int32_t;
151
+ typedef uint32_t khronos_uint32_t;
152
+ typedef int64_t khronos_int64_t;
153
+ typedef uint64_t khronos_uint64_t;
154
+ #define KHRONOS_SUPPORT_INT64 1
155
+ #define KHRONOS_SUPPORT_FLOAT 1
156
+
157
+ #elif defined(__VMS ) || defined(__sgi)
158
+
159
+ /*
160
+ * Using <inttypes.h>
161
+ */
162
+ #include <inttypes.h>
163
+ typedef int32_t khronos_int32_t;
164
+ typedef uint32_t khronos_uint32_t;
165
+ typedef int64_t khronos_int64_t;
166
+ typedef uint64_t khronos_uint64_t;
167
+ #define KHRONOS_SUPPORT_INT64 1
168
+ #define KHRONOS_SUPPORT_FLOAT 1
169
+
170
+ #elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
171
+
172
+ /*
173
+ * Win32
174
+ */
175
+ typedef __int32 khronos_int32_t;
176
+ typedef unsigned __int32 khronos_uint32_t;
177
+ typedef __int64 khronos_int64_t;
178
+ typedef unsigned __int64 khronos_uint64_t;
179
+ #define KHRONOS_SUPPORT_INT64 1
180
+ #define KHRONOS_SUPPORT_FLOAT 1
181
+
182
+ #elif defined(__sun__) || defined(__digital__)
183
+
184
+ /*
185
+ * Sun or Digital
186
+ */
187
+ typedef int khronos_int32_t;
188
+ typedef unsigned int khronos_uint32_t;
189
+ #if defined(__arch64__) || defined(_LP64)
190
+ typedef long int khronos_int64_t;
191
+ typedef unsigned long int khronos_uint64_t;
192
+ #else
193
+ typedef long long int khronos_int64_t;
194
+ typedef unsigned long long int khronos_uint64_t;
195
+ #endif /* __arch64__ */
196
+ #define KHRONOS_SUPPORT_INT64 1
197
+ #define KHRONOS_SUPPORT_FLOAT 1
198
+
199
+ #elif 0
200
+
201
+ /*
202
+ * Hypothetical platform with no float or int64 support
203
+ */
204
+ typedef int khronos_int32_t;
205
+ typedef unsigned int khronos_uint32_t;
206
+ #define KHRONOS_SUPPORT_INT64 0
207
+ #define KHRONOS_SUPPORT_FLOAT 0
208
+
209
+ #else
210
+
211
+ /*
212
+ * Generic fallback
213
+ */
214
+ #include <stdint.h>
215
+ typedef int32_t khronos_int32_t;
216
+ typedef uint32_t khronos_uint32_t;
217
+ typedef int64_t khronos_int64_t;
218
+ typedef uint64_t khronos_uint64_t;
219
+ #define KHRONOS_SUPPORT_INT64 1
220
+ #define KHRONOS_SUPPORT_FLOAT 1
221
+
222
+ #endif
223
+
224
+
225
+ /*
226
+ * Types that are (so far) the same on all platforms
227
+ */
228
+ typedef signed char khronos_int8_t;
229
+ typedef unsigned char khronos_uint8_t;
230
+ typedef signed short int khronos_int16_t;
231
+ typedef unsigned short int khronos_uint16_t;
232
+
233
+ /*
234
+ * Types that differ between LLP64 and LP64 architectures - in LLP64,
235
+ * pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
236
+ * to be the only LLP64 architecture in current use.
237
+ */
238
+ #ifdef _WIN64
239
+ typedef signed long long int khronos_intptr_t;
240
+ typedef unsigned long long int khronos_uintptr_t;
241
+ typedef signed long long int khronos_ssize_t;
242
+ typedef unsigned long long int khronos_usize_t;
243
+ #else
244
+ typedef signed long int khronos_intptr_t;
245
+ typedef unsigned long int khronos_uintptr_t;
246
+ typedef signed long int khronos_ssize_t;
247
+ typedef unsigned long int khronos_usize_t;
248
+ #endif
249
+
250
+ #if KHRONOS_SUPPORT_FLOAT
251
+ /*
252
+ * Float type
253
+ */
254
+ typedef float khronos_float_t;
255
+ #endif
256
+
257
+ #if KHRONOS_SUPPORT_INT64
258
+ /* Time types
259
+ *
260
+ * These types can be used to represent a time interval in nanoseconds or
261
+ * an absolute Unadjusted System Time. Unadjusted System Time is the number
262
+ * of nanoseconds since some arbitrary system event (e.g. since the last
263
+ * time the system booted). The Unadjusted System Time is an unsigned
264
+ * 64 bit value that wraps back to 0 every 584 years. Time intervals
265
+ * may be either signed or unsigned.
266
+ */
267
+ typedef khronos_uint64_t khronos_utime_nanoseconds_t;
268
+ typedef khronos_int64_t khronos_stime_nanoseconds_t;
269
+ #endif
270
+
271
+ /*
272
+ * Dummy value used to pad enum types to 32 bits.
273
+ */
274
+ #ifndef KHRONOS_MAX_ENUM
275
+ #define KHRONOS_MAX_ENUM 0x7FFFFFFF
276
+ #endif
277
+
278
+ /*
279
+ * Enumerated boolean type
280
+ *
281
+ * Values other than zero should be considered to be true. Therefore
282
+ * comparisons should not be made against KHRONOS_TRUE.
283
+ */
284
+ typedef enum {
285
+ KHRONOS_FALSE = 0,
286
+ KHRONOS_TRUE = 1,
287
+ KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
288
+ } khronos_boolean_enum_t;
289
+
290
+ #endif /* __khrplatform_h_ */
@@ -0,0 +1,279 @@
1
+ #include "game.h"
2
+
3
+ VALUE rb_cMat4;
4
+ VALUE rb_cMat3; // TODO
5
+
6
+ CREATE_ALLOC_FUNC(mat4, RGSS_MAT4_ALIGN, RGSS_MAT4_SIZE)
7
+
8
+ static VALUE mat4_get(int argc, VALUE *argv, VALUE self)
9
+ {
10
+ VALUE x, y;
11
+ rb_scan_args(argc, argv, "11", &x, &y);
12
+
13
+
14
+ return Qnil;
15
+ }
16
+
17
+ static VALUE mat4_set(int argc, VALUE *argv, VALUE self)
18
+ {
19
+
20
+
21
+ return self;
22
+ }
23
+
24
+ static VALUE mat4_rows(VALUE self)
25
+ {
26
+ float *mat = DATA_PTR(self);
27
+
28
+ VALUE ary = rb_ary_new_capa(4);
29
+ for (long i = 0; i < 4; i++)
30
+ {
31
+ float *v = RGSS_VEC4_NEW;
32
+ glm_vec4_copy(&mat[i * 4], v);
33
+ rb_ary_store(ary, i, VEC4_WRAP(v));
34
+ }
35
+ return ary;
36
+ }
37
+
38
+ static VALUE mat4_columns(VALUE self)
39
+ {
40
+ float *mat = DATA_PTR(self);
41
+
42
+ VALUE ary = rb_ary_new_capa(4);
43
+ for (long i = 0; i < 4; i++)
44
+ {
45
+ rb_ary_store(ary, i, RGSS_Vec4_New(
46
+ mat[i + 0],
47
+ mat[i + 4],
48
+ mat[i + 8],
49
+ mat[i + 12]
50
+ ));
51
+ }
52
+ return ary;
53
+ }
54
+
55
+ static VALUE mat4_zero(VALUE klass)
56
+ {
57
+ vec4 *mat = RGSS_MAT4_NEW;
58
+ glm_mat4_zero(mat);
59
+ return MAT4_WRAP(mat);
60
+ }
61
+
62
+ static VALUE mat4_identity(VALUE klass)
63
+ {
64
+ vec4 *mat = RGSS_MAT4_NEW;
65
+ glm_mat4_identity(mat);
66
+ return MAT4_WRAP(mat);
67
+ }
68
+
69
+ static VALUE mat4_initialize(VALUE self, VALUE r1, VALUE r2, VALUE r3, VALUE r4)
70
+ {
71
+ float *mat = DATA_PTR(self);
72
+
73
+ glm_vec4_copy(DATA_PTR(r1), &mat[0]);
74
+ glm_vec4_copy(DATA_PTR(r2), &mat[4]);
75
+ glm_vec4_copy(DATA_PTR(r3), &mat[8]);
76
+ glm_vec4_copy(DATA_PTR(r4), &mat[12]);
77
+
78
+ return Qnil;
79
+ }
80
+
81
+ static VALUE mat4_copy(VALUE self)
82
+ {
83
+ vec4 *d = RGSS_MAT4_NEW;
84
+ glm_mat4_copy(DATA_PTR(self), d);
85
+ return MAT4_WRAP(d);
86
+ }
87
+
88
+ static VALUE mat4_multiply(VALUE self, VALUE other)
89
+ {
90
+
91
+ if (CLASS_OF(other) == rb_cMat4)
92
+ {
93
+ vec4 *dest = RGSS_MAT4_NEW;
94
+ glm_mat4_mul(DATA_PTR(self), DATA_PTR(other), dest);
95
+ return MAT4_WRAP(dest);
96
+ }
97
+ else if (CLASS_OF(other) == rb_cVec4)
98
+ {
99
+ float *v = RGSS_VEC4_NEW;
100
+ glm_mat4_mulv(DATA_PTR(self), DATA_PTR(other), v);
101
+ return VEC4_WRAP(v);
102
+ }
103
+
104
+ rb_raise(rb_eTypeError, "%s is not a Mat4 or Vec4", CLASS_NAME(other));
105
+ }
106
+
107
+ static VALUE mat4_test(VALUE self, VALUE position, VALUE angle, VALUE pivot, VALUE scale, VALUE velocity, VALUE size, VALUE delta)
108
+ {
109
+ vec3 axis = { 0.0f, 0.0f, 1.0f };
110
+
111
+ vec4 *mat = DATA_PTR(self);
112
+ float *pos = DATA_PTR(position);
113
+ float radians = NUM2FLT(angle);
114
+ float *piv = DATA_PTR(pivot);
115
+ float *vel = DATA_PTR(velocity);
116
+
117
+ // # @model.create_rotation!(@pivot + @position, @angle, AXIS)
118
+ // # @model.translate!(@position)
119
+ // # @model.scale!(@scale * @size)
120
+
121
+ vec3 zoom;
122
+ glm_vec3_mul(DATA_PTR(scale), DATA_PTR(size), zoom);
123
+
124
+ vec3 speed;
125
+ glm_vec3_scale(vel, NUM2FLT(delta), speed);
126
+ glm_vec3_add(pos, speed, pos);
127
+
128
+
129
+ vec3 point;
130
+ glm_vec3_add(piv, pos, point);
131
+
132
+ glm_rotate_atm(mat, point, radians, axis);
133
+ glm_translate(mat, pos);
134
+ glm_scale(mat, zoom);
135
+
136
+
137
+
138
+
139
+
140
+
141
+ return self;
142
+
143
+ }
144
+
145
+ static VALUE mat4_rotate(VALUE self, VALUE pivot, VALUE angle, VALUE axis)
146
+ {
147
+ vec4 *mat = DATA_PTR(self);
148
+ vec4 *dst = RGSS_MAT4_NEW;
149
+ glm_mat4_copy(mat, dst);
150
+
151
+ float *p = DATA_PTR(pivot);
152
+ float *a = DATA_PTR(axis);
153
+ glm_rotate_at(dst, p, NUM2FLT(angle), a);
154
+ return MAT4_WRAP(dst);
155
+ }
156
+
157
+ static VALUE mat4_rotate_bang(VALUE self, VALUE pivot, VALUE angle, VALUE axis)
158
+ {
159
+ vec4 *mat = DATA_PTR(self);
160
+ float *p = DATA_PTR(pivot);
161
+ float *a = DATA_PTR(axis);
162
+ glm_rotate_at(mat, p, NUM2FLT(angle), a);
163
+ return self;
164
+ }
165
+
166
+ static VALUE mat4_create_rotation(VALUE self, VALUE pivot, VALUE angle, VALUE axis)
167
+ {
168
+ vec4 *mat = DATA_PTR(self);
169
+ vec4 *dst = RGSS_MAT4_NEW;
170
+ glm_mat4_copy(mat, dst);
171
+
172
+ float *p = DATA_PTR(pivot);
173
+ float *a = DATA_PTR(axis);
174
+ glm_rotate_atm(dst, p, NUM2FLT(angle), a);
175
+ return MAT4_WRAP(dst);
176
+ }
177
+
178
+ static VALUE mat4_create_rotation_bang(VALUE self, VALUE pivot, VALUE angle, VALUE axis)
179
+ {
180
+ vec4 *mat = DATA_PTR(self);
181
+ float *p = DATA_PTR(pivot);
182
+ float *a = DATA_PTR(axis);
183
+ glm_rotate_atm(mat, p, NUM2FLT(angle), a);
184
+ return self;
185
+ }
186
+
187
+ static VALUE mat4_scale(VALUE self, VALUE scale)
188
+ {
189
+ vec4 *mat = DATA_PTR(self);
190
+ vec4 *dst = RGSS_MAT4_NEW;
191
+ float *vec = DATA_PTR(scale);
192
+
193
+ glm_scale_to(mat, vec, dst);
194
+ return MAT4_WRAP(dst);
195
+ }
196
+
197
+ static VALUE mat4_scale_bang(VALUE self, VALUE scale)
198
+ {
199
+ vec4 *mat = DATA_PTR(self);
200
+ float *vec = DATA_PTR(scale);
201
+ glm_scale(mat, vec);
202
+ return self;
203
+ }
204
+
205
+ static VALUE mat4_translate(VALUE self, VALUE translation)
206
+ {
207
+ vec4 *mat = DATA_PTR(self);
208
+ vec4 *dst = RGSS_MAT4_NEW;
209
+ float *vec = DATA_PTR(translation);
210
+ glm_translate_to(mat, vec, dst);
211
+ return MAT4_WRAP(dst);
212
+ }
213
+
214
+ static VALUE mat4_translate_bang(VALUE self, VALUE translation)
215
+ {
216
+ vec4 *mat = DATA_PTR(self);
217
+ float *vec = DATA_PTR(translation);
218
+ glm_translate(mat, vec);
219
+ return self;
220
+ }
221
+
222
+ static VALUE mat4_inspect(VALUE self)
223
+ {
224
+ float *mat = DATA_PTR(self);
225
+ return rb_sprintf("[<%f, %f, %f, %f>, <%f, %f, %f, %f>, <%f, %f, %f, %f>, <%f, %f, %f, %f>]",
226
+ mat[0], mat[1], mat[2], mat[3],
227
+ mat[4], mat[5], mat[6], mat[7],
228
+ mat[8], mat[9], mat[10], mat[11],
229
+ mat[12], mat[13], mat[14], mat[15]
230
+ );
231
+ }
232
+
233
+ static VALUE mat4_ortho(VALUE klass, VALUE left, VALUE right, VALUE top, VALUE bottom, VALUE near, VALUE far)
234
+ {
235
+ vec4 *mat = RGSS_MAT4_NEW;
236
+ glm_ortho(NUM2FLT(left), NUM2FLT(right), NUM2FLT(top), NUM2FLT(bottom), NUM2FLT(near), NUM2FLT(far), mat);
237
+ return Data_Wrap_Struct(klass, NULL, free, mat);
238
+ }
239
+
240
+ static VALUE mat4_lookat(VALUE klass, VALUE eye, VALUE center, VALUE up)
241
+ {
242
+ vec4 *mat = RGSS_MAT4_NEW;
243
+ glm_lookat(DATA_PTR(eye), DATA_PTR(center), DATA_PTR(up), mat);
244
+ return Data_Wrap_Struct(klass, NULL, free, mat);
245
+ }
246
+
247
+ void RGSS_Init_Mat4(VALUE parent)
248
+ {
249
+ rb_cMat4 = rb_define_class_under(parent, "Mat3", rb_cObject); // TODO
250
+ rb_cMat4 = rb_define_class_under(parent, "Mat4", rb_cObject);
251
+ rb_define_alloc_func(rb_cMat4, mat4_alloc);
252
+
253
+ rb_define_methodm1(rb_cMat4, "[]", mat4_get, -1);
254
+ rb_define_methodm1(rb_cMat4, "[]=", mat4_set, -1);
255
+
256
+ rb_define_method7(rb_cMat4, "test!", mat4_test, 7);
257
+
258
+ rb_define_method4(rb_cMat4, "initialize", mat4_initialize, 4);
259
+ rb_define_method0(rb_cMat4, "inspect", mat4_inspect, 0);
260
+ rb_define_method0(rb_cMat4, "rows", mat4_rows, 0);
261
+ rb_define_method0(rb_cMat4, "columns", mat4_columns, 0);
262
+ rb_define_method0(rb_cMat4, "copy", mat4_copy, 0);
263
+
264
+ rb_define_method3(rb_cMat4, "rotate", mat4_rotate, 3);
265
+ rb_define_method3(rb_cMat4, "rotate!", mat4_rotate_bang, 3);
266
+ rb_define_method3(rb_cMat4, "create_rotation", mat4_create_rotation, 3);
267
+ rb_define_method3(rb_cMat4, "create_rotation!", mat4_create_rotation_bang, 3);
268
+ rb_define_method1(rb_cMat4, "scale", mat4_scale, 1);
269
+ rb_define_method1(rb_cMat4, "scale!", mat4_scale_bang, 1);
270
+ rb_define_method1(rb_cMat4, "translate", mat4_translate, 1);
271
+ rb_define_method1(rb_cMat4, "translate!", mat4_translate_bang, 1);
272
+
273
+ rb_define_alias(rb_cMat4, "dup", "copy");
274
+
275
+ rb_define_singleton_method6(rb_cMat4, "ortho", mat4_ortho, 6);
276
+ rb_define_singleton_method3(rb_cMat4, "lookat", mat4_lookat, 3);
277
+ rb_define_singleton_method0(rb_cMat4, "identity", mat4_identity, 0);
278
+ rb_define_singleton_method0(rb_cMat4, "zero", mat4_zero, 0);
279
+ }