larb 0.1.0 → 1.0.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/README.md +63 -1
- data/ext/larb/color.c +449 -0
- data/ext/larb/color.h +35 -0
- data/ext/larb/extconf.rb +11 -0
- data/ext/larb/larb.c +27 -0
- data/ext/larb/larb.h +31 -0
- data/ext/larb/mat2.c +303 -0
- data/ext/larb/mat2.h +30 -0
- data/ext/larb/mat2d.c +397 -0
- data/ext/larb/mat2d.h +35 -0
- data/ext/larb/mat3.c +455 -0
- data/ext/larb/mat3.h +33 -0
- data/ext/larb/mat4.c +651 -0
- data/ext/larb/mat4.h +31 -0
- data/ext/larb/matrix_utils.h +97 -0
- data/ext/larb/quat.c +567 -0
- data/ext/larb/quat.h +39 -0
- data/ext/larb/quat2.c +511 -0
- data/ext/larb/quat2.h +39 -0
- data/ext/larb/vec2.c +365 -0
- data/ext/larb/vec2.h +43 -0
- data/ext/larb/vec3.c +538 -0
- data/ext/larb/vec3.h +52 -0
- data/ext/larb/vec4.c +361 -0
- data/ext/larb/vec4.h +38 -0
- data/lib/larb/version.rb +5 -0
- data/lib/larb.rb +2 -14
- data/test/larb/color_test.rb +299 -0
- data/test/larb/mat2_test.rb +144 -0
- data/test/larb/mat2d_test.rb +197 -0
- data/test/larb/mat3_test.rb +147 -0
- data/test/larb/mat4_test.rb +347 -0
- data/test/larb/matrix_test.rb +135 -0
- data/test/larb/native_value_test.rb +157 -0
- data/test/larb/quat2_test.rb +254 -0
- data/test/larb/quat_test.rb +284 -0
- data/test/larb/vec2_test.rb +274 -0
- data/test/larb/vec3_test.rb +373 -0
- data/test/larb/vec4_test.rb +196 -0
- data/test/test_helper.rb +4 -0
- metadata +60 -18
- data/Rakefile +0 -11
- data/lib/larb/color.rb +0 -148
- data/lib/larb/mat2.rb +0 -119
- data/lib/larb/mat2d.rb +0 -180
- data/lib/larb/mat3.rb +0 -238
- data/lib/larb/mat4.rb +0 -329
- data/lib/larb/quat.rb +0 -238
- data/lib/larb/quat2.rb +0 -193
- data/lib/larb/vec2.rb +0 -150
- data/lib/larb/vec3.rb +0 -218
- data/lib/larb/vec4.rb +0 -125
data/ext/larb/vec4.c
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
#include "vec4.h"
|
|
2
|
+
|
|
3
|
+
#include <math.h>
|
|
4
|
+
|
|
5
|
+
static void vec4_free(void *ptr) {
|
|
6
|
+
xfree(ptr);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static size_t vec4_memsize(const void *ptr) {
|
|
10
|
+
return sizeof(Vec4Data);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static const rb_data_type_t vec4_type = {
|
|
14
|
+
"Vec4",
|
|
15
|
+
{0, vec4_free, vec4_memsize},
|
|
16
|
+
0,
|
|
17
|
+
0,
|
|
18
|
+
RUBY_TYPED_FREE_IMMEDIATELY,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
static VALUE cVec4 = Qnil;
|
|
22
|
+
|
|
23
|
+
static Vec4Data *vec4_get(VALUE obj) {
|
|
24
|
+
Vec4Data *data = NULL;
|
|
25
|
+
TypedData_Get_Struct(obj, Vec4Data, &vec4_type, data);
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static VALUE vec4_build(VALUE klass, double x, double y, double z, double w) {
|
|
30
|
+
VALUE obj = vec4_alloc(klass);
|
|
31
|
+
Vec4Data *data = vec4_get(obj);
|
|
32
|
+
data->x = x;
|
|
33
|
+
data->y = y;
|
|
34
|
+
data->z = z;
|
|
35
|
+
data->w = w;
|
|
36
|
+
return obj;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
VALUE vec4_alloc(VALUE klass) {
|
|
40
|
+
Vec4Data *data = ALLOC(Vec4Data);
|
|
41
|
+
data->x = 0.0;
|
|
42
|
+
data->y = 0.0;
|
|
43
|
+
data->z = 0.0;
|
|
44
|
+
data->w = 1.0;
|
|
45
|
+
return TypedData_Wrap_Struct(klass, &vec4_type, data);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
VALUE vec4_initialize(int argc, VALUE *argv, VALUE self) {
|
|
49
|
+
rb_check_frozen(self);
|
|
50
|
+
VALUE vx = Qnil;
|
|
51
|
+
VALUE vy = Qnil;
|
|
52
|
+
VALUE vz = Qnil;
|
|
53
|
+
VALUE vw = Qnil;
|
|
54
|
+
rb_scan_args(argc, argv, "04", &vx, &vy, &vz, &vw);
|
|
55
|
+
Vec4Data value = {
|
|
56
|
+
argc > 0 ? NUM2DBL(vx) : 0.0,
|
|
57
|
+
argc > 1 ? NUM2DBL(vy) : 0.0,
|
|
58
|
+
argc > 2 ? NUM2DBL(vz) : 0.0,
|
|
59
|
+
argc > 3 ? NUM2DBL(vw) : 1.0
|
|
60
|
+
};
|
|
61
|
+
rb_check_frozen(self);
|
|
62
|
+
*vec4_get(self) = value;
|
|
63
|
+
return self;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static VALUE vec4_class_bracket(int argc, VALUE *argv, VALUE klass) {
|
|
67
|
+
VALUE vx = Qnil;
|
|
68
|
+
VALUE vy = Qnil;
|
|
69
|
+
VALUE vz = Qnil;
|
|
70
|
+
VALUE vw = Qnil;
|
|
71
|
+
|
|
72
|
+
rb_scan_args(argc, argv, "31", &vx, &vy, &vz, &vw);
|
|
73
|
+
return vec4_build(klass, NUM2DBL(vx), NUM2DBL(vy),
|
|
74
|
+
NUM2DBL(vz), argc < 4 ? 1.0 : NUM2DBL(vw));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static VALUE vec4_class_zero(VALUE klass) {
|
|
78
|
+
return vec4_build(klass, 0.0, 0.0, 0.0, 0.0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static VALUE vec4_class_one(VALUE klass) {
|
|
82
|
+
return vec4_build(klass, 1.0, 1.0, 1.0, 1.0);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static VALUE vec4_get_x(VALUE self) {
|
|
86
|
+
Vec4Data *data = vec4_get(self);
|
|
87
|
+
return DBL2NUM(data->x);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static VALUE vec4_set_x(VALUE self, VALUE value) {
|
|
91
|
+
rb_check_frozen(self);
|
|
92
|
+
Vec4Data *data = vec4_get(self);
|
|
93
|
+
double component = NUM2DBL(value);
|
|
94
|
+
rb_check_frozen(self);
|
|
95
|
+
data->x = component;
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static VALUE vec4_get_y(VALUE self) {
|
|
100
|
+
Vec4Data *data = vec4_get(self);
|
|
101
|
+
return DBL2NUM(data->y);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static VALUE vec4_set_y(VALUE self, VALUE value) {
|
|
105
|
+
rb_check_frozen(self);
|
|
106
|
+
Vec4Data *data = vec4_get(self);
|
|
107
|
+
double component = NUM2DBL(value);
|
|
108
|
+
rb_check_frozen(self);
|
|
109
|
+
data->y = component;
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static VALUE vec4_get_z(VALUE self) {
|
|
114
|
+
Vec4Data *data = vec4_get(self);
|
|
115
|
+
return DBL2NUM(data->z);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static VALUE vec4_set_z(VALUE self, VALUE value) {
|
|
119
|
+
rb_check_frozen(self);
|
|
120
|
+
Vec4Data *data = vec4_get(self);
|
|
121
|
+
double component = NUM2DBL(value);
|
|
122
|
+
rb_check_frozen(self);
|
|
123
|
+
data->z = component;
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static VALUE vec4_get_w(VALUE self) {
|
|
128
|
+
Vec4Data *data = vec4_get(self);
|
|
129
|
+
return DBL2NUM(data->w);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static VALUE vec4_set_w(VALUE self, VALUE value) {
|
|
133
|
+
rb_check_frozen(self);
|
|
134
|
+
Vec4Data *data = vec4_get(self);
|
|
135
|
+
double component = NUM2DBL(value);
|
|
136
|
+
rb_check_frozen(self);
|
|
137
|
+
data->w = component;
|
|
138
|
+
return value;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
VALUE vec4_add(VALUE self, VALUE other) {
|
|
142
|
+
Vec4Data *a = vec4_get(self);
|
|
143
|
+
Vec4Data *b = vec4_get(other);
|
|
144
|
+
return vec4_build(rb_obj_class(self), a->x + b->x, a->y + b->y,
|
|
145
|
+
a->z + b->z, a->w + b->w);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
VALUE vec4_sub(VALUE self, VALUE other) {
|
|
149
|
+
Vec4Data *a = vec4_get(self);
|
|
150
|
+
Vec4Data *b = vec4_get(other);
|
|
151
|
+
return vec4_build(rb_obj_class(self), a->x - b->x, a->y - b->y,
|
|
152
|
+
a->z - b->z, a->w - b->w);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
VALUE vec4_mul(VALUE self, VALUE scalar) {
|
|
156
|
+
Vec4Data *a = vec4_get(self);
|
|
157
|
+
double s = NUM2DBL(scalar);
|
|
158
|
+
return vec4_build(rb_obj_class(self), a->x * s, a->y * s, a->z * s,
|
|
159
|
+
a->w * s);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
VALUE vec4_div(VALUE self, VALUE scalar) {
|
|
163
|
+
Vec4Data *a = vec4_get(self);
|
|
164
|
+
double s = NUM2DBL(scalar);
|
|
165
|
+
return vec4_build(rb_obj_class(self), a->x / s, a->y / s, a->z / s,
|
|
166
|
+
a->w / s);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
VALUE vec4_negate(VALUE self) {
|
|
170
|
+
Vec4Data *a = vec4_get(self);
|
|
171
|
+
return vec4_build(rb_obj_class(self), -a->x, -a->y, -a->z, -a->w);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
VALUE vec4_dot(VALUE self, VALUE other) {
|
|
175
|
+
Vec4Data *a = vec4_get(self);
|
|
176
|
+
Vec4Data *b = vec4_get(other);
|
|
177
|
+
return DBL2NUM(a->x * b->x + a->y * b->y + a->z * b->z + a->w * b->w);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
VALUE vec4_length(VALUE self) {
|
|
181
|
+
Vec4Data *a = vec4_get(self);
|
|
182
|
+
return DBL2NUM(hypot(hypot(hypot(a->x, a->y), a->z), a->w));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
VALUE vec4_length_squared(VALUE self) {
|
|
186
|
+
Vec4Data *a = vec4_get(self);
|
|
187
|
+
return DBL2NUM(a->x * a->x + a->y * a->y + a->z * a->z + a->w * a->w);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
VALUE vec4_normalize(VALUE self) {
|
|
191
|
+
Vec4Data *a = vec4_get(self);
|
|
192
|
+
double values[] = {a->x, a->y, a->z, a->w};
|
|
193
|
+
larb_normalize(values, 4);
|
|
194
|
+
return vec4_build(rb_obj_class(self), values[0], values[1], values[2], values[3]);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
VALUE vec4_normalize_bang(VALUE self) {
|
|
198
|
+
rb_check_frozen(self);
|
|
199
|
+
Vec4Data *a = vec4_get(self);
|
|
200
|
+
double values[] = {a->x, a->y, a->z, a->w};
|
|
201
|
+
larb_normalize(values, 4);
|
|
202
|
+
a->x = values[0];
|
|
203
|
+
a->y = values[1];
|
|
204
|
+
a->z = values[2];
|
|
205
|
+
a->w = values[3];
|
|
206
|
+
return self;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
VALUE vec4_perspective_divide(VALUE self) {
|
|
210
|
+
Vec4Data *a = vec4_get(self);
|
|
211
|
+
VALUE vec3_class = rb_const_get(mLarb, rb_intern("Vec3"));
|
|
212
|
+
|
|
213
|
+
if (!isfinite(a->w) || a->w == 0.0) {
|
|
214
|
+
rb_raise(rb_eArgError, "w must be finite and nonzero for perspective division");
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return rb_funcall(vec3_class, rb_intern("new"), 3, DBL2NUM(a->x / a->w),
|
|
218
|
+
DBL2NUM(a->y / a->w), DBL2NUM(a->z / a->w));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
VALUE vec4_xyz(VALUE self) {
|
|
222
|
+
Vec4Data *a = vec4_get(self);
|
|
223
|
+
VALUE vec3_class = rb_const_get(mLarb, rb_intern("Vec3"));
|
|
224
|
+
return rb_funcall(vec3_class, rb_intern("new"), 3, DBL2NUM(a->x),
|
|
225
|
+
DBL2NUM(a->y), DBL2NUM(a->z));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
VALUE vec4_xy(VALUE self) {
|
|
229
|
+
Vec4Data *a = vec4_get(self);
|
|
230
|
+
VALUE vec2_class = rb_const_get(mLarb, rb_intern("Vec2"));
|
|
231
|
+
return rb_funcall(vec2_class, rb_intern("new"), 2, DBL2NUM(a->x),
|
|
232
|
+
DBL2NUM(a->y));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
VALUE vec4_rgb(VALUE self) {
|
|
236
|
+
return vec4_xyz(self);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
VALUE vec4_to_a(VALUE self) {
|
|
240
|
+
Vec4Data *a = vec4_get(self);
|
|
241
|
+
VALUE ary = rb_ary_new_capa(4);
|
|
242
|
+
rb_ary_push(ary, DBL2NUM(a->x));
|
|
243
|
+
rb_ary_push(ary, DBL2NUM(a->y));
|
|
244
|
+
rb_ary_push(ary, DBL2NUM(a->z));
|
|
245
|
+
rb_ary_push(ary, DBL2NUM(a->w));
|
|
246
|
+
return ary;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
VALUE vec4_aref(VALUE self, VALUE index) {
|
|
250
|
+
VALUE ary = vec4_to_a(self);
|
|
251
|
+
return rb_ary_entry(ary, NUM2LONG(index));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
VALUE vec4_equal(VALUE self, VALUE other) {
|
|
255
|
+
if (!rb_obj_is_kind_of(other, cVec4)) {
|
|
256
|
+
return Qfalse;
|
|
257
|
+
}
|
|
258
|
+
Vec4Data *a = vec4_get(self);
|
|
259
|
+
Vec4Data *b = vec4_get(other);
|
|
260
|
+
return (a->x == b->x && a->y == b->y && a->z == b->z && a->w == b->w)
|
|
261
|
+
? Qtrue
|
|
262
|
+
: Qfalse;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
VALUE vec4_near(int argc, VALUE *argv, VALUE self) {
|
|
266
|
+
VALUE other = Qnil;
|
|
267
|
+
VALUE epsilon = Qnil;
|
|
268
|
+
|
|
269
|
+
rb_scan_args(argc, argv, "11", &other, &epsilon);
|
|
270
|
+
Vec4Data *a = vec4_get(self);
|
|
271
|
+
Vec4Data *b = vec4_get(other);
|
|
272
|
+
double eps = argc < 2 ? 1e-6 : NUM2DBL(epsilon);
|
|
273
|
+
if (!isfinite(eps) || eps <= 0.0) {
|
|
274
|
+
rb_raise(rb_eArgError, "epsilon must be finite and positive");
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (fabs(a->x - b->x) < eps && fabs(a->y - b->y) < eps &&
|
|
278
|
+
fabs(a->z - b->z) < eps && fabs(a->w - b->w) < eps) {
|
|
279
|
+
return Qtrue;
|
|
280
|
+
}
|
|
281
|
+
return Qfalse;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
VALUE vec4_lerp(VALUE self, VALUE other, VALUE t) {
|
|
285
|
+
Vec4Data *a = vec4_get(self);
|
|
286
|
+
Vec4Data *b = vec4_get(other);
|
|
287
|
+
double s = NUM2DBL(t);
|
|
288
|
+
return vec4_build(rb_obj_class(self), a->x + (b->x - a->x) * s,
|
|
289
|
+
a->y + (b->y - a->y) * s,
|
|
290
|
+
a->z + (b->z - a->z) * s,
|
|
291
|
+
a->w + (b->w - a->w) * s);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
VALUE vec4_inspect(VALUE self) {
|
|
295
|
+
Vec4Data *a = vec4_get(self);
|
|
296
|
+
VALUE sx = rb_funcall(DBL2NUM(a->x), rb_intern("to_s"), 0);
|
|
297
|
+
VALUE sy = rb_funcall(DBL2NUM(a->y), rb_intern("to_s"), 0);
|
|
298
|
+
VALUE sz = rb_funcall(DBL2NUM(a->z), rb_intern("to_s"), 0);
|
|
299
|
+
VALUE sw = rb_funcall(DBL2NUM(a->w), rb_intern("to_s"), 0);
|
|
300
|
+
VALUE str = rb_str_new_cstr("Vec4[");
|
|
301
|
+
rb_str_concat(str, sx);
|
|
302
|
+
rb_str_cat_cstr(str, ", ");
|
|
303
|
+
rb_str_concat(str, sy);
|
|
304
|
+
rb_str_cat_cstr(str, ", ");
|
|
305
|
+
rb_str_concat(str, sz);
|
|
306
|
+
rb_str_cat_cstr(str, ", ");
|
|
307
|
+
rb_str_concat(str, sw);
|
|
308
|
+
rb_str_cat_cstr(str, "]");
|
|
309
|
+
return str;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
static VALUE vec4_initialize_copy(VALUE self, VALUE other) {
|
|
313
|
+
if (self == other) return self;
|
|
314
|
+
rb_obj_init_copy(self, other);
|
|
315
|
+
*vec4_get(self) = *vec4_get(other);
|
|
316
|
+
return self;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
void Init_vec4(VALUE module) {
|
|
320
|
+
cVec4 = rb_define_class_under(module, "Vec4", rb_cObject);
|
|
321
|
+
|
|
322
|
+
rb_define_alloc_func(cVec4, vec4_alloc);
|
|
323
|
+
rb_define_method(cVec4, "initialize", vec4_initialize, -1);
|
|
324
|
+
rb_define_method(cVec4, "initialize_copy", vec4_initialize_copy, 1);
|
|
325
|
+
|
|
326
|
+
rb_define_singleton_method(cVec4, "[]", vec4_class_bracket, -1);
|
|
327
|
+
rb_define_singleton_method(cVec4, "zero", vec4_class_zero, 0);
|
|
328
|
+
rb_define_singleton_method(cVec4, "one", vec4_class_one, 0);
|
|
329
|
+
|
|
330
|
+
rb_define_method(cVec4, "x", vec4_get_x, 0);
|
|
331
|
+
rb_define_method(cVec4, "x=", vec4_set_x, 1);
|
|
332
|
+
rb_define_method(cVec4, "y", vec4_get_y, 0);
|
|
333
|
+
rb_define_method(cVec4, "y=", vec4_set_y, 1);
|
|
334
|
+
rb_define_method(cVec4, "z", vec4_get_z, 0);
|
|
335
|
+
rb_define_method(cVec4, "z=", vec4_set_z, 1);
|
|
336
|
+
rb_define_method(cVec4, "w", vec4_get_w, 0);
|
|
337
|
+
rb_define_method(cVec4, "w=", vec4_set_w, 1);
|
|
338
|
+
|
|
339
|
+
rb_define_method(cVec4, "+", vec4_add, 1);
|
|
340
|
+
rb_define_method(cVec4, "-", vec4_sub, 1);
|
|
341
|
+
rb_define_method(cVec4, "*", vec4_mul, 1);
|
|
342
|
+
rb_define_method(cVec4, "/", vec4_div, 1);
|
|
343
|
+
rb_define_method(cVec4, "-@", vec4_negate, 0);
|
|
344
|
+
|
|
345
|
+
rb_define_method(cVec4, "dot", vec4_dot, 1);
|
|
346
|
+
rb_define_method(cVec4, "length", vec4_length, 0);
|
|
347
|
+
rb_define_method(cVec4, "length_squared", vec4_length_squared, 0);
|
|
348
|
+
rb_define_method(cVec4, "normalize", vec4_normalize, 0);
|
|
349
|
+
rb_define_method(cVec4, "normalize!", vec4_normalize_bang, 0);
|
|
350
|
+
rb_define_method(cVec4, "perspective_divide", vec4_perspective_divide, 0);
|
|
351
|
+
rb_define_method(cVec4, "xyz", vec4_xyz, 0);
|
|
352
|
+
rb_define_method(cVec4, "xy", vec4_xy, 0);
|
|
353
|
+
rb_define_method(cVec4, "rgb", vec4_rgb, 0);
|
|
354
|
+
rb_define_method(cVec4, "to_a", vec4_to_a, 0);
|
|
355
|
+
rb_define_method(cVec4, "[]", vec4_aref, 1);
|
|
356
|
+
rb_define_method(cVec4, "==", vec4_equal, 1);
|
|
357
|
+
rb_define_method(cVec4, "near?", vec4_near, -1);
|
|
358
|
+
rb_define_method(cVec4, "lerp", vec4_lerp, 2);
|
|
359
|
+
rb_define_method(cVec4, "inspect", vec4_inspect, 0);
|
|
360
|
+
rb_define_alias(cVec4, "to_s", "inspect");
|
|
361
|
+
}
|
data/ext/larb/vec4.h
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#ifndef VEC4_H
|
|
2
|
+
#define VEC4_H
|
|
3
|
+
|
|
4
|
+
#include "larb.h"
|
|
5
|
+
|
|
6
|
+
typedef struct {
|
|
7
|
+
double x;
|
|
8
|
+
double y;
|
|
9
|
+
double z;
|
|
10
|
+
double w;
|
|
11
|
+
} Vec4Data;
|
|
12
|
+
|
|
13
|
+
void Init_vec4(VALUE module);
|
|
14
|
+
VALUE vec4_alloc(VALUE klass);
|
|
15
|
+
VALUE vec4_initialize(int argc, VALUE *argv, VALUE self);
|
|
16
|
+
|
|
17
|
+
VALUE vec4_add(VALUE self, VALUE other);
|
|
18
|
+
VALUE vec4_sub(VALUE self, VALUE other);
|
|
19
|
+
VALUE vec4_mul(VALUE self, VALUE scalar);
|
|
20
|
+
VALUE vec4_div(VALUE self, VALUE scalar);
|
|
21
|
+
VALUE vec4_negate(VALUE self);
|
|
22
|
+
VALUE vec4_dot(VALUE self, VALUE other);
|
|
23
|
+
VALUE vec4_length(VALUE self);
|
|
24
|
+
VALUE vec4_length_squared(VALUE self);
|
|
25
|
+
VALUE vec4_normalize(VALUE self);
|
|
26
|
+
VALUE vec4_normalize_bang(VALUE self);
|
|
27
|
+
VALUE vec4_perspective_divide(VALUE self);
|
|
28
|
+
VALUE vec4_xyz(VALUE self);
|
|
29
|
+
VALUE vec4_xy(VALUE self);
|
|
30
|
+
VALUE vec4_rgb(VALUE self);
|
|
31
|
+
VALUE vec4_to_a(VALUE self);
|
|
32
|
+
VALUE vec4_aref(VALUE self, VALUE index);
|
|
33
|
+
VALUE vec4_equal(VALUE self, VALUE other);
|
|
34
|
+
VALUE vec4_near(int argc, VALUE *argv, VALUE self);
|
|
35
|
+
VALUE vec4_lerp(VALUE self, VALUE other, VALUE t);
|
|
36
|
+
VALUE vec4_inspect(VALUE self);
|
|
37
|
+
|
|
38
|
+
#endif
|
data/lib/larb/version.rb
ADDED
data/lib/larb.rb
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
require_relative "larb/vec4"
|
|
6
|
-
require_relative "larb/quat"
|
|
7
|
-
require_relative "larb/quat2"
|
|
8
|
-
require_relative "larb/mat2"
|
|
9
|
-
require_relative "larb/mat2d"
|
|
10
|
-
require_relative "larb/mat3"
|
|
11
|
-
require_relative "larb/mat4"
|
|
12
|
-
require_relative "larb/color"
|
|
13
|
-
|
|
14
|
-
module Larb
|
|
15
|
-
VERSION = "0.1.0"
|
|
16
|
-
end
|
|
3
|
+
require "larb/larb"
|
|
4
|
+
require "larb/version"
|