|
@@ -101,7 +101,7 @@ THREE.Euler.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- setFromRotationMatrix: function ( m, order ) {
|
|
|
+ setFromRotationMatrix: function ( m, order, update ) {
|
|
|
|
|
|
var clamp = THREE.Math.clamp;
|
|
|
|
|
@@ -218,76 +218,26 @@ THREE.Euler.prototype = {
|
|
|
|
|
|
this._order = order;
|
|
|
|
|
|
- this.onChangeCallback();
|
|
|
+ if ( update !== false ) this.onChangeCallback();
|
|
|
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
- setFromQuaternion: function ( q, order, update ) {
|
|
|
-
|
|
|
- var clamp = THREE.Math.clamp;
|
|
|
-
|
|
|
- // q is assumed to be normalized
|
|
|
-
|
|
|
- // 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 sqy = q.y * q.y;
|
|
|
- var sqz = q.z * q.z;
|
|
|
- var sqw = q.w * q.w;
|
|
|
-
|
|
|
- order = order || this._order;
|
|
|
-
|
|
|
- if ( order === 'XYZ' ) {
|
|
|
-
|
|
|
- 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 ), - 1, 1 ) );
|
|
|
- this._z = Math.atan2( 2 * ( q.z * q.w - q.x * q.y ), ( sqw + sqx - sqy - sqz ) );
|
|
|
-
|
|
|
- } else if ( order === 'YXZ' ) {
|
|
|
-
|
|
|
- this._x = Math.asin( clamp( 2 * ( q.x * q.w - q.y * q.z ), - 1, 1 ) );
|
|
|
- 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 ) );
|
|
|
-
|
|
|
- } else if ( order === 'ZXY' ) {
|
|
|
-
|
|
|
- this._x = Math.asin( clamp( 2 * ( q.x * q.w + q.y * q.z ), - 1, 1 ) );
|
|
|
- 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 ) );
|
|
|
+ setFromQuaternion: function() {
|
|
|
|
|
|
- } else if ( order === 'ZYX' ) {
|
|
|
+ var mIntermediate = null;
|
|
|
+
|
|
|
+ return function( q, order, update ) {
|
|
|
+
|
|
|
+ mIntermediate = mIntermediate || new THREE.Matrix4();
|
|
|
+ mIntermediate.makeRotationFromQuaternion( q );
|
|
|
+ this.setFromRotationMatrix( mIntermediate, order );
|
|
|
+
|
|
|
+ return this;
|
|
|
+ };
|
|
|
|
|
|
- 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 ), - 1, 1 ) );
|
|
|
- this._z = Math.atan2( 2 * ( q.x * q.y + q.z * q.w ), ( sqw + sqx - sqy - sqz ) );
|
|
|
-
|
|
|
- } else if ( order === 'YZX' ) {
|
|
|
-
|
|
|
- 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._z = Math.asin( clamp( 2 * ( q.x * q.y + q.z * q.w ), - 1, 1 ) );
|
|
|
-
|
|
|
- } else if ( order === 'XZY' ) {
|
|
|
-
|
|
|
- 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._z = Math.asin( clamp( 2 * ( q.z * q.w - q.x * q.y ), - 1, 1 ) );
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- console.warn( 'THREE.Euler: .setFromQuaternion() given unsupported order: ' + order )
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- this._order = order;
|
|
|
-
|
|
|
- if ( update !== false ) this.onChangeCallback();
|
|
|
-
|
|
|
- return this;
|
|
|
-
|
|
|
- },
|
|
|
+ }(),
|
|
|
|
|
|
reorder: function () {
|
|
|
|
|
@@ -302,7 +252,6 @@ THREE.Euler.prototype = {
|
|
|
|
|
|
};
|
|
|
|
|
|
-
|
|
|
}(),
|
|
|
|
|
|
equals: function ( euler ) {
|