|
@@ -274,7 +274,7 @@ THREE.Vector3.prototype = {
|
|
setEulerFromRotationMatrix: function ( m, order ) {
|
|
setEulerFromRotationMatrix: function ( m, order ) {
|
|
|
|
|
|
// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
|
|
// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
|
|
-
|
|
|
|
|
|
+
|
|
// clamp, to handle numerical problems
|
|
// clamp, to handle numerical problems
|
|
|
|
|
|
function clamp( x ) {
|
|
function clamp( x ) {
|
|
@@ -291,101 +291,101 @@ THREE.Vector3.prototype = {
|
|
if ( order === undefined || order === 'XYZ' ) {
|
|
if ( order === undefined || order === 'XYZ' ) {
|
|
|
|
|
|
this.y = Math.asin( clamp( m13 ) );
|
|
this.y = Math.asin( clamp( m13 ) );
|
|
-
|
|
|
|
|
|
+
|
|
if ( Math.abs( m13 ) < 0.99999 ) {
|
|
if ( Math.abs( m13 ) < 0.99999 ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.x = Math.atan2( - m23, m33 );
|
|
this.x = Math.atan2( - m23, m33 );
|
|
this.z = Math.atan2( - m12, m11 );
|
|
this.z = Math.atan2( - m12, m11 );
|
|
-
|
|
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
|
|
+
|
|
this.x = Math.atan2( m21, m22 );
|
|
this.x = Math.atan2( m21, m22 );
|
|
this.z = 0;
|
|
this.z = 0;
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
} else if ( order === 'YXZ' ) {
|
|
} else if ( order === 'YXZ' ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.x = Math.asin( - clamp( m23 ) );
|
|
this.x = Math.asin( - clamp( m23 ) );
|
|
-
|
|
|
|
|
|
+
|
|
if ( Math.abs( m23 ) < 0.99999 ) {
|
|
if ( Math.abs( m23 ) < 0.99999 ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.y = Math.atan2( m13, m33 );
|
|
this.y = Math.atan2( m13, m33 );
|
|
this.z = Math.atan2( m21, m22 );
|
|
this.z = Math.atan2( m21, m22 );
|
|
-
|
|
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
|
|
+
|
|
this.y = Math.atan2( - m31, m11 );
|
|
this.y = Math.atan2( - m31, m11 );
|
|
this.z = 0;
|
|
this.z = 0;
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
} else if ( order === 'ZXY' ) {
|
|
} else if ( order === 'ZXY' ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.x = Math.asin( clamp( m32 ) );
|
|
this.x = Math.asin( clamp( m32 ) );
|
|
-
|
|
|
|
|
|
+
|
|
if ( Math.abs( m32 ) < 0.99999 ) {
|
|
if ( Math.abs( m32 ) < 0.99999 ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.y = Math.atan2( - m31, m33 );
|
|
this.y = Math.atan2( - m31, m33 );
|
|
this.z = Math.atan2( - m12, m22 );
|
|
this.z = Math.atan2( - m12, m22 );
|
|
-
|
|
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
|
|
+
|
|
this.y = 0;
|
|
this.y = 0;
|
|
this.z = Math.atan2( m13, m11 );
|
|
this.z = Math.atan2( m13, m11 );
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
} else if ( order === 'ZYX' ) {
|
|
} else if ( order === 'ZYX' ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.y = Math.asin( - clamp( m31 ) );
|
|
this.y = Math.asin( - clamp( m31 ) );
|
|
-
|
|
|
|
|
|
+
|
|
if ( Math.abs( m31 ) < 0.99999 ) {
|
|
if ( Math.abs( m31 ) < 0.99999 ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.x = Math.atan2( m32, m33 );
|
|
this.x = Math.atan2( m32, m33 );
|
|
this.z = Math.atan2( m21, m11 );
|
|
this.z = Math.atan2( m21, m11 );
|
|
-
|
|
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
|
|
+
|
|
this.x = 0;
|
|
this.x = 0;
|
|
this.z = Math.atan2( - m12, m22 );
|
|
this.z = Math.atan2( - m12, m22 );
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
} else if ( order === 'YZX' ) {
|
|
} else if ( order === 'YZX' ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.z = Math.asin( clamp( m21 ) );
|
|
this.z = Math.asin( clamp( m21 ) );
|
|
-
|
|
|
|
|
|
+
|
|
if ( Math.abs( m21 ) < 0.99999 ) {
|
|
if ( Math.abs( m21 ) < 0.99999 ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.x = Math.atan2( - m23, m22 );
|
|
this.x = Math.atan2( - m23, m22 );
|
|
this.y = Math.atan2( - m31, m11 );
|
|
this.y = Math.atan2( - m31, m11 );
|
|
-
|
|
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
|
|
+
|
|
this.x = 0;
|
|
this.x = 0;
|
|
this.y = Math.atan2( m31, m33 );
|
|
this.y = Math.atan2( m31, m33 );
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
} else if ( order === 'XZY' ) {
|
|
} else if ( order === 'XZY' ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.z = Math.asin( - clamp( m12 ) );
|
|
this.z = Math.asin( - clamp( m12 ) );
|
|
-
|
|
|
|
|
|
+
|
|
if ( Math.abs( m12 ) < 0.99999 ) {
|
|
if ( Math.abs( m12 ) < 0.99999 ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.x = Math.atan2( m32, m22 );
|
|
this.x = Math.atan2( m32, m22 );
|
|
this.y = Math.atan2( m13, m11 );
|
|
this.y = Math.atan2( m13, m11 );
|
|
-
|
|
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
|
|
+
|
|
this.x = Math.atan2( - m13, m33 );
|
|
this.x = Math.atan2( - m13, m33 );
|
|
this.y = 0;
|
|
this.y = 0;
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
return this;
|
|
return this;
|
|
|
|
|
|
},
|
|
},
|
|
@@ -403,7 +403,7 @@ THREE.Vector3.prototype = {
|
|
}
|
|
}
|
|
|
|
|
|
// http://www.mathworks.com/matlabcentral/fileexchange/20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/content/SpinCalc.m
|
|
// http://www.mathworks.com/matlabcentral/fileexchange/20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/content/SpinCalc.m
|
|
-
|
|
|
|
|
|
+
|
|
var sqx = q.x * q.x;
|
|
var sqx = q.x * q.x;
|
|
var sqy = q.y * q.y;
|
|
var sqy = q.y * q.y;
|
|
var sqz = q.z * q.z;
|
|
var sqz = q.z * q.z;
|
|
@@ -414,39 +414,39 @@ THREE.Vector3.prototype = {
|
|
this.x = Math.atan2( 2 * ( q.x * q.w - q.y * q.z ), ( sqw - sqx - sqy + sqz ) );
|
|
this.x = Math.atan2( 2 * ( q.x * q.w - q.y * q.z ), ( sqw - sqx - sqy + sqz ) );
|
|
this.y = Math.asin( clamp( 2 * ( q.x * q.z + q.y * q.w ) ) );
|
|
this.y = Math.asin( clamp( 2 * ( q.x * q.z + q.y * q.w ) ) );
|
|
this.z = Math.atan2( 2 * ( q.z * q.w - q.x * q.y ), ( sqw + sqx - sqy - sqz ) );
|
|
this.z = Math.atan2( 2 * ( q.z * q.w - q.x * q.y ), ( sqw + sqx - sqy - sqz ) );
|
|
-
|
|
|
|
|
|
+
|
|
} else if ( order === 'YXZ' ) {
|
|
} else if ( order === 'YXZ' ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.x = Math.asin( clamp( 2 * ( q.x * q.w - q.y * q.z ) ) );
|
|
this.x = Math.asin( clamp( 2 * ( q.x * q.w - q.y * q.z ) ) );
|
|
this.y = Math.atan2( 2 * ( q.x * q.z + q.y * q.w ), ( sqw - sqx - sqy + sqz ) );
|
|
this.y = Math.atan2( 2 * ( q.x * q.z + q.y * q.w ), ( sqw - sqx - sqy + sqz ) );
|
|
this.z = Math.atan2( 2 * ( q.x * q.y + q.z * q.w ), ( sqw - sqx + sqy - sqz ) );
|
|
this.z = Math.atan2( 2 * ( q.x * q.y + q.z * q.w ), ( sqw - sqx + sqy - sqz ) );
|
|
-
|
|
|
|
|
|
+
|
|
} else if ( order === 'ZXY' ) {
|
|
} else if ( order === 'ZXY' ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.x = Math.asin( clamp( 2 * ( q.x * q.w + q.y * q.z ) ) );
|
|
this.x = Math.asin( clamp( 2 * ( q.x * q.w + q.y * q.z ) ) );
|
|
this.y = Math.atan2( 2 * ( q.y * q.w - q.z * q.x ), ( sqw - sqx - sqy + sqz ) );
|
|
this.y = Math.atan2( 2 * ( q.y * q.w - q.z * q.x ), ( sqw - sqx - sqy + sqz ) );
|
|
this.z = Math.atan2( 2 * ( q.z * q.w - q.x * q.y ), ( sqw - sqx + sqy - sqz ) );
|
|
this.z = Math.atan2( 2 * ( q.z * q.w - q.x * q.y ), ( sqw - sqx + sqy - sqz ) );
|
|
-
|
|
|
|
|
|
+
|
|
} else if ( order === 'ZYX' ) {
|
|
} else if ( order === 'ZYX' ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.x = Math.atan2( 2 * ( q.x * q.w + q.z * q.y ), ( sqw - sqx - sqy + sqz ) );
|
|
this.x = Math.atan2( 2 * ( q.x * q.w + q.z * q.y ), ( sqw - sqx - sqy + sqz ) );
|
|
this.y = Math.asin( clamp( 2 * ( q.y * q.w - q.x * q.z ) ) );
|
|
this.y = Math.asin( clamp( 2 * ( q.y * q.w - q.x * q.z ) ) );
|
|
this.z = Math.atan2( 2 * ( q.x * q.y + q.z * q.w ), ( sqw + sqx - sqy - sqz ) );
|
|
this.z = Math.atan2( 2 * ( q.x * q.y + q.z * q.w ), ( sqw + sqx - sqy - sqz ) );
|
|
-
|
|
|
|
|
|
+
|
|
} else if ( order === 'YZX' ) {
|
|
} else if ( order === 'YZX' ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.x = Math.atan2( 2 * ( q.x * q.w - q.z * q.y ), ( sqw - sqx + sqy - sqz ) );
|
|
this.x = Math.atan2( 2 * ( q.x * q.w - q.z * q.y ), ( sqw - sqx + sqy - sqz ) );
|
|
this.y = Math.atan2( 2 * ( q.y * q.w - q.x * q.z ), ( sqw + sqx - sqy - sqz ) );
|
|
this.y = Math.atan2( 2 * ( q.y * q.w - q.x * q.z ), ( sqw + sqx - sqy - sqz ) );
|
|
this.z = Math.asin( clamp( 2 * ( q.x * q.y + q.z * q.w ) ) );
|
|
this.z = Math.asin( clamp( 2 * ( q.x * q.y + q.z * q.w ) ) );
|
|
-
|
|
|
|
|
|
+
|
|
} else if ( order === 'XZY' ) {
|
|
} else if ( order === 'XZY' ) {
|
|
-
|
|
|
|
|
|
+
|
|
this.x = Math.atan2( 2 * ( q.x * q.w + q.y * q.z ), ( sqw - sqx + sqy - sqz ) );
|
|
this.x = Math.atan2( 2 * ( q.x * q.w + q.y * q.z ), ( sqw - sqx + sqy - sqz ) );
|
|
this.y = Math.atan2( 2 * ( q.x * q.z + q.y * q.w ), ( sqw + sqx - sqy - sqz ) );
|
|
this.y = Math.atan2( 2 * ( q.x * q.z + q.y * q.w ), ( sqw + sqx - sqy - sqz ) );
|
|
this.z = Math.asin( clamp( 2 * ( q.z * q.w - q.x * q.y ) ) );
|
|
this.z = Math.asin( clamp( 2 * ( q.z * q.w - q.x * q.y ) ) );
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
return this;
|
|
return this;
|
|
|
|
|
|
},
|
|
},
|