snow-math 1.7.0 → 1.7.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/ext/snow-math/mat3.c +38 -37
- data/ext/snow-math/mat4.c +36 -34
- data/ext/snow-math/snow-math.c +2 -2
- data/lib/snow-math/quat.rb +22 -0
- data/lib/snow-math/swizzle.rb +0 -1
- data/lib/snow-math/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 142f6e19b8c998b9745f575ed0c8d2b0ea798d23
|
4
|
+
data.tar.gz: 81c3a701da5050c2a48d41e7e8231d785d3e9808
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 600813616e652545b881ba308b2bacfd4e508a26b540465463b24dea6560715eb935c3f285dcf0e6bea57e276be3d113af79bb9f8c0030fb18cbbf3245519243
|
7
|
+
data.tar.gz: be637a1bd6f32da28ca8b1c8ba9830c26f838d68c98729116c40ae44fde87d70e316fc3f8d134b7973ad749ec028c465804764f9d489a97fd3fbc7a65c6f9dc9
|
data/ext/snow-math/mat3.c
CHANGED
@@ -121,50 +121,51 @@ void mat3_rotation(s_float_t angle, s_float_t x, s_float_t y, s_float_t z, mat3_
|
|
121
121
|
const s_float_t xs = s * x;
|
122
122
|
const s_float_t ys = s * y;
|
123
123
|
const s_float_t zs = s * z;
|
124
|
+
const s_float_t xx = x * x;
|
125
|
+
const s_float_t yy = y * y;
|
126
|
+
const s_float_t zz = z * z;
|
124
127
|
|
125
|
-
out[0] =
|
126
|
-
out[1] = xy
|
127
|
-
out[2] =
|
128
|
-
|
129
|
-
out[
|
130
|
-
out[
|
131
|
-
out[
|
132
|
-
|
133
|
-
out[
|
128
|
+
out[0] = xx + c * (s_float_lit(1.0) - xx);
|
129
|
+
out[1] = xy * ic - zs;
|
130
|
+
out[2] = z * x * ic + ys;
|
131
|
+
|
132
|
+
out[3] = xy * ic + zs;
|
133
|
+
out[4] = yy + c * (s_float_lit(1.0) - yy);
|
134
|
+
out[5] = yz * ic - xs;
|
135
|
+
|
136
|
+
out[6] = xz * ic - ys;
|
137
|
+
out[7] = yz * ic + xs;
|
138
|
+
out[8] = zz + c * (s_float_lit(1.0) - zz);
|
134
139
|
}
|
135
140
|
|
136
141
|
|
137
142
|
|
138
143
|
void mat3_from_quat(const quat_t in, mat3_t out)
|
139
144
|
{
|
140
|
-
s_float_t
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
out[
|
160
|
-
out[
|
161
|
-
out[
|
162
|
-
out[
|
163
|
-
out[
|
164
|
-
out[5] = yz - wx;
|
165
|
-
out[6] = xz - wy;
|
166
|
-
out[7] = yz + wx;
|
167
|
-
out[8] = s_float_lit(1.0) - (xx + yy);
|
145
|
+
s_float_t xx, xy, xz, yy, yz, zz, wx, wy, wz;
|
146
|
+
|
147
|
+
xx = in[0] * in[0];
|
148
|
+
xy = in[0] * in[1];
|
149
|
+
xz = in[0] * in[2];
|
150
|
+
|
151
|
+
yy = in[1] * in[1];
|
152
|
+
yz = in[2] * in[2];
|
153
|
+
|
154
|
+
zz = in[2] * in[2];
|
155
|
+
|
156
|
+
wx = in[0] * in[3];
|
157
|
+
wy = in[1] * in[3];
|
158
|
+
wz = in[2] * in[3];
|
159
|
+
|
160
|
+
out[0] = s_float_lit(1.0) - s_float_lit(2.0) * (yy + zz);
|
161
|
+
out[1] = s_float_lit(2.0) * (xy - wz);
|
162
|
+
out[2] = s_float_lit(2.0) * (xz + wy);
|
163
|
+
out[3] = s_float_lit(2.0) * (xy + wz);
|
164
|
+
out[4] = s_float_lit(1.0) - s_float_lit(2.0) * (xx + zz);
|
165
|
+
out[5] = s_float_lit(2.0) * (yz - wx);
|
166
|
+
out[6] = s_float_lit(2.0) * (xz - wy);
|
167
|
+
out[7] = s_float_lit(2.0) * (yz + wx);
|
168
|
+
out[8] = s_float_lit(1.0) - s_float_lit(2.0) * (xx + yy);
|
168
169
|
}
|
169
170
|
|
170
171
|
|
data/ext/snow-math/mat4.c
CHANGED
@@ -206,8 +206,8 @@ void mat4_get_axes4(const mat4_t m, vec4_t x, vec4_t y, vec4_t z, vec4_t w)
|
|
206
206
|
void mat4_rotation(s_float_t angle, s_float_t x, s_float_t y, s_float_t z, mat4_t out)
|
207
207
|
{
|
208
208
|
const s_float_t angle_rad = angle * S_DEG2RAD;
|
209
|
-
const s_float_t c
|
210
|
-
const s_float_t s
|
209
|
+
const s_float_t c = s_cos(angle_rad);
|
210
|
+
const s_float_t s = s_sin(angle_rad);
|
211
211
|
const s_float_t ic = s_float_lit(1.0) - c;
|
212
212
|
const s_float_t xy = x * y * ic;
|
213
213
|
const s_float_t yz = y * z * ic;
|
@@ -215,16 +215,22 @@ void mat4_rotation(s_float_t angle, s_float_t x, s_float_t y, s_float_t z, mat4_
|
|
215
215
|
const s_float_t xs = s * x;
|
216
216
|
const s_float_t ys = s * y;
|
217
217
|
const s_float_t zs = s * z;
|
218
|
+
const s_float_t xx = x * x;
|
219
|
+
const s_float_t yy = y * y;
|
220
|
+
const s_float_t zz = z * z;
|
221
|
+
|
222
|
+
out[0] = xx + c * (s_float_lit(1.0) - xx);
|
223
|
+
out[1] = xy * ic - zs;
|
224
|
+
out[2] = z * x * ic + ys;
|
225
|
+
|
226
|
+
out[4] = xy * ic + zs;
|
227
|
+
out[5] = yy + c * (s_float_lit(1.0) - yy);
|
228
|
+
out[6] = yz * ic - xs;
|
229
|
+
|
230
|
+
out[8] = xz * ic - ys;
|
231
|
+
out[9] = yz * ic + xs;
|
232
|
+
out[10] = zz + c * (s_float_lit(1.0) - zz);
|
218
233
|
|
219
|
-
out[0] = ((x * x) * ic) + c;
|
220
|
-
out[1] = xy + zs;
|
221
|
-
out[2] = xz - ys;
|
222
|
-
out[4] = xy - zs;
|
223
|
-
out[5] = ((y * y) * ic) + c;
|
224
|
-
out[6] = yz + xs;
|
225
|
-
out[8] = xz + ys;
|
226
|
-
out[9] = yz - xs;
|
227
|
-
out[10] = ((z * z) * ic) + c;
|
228
234
|
out[3] = out[7] = out[11] =
|
229
235
|
out[12] = out[13] = out[14] = s_float_lit(0.0);
|
230
236
|
out[15] = s_float_lit(1.0);
|
@@ -309,34 +315,30 @@ void mat4_look_at(const vec3_t eye, const vec3_t center, const vec3_t up, mat4_t
|
|
309
315
|
|
310
316
|
void mat4_from_quat(const quat_t quat, mat4_t out)
|
311
317
|
{
|
312
|
-
s_float_t
|
313
|
-
|
314
|
-
tx = s_float_lit(2.0) * quat[0];
|
315
|
-
ty = s_float_lit(2.0) * quat[1];
|
316
|
-
tz = s_float_lit(2.0) * quat[2];
|
318
|
+
s_float_t xx, xy, xz, yy, yz, zz, wx, wy, wz;
|
317
319
|
|
318
|
-
xx =
|
319
|
-
xy =
|
320
|
-
xz =
|
320
|
+
xx = quat[0] * quat[0];
|
321
|
+
xy = quat[0] * quat[1];
|
322
|
+
xz = quat[0] * quat[2];
|
321
323
|
|
322
|
-
yy =
|
323
|
-
yz =
|
324
|
+
yy = quat[1] * quat[1];
|
325
|
+
yz = quat[2] * quat[2];
|
324
326
|
|
325
|
-
zz =
|
327
|
+
zz = quat[2] * quat[2];
|
326
328
|
|
327
|
-
wx =
|
328
|
-
wy =
|
329
|
-
wz =
|
329
|
+
wx = quat[0] * quat[3];
|
330
|
+
wy = quat[1] * quat[3];
|
331
|
+
wz = quat[2] * quat[3];
|
330
332
|
|
331
|
-
out[0 ] = s_float_lit(1.0) - (yy + zz);
|
332
|
-
out[1 ] = xy - wz;
|
333
|
-
out[2 ] = xz + wy;
|
334
|
-
out[4 ] = xy + wz;
|
335
|
-
out[5 ] = s_float_lit(1.0) - (xx + zz);
|
336
|
-
out[6 ] = yz - wx;
|
337
|
-
out[8 ] = xz - wy;
|
338
|
-
out[9 ] = yz + wx;
|
339
|
-
out[10] = s_float_lit(1.0) - (xx + yy);
|
333
|
+
out[0 ] = s_float_lit(1.0) - s_float_lit(2.0) * (yy + zz);
|
334
|
+
out[1 ] = s_float_lit(2.0) * (xy - wz);
|
335
|
+
out[2 ] = s_float_lit(2.0) * (xz + wy);
|
336
|
+
out[4 ] = s_float_lit(2.0) * (xy + wz);
|
337
|
+
out[5 ] = s_float_lit(1.0) - s_float_lit(2.0) * (xx + zz);
|
338
|
+
out[6 ] = s_float_lit(2.0) * (yz - wx);
|
339
|
+
out[8 ] = s_float_lit(2.0) * (xz - wy);
|
340
|
+
out[9 ] = s_float_lit(2.0) * (yz + wx);
|
341
|
+
out[10] = s_float_lit(1.0) - s_float_lit(2.0) * (xx + yy);
|
340
342
|
|
341
343
|
out[7 ] = s_float_lit(0.0);
|
342
344
|
out[3 ] = s_float_lit(0.0);
|
data/ext/snow-math/snow-math.c
CHANGED
@@ -4346,7 +4346,7 @@ static VALUE sm_mat4_to_mat3(int argc, VALUE *argv, VALUE sm_self)
|
|
4346
4346
|
SM_LABEL(skip_output): {
|
4347
4347
|
mat3_t output;
|
4348
4348
|
mat4_to_mat3 (*self, output);
|
4349
|
-
sm_out = sm_wrap_mat3(output,
|
4349
|
+
sm_out = sm_wrap_mat3(output, s_sm_mat3_klass);
|
4350
4350
|
rb_obj_call_init(sm_out, 0, 0);
|
4351
4351
|
}} else {
|
4352
4352
|
rb_raise(rb_eArgError, "Invalid number of arguments to to_mat3");
|
@@ -5914,7 +5914,7 @@ static VALUE sm_mat3_to_mat4(int argc, VALUE *argv, VALUE sm_self)
|
|
5914
5914
|
SM_LABEL(skip_output): {
|
5915
5915
|
mat4_t output;
|
5916
5916
|
mat3_to_mat4 (*self, output);
|
5917
|
-
sm_out = sm_wrap_mat4(output,
|
5917
|
+
sm_out = sm_wrap_mat4(output, s_sm_mat4_klass);
|
5918
5918
|
rb_obj_call_init(sm_out, 0, 0);
|
5919
5919
|
}} else {
|
5920
5920
|
rb_raise(rb_eArgError, "Invalid number of arguments to to_mat4");
|
data/lib/snow-math/quat.rb
CHANGED
@@ -222,6 +222,28 @@ class Snow::Quat
|
|
222
222
|
slerp(destination, alpha, self)
|
223
223
|
end
|
224
224
|
|
225
|
+
def pitch
|
226
|
+
x, y, z, w = self[0], self[1], self[2], self[3]
|
227
|
+
tx = 2.0 * (x * z - w * y)
|
228
|
+
ty = 2.0 * (y * z + w * x)
|
229
|
+
tz = 1.0 - 2.0 * (x * x + y * y)
|
230
|
+
Math::atan2(ty, Math::sqrt(tx * tx - tz * tz)) * Snow::RADIANS_TO_DEGREES
|
231
|
+
end
|
232
|
+
|
233
|
+
def yaw
|
234
|
+
x, y, z, w = self[0], self[1], self[2], self[3]
|
235
|
+
tx = 2.0 * (x * z - w * y)
|
236
|
+
tz = 1.0 - 2.0 * (x * x + y * y)
|
237
|
+
-Math::atan2(tx, tz) * Snow::RADIANS_TO_DEGREES
|
238
|
+
end
|
239
|
+
|
240
|
+
def roll
|
241
|
+
x, y, z, w = self[0], self[1], self[2], self[3]
|
242
|
+
txy = 2.0 * (x * y - w * z)
|
243
|
+
tyy = 1.0 - 2.0 * (x * x + z * z)
|
244
|
+
Math::atan2(txy, tyy) * Snow::RADIANS_TO_DEGREES
|
245
|
+
end
|
246
|
+
|
225
247
|
|
226
248
|
alias_method :-, :subtract
|
227
249
|
alias_method :+, :add
|
data/lib/snow-math/swizzle.rb
CHANGED
data/lib/snow-math/version.rb
CHANGED