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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07dcfa849094229689bdbf469119e52479b5034e
4
- data.tar.gz: 51702b6e75a2b89f77c257a79ca5e1b9162a763a
3
+ metadata.gz: 142f6e19b8c998b9745f575ed0c8d2b0ea798d23
4
+ data.tar.gz: 81c3a701da5050c2a48d41e7e8231d785d3e9808
5
5
  SHA512:
6
- metadata.gz: 6a625c25c0d0c193dc9cd1d76f921c6ac8e59d94da5da176418656afa924c6f7d2a9dfc8054c091736faa934a37354e5893fa1296c8bfb6905ad0b3f1ffdd562
7
- data.tar.gz: a1f15c58795706985615239610c1a673ab009a41a12df9061c3bfac81b4af5f5c00cb03c74e0eba84236b230e9dd0beef48e3bc94ecd6d8d9fe286eea7ca892f
6
+ metadata.gz: 600813616e652545b881ba308b2bacfd4e508a26b540465463b24dea6560715eb935c3f285dcf0e6bea57e276be3d113af79bb9f8c0030fb18cbbf3245519243
7
+ data.tar.gz: be637a1bd6f32da28ca8b1c8ba9830c26f838d68c98729116c40ae44fde87d70e316fc3f8d134b7973ad749ec028c465804764f9d489a97fd3fbc7a65c6f9dc9
@@ -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] = ((x * x) * ic) + c;
126
- out[1] = xy + zs;
127
- out[2] = xz - ys;
128
- out[3] = xy - zs;
129
- out[4] = ((y * y) * ic) + c;
130
- out[5] = yz + xs;
131
- out[6] = xz + ys;
132
- out[7] = yz - xs;
133
- out[8] = ((z * z) * ic) + c;
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 tx, ty, tz, xx, xy, xz, yy, yz, zz, wx, wy, wz;
141
-
142
- tx = s_float_lit(2.0) * in[0];
143
- ty = s_float_lit(2.0) * in[1];
144
- tz = s_float_lit(2.0) * in[2];
145
-
146
- xx = tx * in[0];
147
- xy = tx * in[1];
148
- xz = tx * in[2];
149
-
150
- yy = ty * in[1];
151
- yz = tz * in[1];
152
-
153
- zz = tz * in[3];
154
-
155
- wx = tx * in[3];
156
- wy = ty * in[3];
157
- wz = tz * in[3];
158
-
159
- out[0] = s_float_lit(1.0) - (yy + zz);
160
- out[1] = xy - wz;
161
- out[2] = xz + wy;
162
- out[3] = xy + wz;
163
- out[4] = s_float_lit(1.0) - (xx + zz);
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
 
@@ -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 = s_cos(angle_rad);
210
- const s_float_t s = s_sin(angle_rad);
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 tx, ty, tz, xx, xy, xz, yy, yz, zz, wx, wy, wz;
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 = tx * quat[0];
319
- xy = tx * quat[1];
320
- xz = tx * quat[2];
320
+ xx = quat[0] * quat[0];
321
+ xy = quat[0] * quat[1];
322
+ xz = quat[0] * quat[2];
321
323
 
322
- yy = ty * quat[1];
323
- yz = tz * quat[1];
324
+ yy = quat[1] * quat[1];
325
+ yz = quat[2] * quat[2];
324
326
 
325
- zz = tz * quat[3];
327
+ zz = quat[2] * quat[2];
326
328
 
327
- wx = tx * quat[3];
328
- wy = ty * quat[3];
329
- wz = tz * quat[3];
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);
@@ -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, s_sm_mat4_klass);
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, s_sm_mat3_klass);
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");
@@ -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
@@ -32,7 +32,6 @@ module Snow
32
32
  #
33
33
  # # Bad
34
34
  # Vec3[1, 2, 3].www # => Invalid, no W component for Vec3
35
- # Vec3[1, 2, 3].xx # => Invalid, no 2-component vector type
36
35
  # Vec3[1, 2, 3].xxxxx # => Invalid, no 5-component vector type
37
36
  #
38
37
  module SwizzleSupport
@@ -7,6 +7,6 @@ module Snow
7
7
  #
8
8
  # snow-math bindings version string.
9
9
  #
10
- SNOW_MATH_VERSION = '1.7.0'
10
+ SNOW_MATH_VERSION = '1.7.1'
11
11
 
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snow-math
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noel Raymond Cower