|
@@ -1296,45 +1296,47 @@ var BABYLON;
|
|
|
this.w *= length;
|
|
|
return this;
|
|
|
};
|
|
|
- Quaternion.prototype.toEulerAngles = function () {
|
|
|
+ Quaternion.prototype.toEulerAngles = function (order) {
|
|
|
+ if (order === void 0) { order = "YZX"; }
|
|
|
var result = Vector3.Zero();
|
|
|
this.toEulerAnglesToRef(result);
|
|
|
return result;
|
|
|
};
|
|
|
- Quaternion.prototype.toEulerAnglesToRef = function (result) {
|
|
|
- //result is an EulerAngles in the in the z-x-z convention
|
|
|
- var qx = this.x;
|
|
|
- var qy = this.y;
|
|
|
- var qz = this.z;
|
|
|
- var qw = this.w;
|
|
|
- var qxy = qx * qy;
|
|
|
- var qxz = qx * qz;
|
|
|
- var qwy = qw * qy;
|
|
|
- var qwz = qw * qz;
|
|
|
- var qwx = qw * qx;
|
|
|
- var qyz = qy * qz;
|
|
|
- var sqx = qx * qx;
|
|
|
- var sqy = qy * qy;
|
|
|
- var determinant = sqx + sqy;
|
|
|
- if (determinant !== 0.000 && determinant !== 1.000) {
|
|
|
- result.x = Math.atan2(qxz + qwy, qwx - qyz);
|
|
|
- result.y = Math.acos(1 - 2 * determinant);
|
|
|
- result.z = Math.atan2(qxz - qwy, qwx + qyz);
|
|
|
- }
|
|
|
- else {
|
|
|
- if (determinant === 0.0) {
|
|
|
- result.x = 0.0;
|
|
|
- result.y = 0.0;
|
|
|
- result.z = Math.atan2(qxy - qwz, 0.5 - sqy - qz * qz); //actually, degeneracy gives us choice with x+z=Math.atan2(qxy-qwz,0.5-sqy-qz*qz)
|
|
|
- }
|
|
|
- else {
|
|
|
- result.x = Math.atan2(qxy - qwz, 0.5 - sqy - qz * qz); //actually, degeneracy gives us choice with x-z=Math.atan2(qxy-qwz,0.5-sqy-qz*qz)
|
|
|
- result.y = Math.PI;
|
|
|
- result.z = 0.0;
|
|
|
- }
|
|
|
- }
|
|
|
- return this;
|
|
|
- };
|
|
|
+ Quaternion.prototype.toEulerAnglesToRef = function (result, order) {
|
|
|
+ if (order === void 0) { order = "YZX"; }
|
|
|
+ var heading, attitude, bank;
|
|
|
+ var x = this.x, y = this.y, z = this.z, w = this.w;
|
|
|
+ switch (order) {
|
|
|
+ case "YZX":
|
|
|
+ var test = x * y + z * w;
|
|
|
+ if (test > 0.499) {
|
|
|
+ heading = 2 * Math.atan2(x, w);
|
|
|
+ attitude = Math.PI / 2;
|
|
|
+ bank = 0;
|
|
|
+ }
|
|
|
+ if (test < -0.499) {
|
|
|
+ heading = -2 * Math.atan2(x, w);
|
|
|
+ attitude = -Math.PI / 2;
|
|
|
+ bank = 0;
|
|
|
+ }
|
|
|
+ if (isNaN(heading)) {
|
|
|
+ var sqx = x * x;
|
|
|
+ var sqy = y * y;
|
|
|
+ var sqz = z * z;
|
|
|
+ heading = Math.atan2(2 * y * w - 2 * x * z, 1 - 2 * sqy - 2 * sqz); // Heading
|
|
|
+ attitude = Math.asin(2 * test); // attitude
|
|
|
+ bank = Math.atan2(2 * x * w - 2 * y * z, 1 - 2 * sqx - 2 * sqz); // bank
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new Error("Euler order " + order + " not supported yet.");
|
|
|
+ }
|
|
|
+ result.y = heading;
|
|
|
+ result.z = attitude;
|
|
|
+ result.x = bank;
|
|
|
+ return this;
|
|
|
+ };
|
|
|
+ ;
|
|
|
Quaternion.prototype.toRotationMatrix = function (result) {
|
|
|
var xx = this.x * this.x;
|
|
|
var yy = this.y * this.y;
|