@galacean/engine-math 1.1.0-beta.17 → 1.1.0-beta.18

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.
@@ -2234,14 +2234,27 @@ function _create_class(Constructor, protoProps, staticProps) {
2234
2234
  };
2235
2235
  };
2236
2236
  _proto._toYawPitchRoll = function _toYawPitchRoll(out) {
2237
- // https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
2237
+ // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/
2238
2238
  var _this = this, x = _this._x, y = _this._y, z = _this._z, w = _this._w;
2239
2239
  var xx = x * x;
2240
- var sinP = 2.0 * (x * w - y * z);
2241
- // use 90 degrees if out of range
2242
- out._y = Math.abs(sinP) >= 1 ? Math.sign(sinP) * (Math.PI / 2) : Math.asin(sinP);
2243
- out._x = Math.atan2(2.0 * (z * x + y * w), 1.0 - 2.0 * (y * y + xx));
2244
- out._z = Math.atan2(2.0 * (x * y + z * w), 1.0 - 2.0 * (z * z + xx));
2240
+ var yy = y * y;
2241
+ var zz = z * z;
2242
+ var ww = w * w;
2243
+ var unit = xx + yy + zz + ww;
2244
+ var test = 2 * (x * w - y * z);
2245
+ if (test > (1 - MathUtil.zeroTolerance) * unit) {
2246
+ out._x = Math.atan2(2.0 * (w * y - x * z), zz + ww - yy - zz);
2247
+ out._y = Math.PI / 2;
2248
+ out._z = 0;
2249
+ } else if (test < -(1 - MathUtil.zeroTolerance) * unit) {
2250
+ out._x = Math.atan2(2.0 * (w * y - x * z), zz + ww - yy - zz);
2251
+ out._y = -Math.PI / 2;
2252
+ out._z = 0;
2253
+ } else {
2254
+ out._x = Math.atan2(2.0 * (z * x + y * w), zz + ww - yy - xx);
2255
+ out._y = Math.asin(test / unit);
2256
+ out._z = Math.atan2(2.0 * (x * y + z * w), yy + ww - zz - xx);
2257
+ }
2245
2258
  };
2246
2259
  /**
2247
2260
  * Determines the sum of two quaternions.
package/dist/module.js CHANGED
@@ -2230,14 +2230,27 @@ function _create_class(Constructor, protoProps, staticProps) {
2230
2230
  };
2231
2231
  };
2232
2232
  _proto._toYawPitchRoll = function _toYawPitchRoll(out) {
2233
- // https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
2233
+ // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/
2234
2234
  var _this = this, x = _this._x, y = _this._y, z = _this._z, w = _this._w;
2235
2235
  var xx = x * x;
2236
- var sinP = 2.0 * (x * w - y * z);
2237
- // use 90 degrees if out of range
2238
- out._y = Math.abs(sinP) >= 1 ? Math.sign(sinP) * (Math.PI / 2) : Math.asin(sinP);
2239
- out._x = Math.atan2(2.0 * (z * x + y * w), 1.0 - 2.0 * (y * y + xx));
2240
- out._z = Math.atan2(2.0 * (x * y + z * w), 1.0 - 2.0 * (z * z + xx));
2236
+ var yy = y * y;
2237
+ var zz = z * z;
2238
+ var ww = w * w;
2239
+ var unit = xx + yy + zz + ww;
2240
+ var test = 2 * (x * w - y * z);
2241
+ if (test > (1 - MathUtil.zeroTolerance) * unit) {
2242
+ out._x = Math.atan2(2.0 * (w * y - x * z), zz + ww - yy - zz);
2243
+ out._y = Math.PI / 2;
2244
+ out._z = 0;
2245
+ } else if (test < -(1 - MathUtil.zeroTolerance) * unit) {
2246
+ out._x = Math.atan2(2.0 * (w * y - x * z), zz + ww - yy - zz);
2247
+ out._y = -Math.PI / 2;
2248
+ out._z = 0;
2249
+ } else {
2250
+ out._x = Math.atan2(2.0 * (z * x + y * w), zz + ww - yy - xx);
2251
+ out._y = Math.asin(test / unit);
2252
+ out._z = Math.atan2(2.0 * (x * y + z * w), yy + ww - zz - xx);
2253
+ }
2241
2254
  };
2242
2255
  /**
2243
2256
  * Determines the sum of two quaternions.