diff --git a/examples/css3d_molecules.html b/examples/css3d_molecules.html index 9d17acbf08374d..8b37a9dd372088 100644 --- a/examples/css3d_molecules.html +++ b/examples/css3d_molecules.html @@ -433,7 +433,7 @@ var objMatrix = new THREE.Matrix4().makeRotationAxis( axis.normalize(), radians ); object.matrix = objMatrix; - object.rotation.setEulerFromRotationMatrix( object.matrix, object.eulerOrder ); + object.rotation.setFromRotationMatrix( object.matrix, object.rotation.order ); object.matrixAutoUpdate = false; object.updateMatrix(); @@ -453,7 +453,7 @@ joint.position.lerp( end, 0.5 ); joint.matrix.copy( objMatrix ); - joint.rotation.setEulerFromRotationMatrix( joint.matrix, joint.eulerOrder ); + joint.rotation.setFromRotationMatrix( joint.matrix, joint.rotation.order ); joint.matrixAutoUpdate = false; joint.updateMatrix(); diff --git a/examples/js/controls/FlyControls.js b/examples/js/controls/FlyControls.js index 1c21e5eca55d0b..bf0e6fee55e96c 100644 --- a/examples/js/controls/FlyControls.js +++ b/examples/js/controls/FlyControls.js @@ -199,7 +199,7 @@ THREE.FlyControls = function ( object, domElement ) { this.object.quaternion.multiply( this.tmpQuaternion ); // expose the rotation vector for convenience - this.object.rotation.setEulerFromQuaternion( this.object.quaternion, this.object.eulerOrder ); + this.object.rotation.setFromQuaternion( this.object.quaternion, this.object.rotation.order ); }; diff --git a/examples/js/controls/TransformControls.js b/examples/js/controls/TransformControls.js index ef441fb19282da..d01a9358a8f9ca 100644 --- a/examples/js/controls/TransformControls.js +++ b/examples/js/controls/TransformControls.js @@ -379,11 +379,11 @@ THREE.TransformControls = function ( camera, domElement, doc ) { this.object.updateMatrixWorld(); worldPosition.getPositionFromMatrix( this.object.matrixWorld ); - worldRotation.setEulerFromRotationMatrix( tempMatrix.extractRotation(this.object.matrixWorld )); + worldRotation.setFromRotationMatrix( tempMatrix.extractRotation(this.object.matrixWorld )); this.camera.updateMatrixWorld(); camPosition.getPositionFromMatrix( this.camera.matrixWorld ); - camRotation.setEulerFromRotationMatrix( tempMatrix.extractRotation( this.camera.matrixWorld )); + camRotation.setFromRotationMatrix( tempMatrix.extractRotation( this.camera.matrixWorld )); scale = worldPosition.distanceTo( camPosition ) / 6 * this.scale; this.gizmo.position.copy( worldPosition ) @@ -399,7 +399,7 @@ THREE.TransformControls = function ( camera, domElement, doc ) { if ( name.search('E') != -1 ){ lookAtMatrix.lookAt( camPosition, worldPosition, tempVector.set( 0, 1, 0 )); - object.rotation.setEulerFromRotationMatrix( lookAtMatrix ); + object.rotation.setFromRotationMatrix( lookAtMatrix ); } else { @@ -431,7 +431,7 @@ THREE.TransformControls = function ( camera, domElement, doc ) { } - object.rotation.setEulerFromQuaternion( tempQuaternion ); + object.rotation.setFromQuaternion( tempQuaternion ); } else if ( this.space == 'world' ) { @@ -789,7 +789,7 @@ THREE.TransformControls = function ( camera, domElement, doc ) { tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionE ); tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ ); - scope.object.rotation.setEulerFromQuaternion( tempQuaternion ); + scope.object.rotation.setFromQuaternion( tempQuaternion ); } else if ( scope.active == "RXYZE" ) { @@ -802,7 +802,7 @@ THREE.TransformControls = function ( camera, domElement, doc ) { tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX ); tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ ); - scope.object.rotation.setEulerFromQuaternion( tempQuaternion ); + scope.object.rotation.setFromQuaternion( tempQuaternion ); } else if ( scope.space == 'local' ) { @@ -822,7 +822,7 @@ THREE.TransformControls = function ( camera, domElement, doc ) { if ( scope.active == "RY" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionY ); if ( scope.active == "RZ" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionZ ); - scope.object.rotation.setEulerFromQuaternion( quaternionXYZ ); + scope.object.rotation.setFromQuaternion( quaternionXYZ ); } else if ( scope.space == 'world' ) { @@ -842,7 +842,7 @@ THREE.TransformControls = function ( camera, domElement, doc ) { tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ ); - scope.object.rotation.setEulerFromQuaternion( tempQuaternion ); + scope.object.rotation.setFromQuaternion( tempQuaternion ); } diff --git a/examples/webgl_geometry_extrude_splines.html b/examples/webgl_geometry_extrude_splines.html index 755e16babdfef2..006688603f85fb 100644 --- a/examples/webgl_geometry_extrude_splines.html +++ b/examples/webgl_geometry_extrude_splines.html @@ -380,7 +380,7 @@ if (!lookAhead) lookAt.copy( pos ).add( dir ); splineCamera.matrix.lookAt(splineCamera.position, lookAt, normal); - splineCamera.rotation.setEulerFromRotationMatrix( splineCamera.matrix, splineCamera.eulerOrder ); + splineCamera.rotation.setFromRotationMatrix( splineCamera.matrix, splineCamera.rotation.order ); cameraHelper.update(); diff --git a/examples/webgl_multiple_windows.html b/examples/webgl_multiple_windows.html index 01bbaeedf77a1f..20dfd5e6b1c067 100644 --- a/examples/webgl_multiple_windows.html +++ b/examples/webgl_multiple_windows.html @@ -192,7 +192,7 @@ dst.up.copy( src.up ); dst.position.copy( src.position ); dst.scale.copy( src.scale ); - dst.eulerOrder = src.eulerOrder; + dst.rotation.copy( src.rotation ); dst.quaternion.copy( src.quaternion ); }; diff --git a/src/cameras/Camera.js b/src/cameras/Camera.js index a982a0e4ef3786..ab3f4b08ed30e3 100644 --- a/src/cameras/Camera.js +++ b/src/cameras/Camera.js @@ -33,7 +33,7 @@ THREE.Camera.prototype.lookAt = function () { } else { - this.rotation.setEulerFromRotationMatrix( m1, this.eulerOrder ); + this.rotation.setFromRotationMatrix( m1, this.rotation.Order ); } diff --git a/src/core/Object3D.js b/src/core/Object3D.js index 6e76322d6582ae..676b72383fed72 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -17,8 +17,7 @@ THREE.Object3D = function () { this.up = new THREE.Vector3( 0, 1, 0 ); this.position = new THREE.Vector3(); - this.rotation = new THREE.Vector3(); - this.eulerOrder = THREE.Object3D.defaultEulerOrder; + this.rotation = new THREE.Euler(); this.scale = new THREE.Vector3( 1, 1, 1 ); this.renderDepth = null; @@ -75,7 +74,7 @@ THREE.Object3D.prototype = { } else { - this.rotation.setEulerFromRotationMatrix( m1, this.eulerOrder ); + this.rotation.setFromRotationMatrix( m1, this.rotation.order ); } @@ -101,10 +100,10 @@ THREE.Object3D.prototype = { } else { - q2.setFromEuler( this.rotation, this.eulerOrder ); + q2.setFromEuler( this.rotation ); q2.multiply( q1 ); - this.rotation.setEulerFromQuaternion( q2, this.eulerOrder ); + this.rotation.setFromQuaternion( q2, this.rotation.order ); } @@ -131,7 +130,7 @@ THREE.Object3D.prototype = { } else { - v1.applyEuler( this.rotation, this.eulerOrder ); + v1.applyEuler( this.rotation ); } @@ -220,7 +219,7 @@ THREE.Object3D.prototype = { } else { - this.rotation.setEulerFromRotationMatrix( m1, this.eulerOrder ); + this.rotation.setFromRotationMatrix( m1, this.rotation.order ); } @@ -398,7 +397,7 @@ THREE.Object3D.prototype = { if ( this.useQuaternion === false ) { - this.matrix.makeFromPositionEulerScale( this.position, this.rotation, this.eulerOrder, this.scale ); + this.matrix.makeFromPositionEulerScale( this.position, this.rotation, this.scale ); } else { @@ -451,8 +450,7 @@ THREE.Object3D.prototype = { object.up.copy( this.up ); object.position.copy( this.position ); - if ( object.rotation instanceof THREE.Vector3 ) object.rotation.copy( this.rotation ); // because of Sprite madness - object.eulerOrder = this.eulerOrder; + if ( object.rotation instanceof THREE.Euler ) object.rotation.copy( this.rotation ); // because of Sprite madness object.scale.copy( this.scale ); object.renderDepth = this.renderDepth; diff --git a/src/math/Euler3.js b/src/math/Euler.js similarity index 82% rename from src/math/Euler3.js rename to src/math/Euler.js index dcdff65ffd6aa5..5e397e0fcb2333 100644 --- a/src/math/Euler3.js +++ b/src/math/Euler.js @@ -1,21 +1,25 @@ /** + * @author mrdoob / http://mrdoob.com/ + * @author WestLangley / http://github.com/WestLangley * @author bhouston / http://exocortex.com */ -THREE.Euler3 = function ( x, y, z, order ) { +THREE.Euler = function ( x, y, z, order ) { this.x = x || 0; this.y = y || 0; this.z = z || 0; - this.order = order || "XYZ"; + this.order = order || THREE.Euler.DefaultOrder; }; -THREE.Euler3.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ]; +THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ]; -THREE.Euler3.prototype = { +THREE.Euler.DefaultOrder = 'XYZ'; - constructor: THREE.Euler3, +THREE.Euler.prototype = { + + constructor: THREE.Euler, set: function ( x, y, z, order ) { @@ -226,30 +230,50 @@ THREE.Euler3.prototype = { clamp: function() { // todo + console.error( "ERROR: Euler.clamp() is not yet implemented."); }, reorder: function( newOrder ) { // todo. + console.error( "ERROR: Euler.reorder() is not yet implemented."); }, alternativeSolution: function() { // todo. + console.error( "ERROR: Euler.alternativeSolution() is not yet implemented."); + + }, + + fromArray: function ( array ) { + + this.x = array[ 0 ]; + this.y = array[ 1 ]; + this.z = array[ 2 ]; + this.order = array[ 3 ]; + + return this; + + }, + + toArray: function () { + + return [ this.x, this.y, this.z, this.order ]; }, - equals: function ( e ) { + equals: function ( rotation ) { - return ( ( e.x === this.x ) && ( e.y === this.y ) && ( e.z === this.z ) && ( e.order === this.order ) ); + return ( ( rotation.x === this.x ) && ( rotation.y === this.y ) && ( rotation.z === this.z ) && ( rotation.order === this.order ) ); }, clone: function () { - return new THREE.Euler3( this.x, this.y, this.z, this.order ); + return new THREE.Euler( this.x, this.y, this.z, this.order ); } diff --git a/src/math/Matrix4.js b/src/math/Matrix4.js index b518ff3f477047..df794d645bacaa 100644 --- a/src/math/Matrix4.js +++ b/src/math/Matrix4.js @@ -126,24 +126,20 @@ THREE.Matrix4.prototype = { }(), - setRotationFromEuler: function ( v, order ) { + makeRotationFromEuler: function ( rotation ) { - console.warn( 'DEPRECATED: Matrix4\'s .setRotationFromEuler() has been deprecated in favor of makeRotationFromEuler. Please update your code.' ); - - return this.makeRotationFromEuler( v, order ); - - }, - - makeRotationFromEuler: function ( v, order ) { + if( typeof rotation['order'] === undefined ) { + console.error( 'ERROR: Matrix\'s .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order. Please update your code.' ); + } var te = this.elements; - var x = v.x, y = v.y, z = v.z; + var x = rotation.x, y = rotation.y, z = rotation.z; var a = Math.cos( x ), b = Math.sin( x ); var c = Math.cos( y ), d = Math.sin( y ); var e = Math.cos( z ), f = Math.sin( z ); - if ( order === undefined || order === 'XYZ' ) { + if ( rotation.order === undefined || rotation.order === 'XYZ' ) { var ae = a * e, af = a * f, be = b * e, bf = b * f; @@ -159,7 +155,7 @@ THREE.Matrix4.prototype = { te[6] = be + af * d; te[10] = a * c; - } else if ( order === 'YXZ' ) { + } else if ( rotation.order === 'YXZ' ) { var ce = c * e, cf = c * f, de = d * e, df = d * f; @@ -175,7 +171,7 @@ THREE.Matrix4.prototype = { te[6] = df + ce * b; te[10] = a * c; - } else if ( order === 'ZXY' ) { + } else if ( rotation.order === 'ZXY' ) { var ce = c * e, cf = c * f, de = d * e, df = d * f; @@ -191,7 +187,7 @@ THREE.Matrix4.prototype = { te[6] = b; te[10] = a * c; - } else if ( order === 'ZYX' ) { + } else if ( rotation.order === 'ZYX' ) { var ae = a * e, af = a * f, be = b * e, bf = b * f; @@ -207,7 +203,7 @@ THREE.Matrix4.prototype = { te[6] = b * c; te[10] = a * c; - } else if ( order === 'YZX' ) { + } else if ( rotation.order === 'YZX' ) { var ac = a * c, ad = a * d, bc = b * c, bd = b * d; @@ -223,7 +219,7 @@ THREE.Matrix4.prototype = { te[6] = ad * f + bc; te[10] = ac - bd * f; - } else if ( order === 'XZY' ) { + } else if ( rotation.order === 'XZY' ) { var ac = a * c, ad = a * d, bc = b * c, bd = b * d; @@ -843,9 +839,13 @@ THREE.Matrix4.prototype = { }, - makeFromPositionEulerScale: function ( position, rotation, eulerOrder, scale ) { + makeFromPositionEulerScale: function ( position, rotation, scale ) { + + if( typeof rotation['order'] === undefined ) { + console.error( 'ERROR: Matrix4\'s .makeFromPositionEulerScale() now expects a Euler rotation rather than a Vector3 and order. Please update your code.' ); + } - this.makeRotationFromEuler( rotation, eulerOrder ); + this.makeRotationFromEuler( rotation ); this.scale( scale ); this.setPosition( position ); diff --git a/src/math/Quaternion.js b/src/math/Quaternion.js index aafdf57b5895ac..ed710f79bf4e05 100644 --- a/src/math/Quaternion.js +++ b/src/math/Quaternion.js @@ -40,55 +40,59 @@ THREE.Quaternion.prototype = { }, - setFromEuler: function ( v, order ) { + setFromEuler: function ( rotation ) { + + if( typeof rotation['order'] === undefined ) { + console.error( 'ERROR: Quaternion\'s .setFromEuler() now expects a Euler rotation rather than a Vector3 and order. Please update your code.' ); + } // http://www.mathworks.com/matlabcentral/fileexchange/ // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/ // content/SpinCalc.m - var c1 = Math.cos( v.x / 2 ); - var c2 = Math.cos( v.y / 2 ); - var c3 = Math.cos( v.z / 2 ); - var s1 = Math.sin( v.x / 2 ); - var s2 = Math.sin( v.y / 2 ); - var s3 = Math.sin( v.z / 2 ); + var c1 = Math.cos( rotation.x / 2 ); + var c2 = Math.cos( rotation.y / 2 ); + var c3 = Math.cos( rotation.z / 2 ); + var s1 = Math.sin( rotation.x / 2 ); + var s2 = Math.sin( rotation.y / 2 ); + var s3 = Math.sin( rotation.z / 2 ); - if ( order === undefined || order === 'XYZ' ) { + if ( rotation.order === undefined || rotation.order === 'XYZ' ) { this.x = s1 * c2 * c3 + c1 * s2 * s3; this.y = c1 * s2 * c3 - s1 * c2 * s3; this.z = c1 * c2 * s3 + s1 * s2 * c3; this.w = c1 * c2 * c3 - s1 * s2 * s3; - } else if ( order === 'YXZ' ) { + } else if ( rotation.order === 'YXZ' ) { this.x = s1 * c2 * c3 + c1 * s2 * s3; this.y = c1 * s2 * c3 - s1 * c2 * s3; this.z = c1 * c2 * s3 - s1 * s2 * c3; this.w = c1 * c2 * c3 + s1 * s2 * s3; - } else if ( order === 'ZXY' ) { + } else if ( rotation.order === 'ZXY' ) { this.x = s1 * c2 * c3 - c1 * s2 * s3; this.y = c1 * s2 * c3 + s1 * c2 * s3; this.z = c1 * c2 * s3 + s1 * s2 * c3; this.w = c1 * c2 * c3 - s1 * s2 * s3; - } else if ( order === 'ZYX' ) { + } else if ( rotation.order === 'ZYX' ) { this.x = s1 * c2 * c3 - c1 * s2 * s3; this.y = c1 * s2 * c3 + s1 * c2 * s3; this.z = c1 * c2 * s3 - s1 * s2 * c3; this.w = c1 * c2 * c3 + s1 * s2 * s3; - } else if ( order === 'YZX' ) { + } else if ( rotation.order === 'YZX' ) { this.x = s1 * c2 * c3 + c1 * s2 * s3; this.y = c1 * s2 * c3 + s1 * c2 * s3; this.z = c1 * c2 * s3 - s1 * s2 * c3; this.w = c1 * c2 * c3 - s1 * s2 * s3; - } else if ( order === 'XZY' ) { + } else if ( rotation.order === 'XZY' ) { this.x = s1 * c2 * c3 - c1 * s2 * s3; this.y = c1 * s2 * c3 - s1 * c2 * s3; diff --git a/src/math/Vector3.js b/src/math/Vector3.js index fe5212c8a5baea..1989ed4217107e 100644 --- a/src/math/Vector3.js +++ b/src/math/Vector3.js @@ -516,186 +516,6 @@ THREE.Vector3.prototype = { }, - setEulerFromRotationMatrix: function ( m, order ) { - - // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled) - - // clamp, to handle numerical problems - - function clamp( x ) { - - return Math.min( Math.max( x, -1 ), 1 ); - - } - - var te = m.elements; - var m11 = te[0], m12 = te[4], m13 = te[8]; - var m21 = te[1], m22 = te[5], m23 = te[9]; - var m31 = te[2], m32 = te[6], m33 = te[10]; - - if ( order === undefined || order === 'XYZ' ) { - - this.y = Math.asin( clamp( m13 ) ); - - if ( Math.abs( m13 ) < 0.99999 ) { - - this.x = Math.atan2( - m23, m33 ); - this.z = Math.atan2( - m12, m11 ); - - } else { - - this.x = Math.atan2( m32, m22 ); - this.z = 0; - - } - - } else if ( order === 'YXZ' ) { - - this.x = Math.asin( - clamp( m23 ) ); - - if ( Math.abs( m23 ) < 0.99999 ) { - - this.y = Math.atan2( m13, m33 ); - this.z = Math.atan2( m21, m22 ); - - } else { - - this.y = Math.atan2( - m31, m11 ); - this.z = 0; - - } - - } else if ( order === 'ZXY' ) { - - this.x = Math.asin( clamp( m32 ) ); - - if ( Math.abs( m32 ) < 0.99999 ) { - - this.y = Math.atan2( - m31, m33 ); - this.z = Math.atan2( - m12, m22 ); - - } else { - - this.y = 0; - this.z = Math.atan2( m21, m11 ); - - } - - } else if ( order === 'ZYX' ) { - - this.y = Math.asin( - clamp( m31 ) ); - - if ( Math.abs( m31 ) < 0.99999 ) { - - this.x = Math.atan2( m32, m33 ); - this.z = Math.atan2( m21, m11 ); - - } else { - - this.x = 0; - this.z = Math.atan2( - m12, m22 ); - - } - - } else if ( order === 'YZX' ) { - - this.z = Math.asin( clamp( m21 ) ); - - if ( Math.abs( m21 ) < 0.99999 ) { - - this.x = Math.atan2( - m23, m22 ); - this.y = Math.atan2( - m31, m11 ); - - } else { - - this.x = 0; - this.y = Math.atan2( m13, m33 ); - - } - - } else if ( order === 'XZY' ) { - - this.z = Math.asin( - clamp( m12 ) ); - - if ( Math.abs( m12 ) < 0.99999 ) { - - this.x = Math.atan2( m32, m22 ); - this.y = Math.atan2( m13, m11 ); - - } else { - - this.x = Math.atan2( - m23, m33 ); - this.y = 0; - - } - - } - - return this; - - }, - - setEulerFromQuaternion: function ( q, order ) { - - // q is assumed to be normalized - - // clamp, to handle numerical problems - - function clamp( x ) { - - return Math.min( Math.max( x, -1 ), 1 ); - - } - - // 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; - - if ( order === undefined || 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 ) ) ); - 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 ) ) ); - 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 ) ) ); - 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 ) ); - - } else if ( order === 'ZYX' ) { - - 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.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 ) ) ); - - } 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 ) ) ); - - } - - return this; - - }, - getPositionFromMatrix: function ( m ) { this.x = m.elements[12]; @@ -769,9 +589,13 @@ THREE.extend( THREE.Vector3.prototype, { var q1 = new THREE.Quaternion(); - return function ( v, eulerOrder ) { + return function ( rotation ) { + + if( typeof rotation['order'] === undefined ) { + console.error( 'ERROR: Vector3\'s .applyEuler() now expects a Euler rotation rather than a Vector3 and order. Please update your code.' ); + } - var quaternion = q1.setFromEuler( v, eulerOrder ); + var quaternion = q1.setFromEuler( rotation ); this.applyQuaternion( quaternion ); diff --git a/src/objects/Sprite.js b/src/objects/Sprite.js index a55967503e9cb3..c8995590c2897b 100644 --- a/src/objects/Sprite.js +++ b/src/objects/Sprite.js @@ -22,8 +22,8 @@ THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype ); THREE.Sprite.prototype.updateMatrix = function () { - this.rotation3d.set( 0, 0, this.rotation ); - this.quaternion.setFromEuler( this.rotation3d, this.eulerOrder ); + this.rotation3d.set( 0, 0, this.rotation, this.rotation3d.order ); + this.quaternion.setFromEuler( this.rotation3d ); this.matrix.makeFromPositionQuaternionScale( this.position, this.quaternion, this.scale ); this.matrixWorldNeedsUpdate = true; diff --git a/test/unit/math/Quaternion.js b/test/unit/math/Quaternion.js index 4169015d6d4c2c..a9b610eee589ee 100644 --- a/test/unit/math/Quaternion.js +++ b/test/unit/math/Quaternion.js @@ -91,16 +91,16 @@ test( "setFromAxisAngle", function() { }); -test( "setFromEuler/setEulerFromQuaternion", function() { +test( "setFromEuler/setFromQuaternion", function() { var angles = [ new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ) ]; // ensure euler conversion to/from Quaternion matches. for( var i = 0; i < orders.length; i ++ ) { for( var j = 0; j < angles.length; j ++ ) { - var eulers2 = new THREE.Vector3().setEulerFromQuaternion( new THREE.Quaternion().setFromEuler( angles[j], orders[i] ), orders[i] ); - - ok( eulers2.distanceTo( angles[j] ) < 0.001, "Passed!" ); + var eulers2 = new THREE.Euler().setFromQuaternion( new THREE.Quaternion().setFromEuler( new THREE.Euler( angles[j].x, angles[j].y, angles[j].z, orders[i] ) ), orders[i] ); + var newAngle = new THREE.Vector3( eulers2.x, eulers2.y, eulers2.z ); + ok( newAngle.distanceTo( angles[j] ) < 0.001, "Passed!" ); } } diff --git a/test/unit/unittests_sources.html b/test/unit/unittests_sources.html index 5ea767d7012539..7c8394d01310f2 100644 --- a/test/unit/unittests_sources.html +++ b/test/unit/unittests_sources.html @@ -17,6 +17,7 @@ + diff --git a/utils/build/includes/common.json b/utils/build/includes/common.json index c48bf4afbe8275..30e23ad26a0fa0 100644 --- a/utils/build/includes/common.json +++ b/utils/build/includes/common.json @@ -5,6 +5,7 @@ "src/math/Vector2.js", "src/math/Vector3.js", "src/math/Vector4.js", + "src/math/Euler.js", "src/math/Line3.js", "src/math/Box2.js", "src/math/Box3.js", diff --git a/utils/build/includes/math.json b/utils/build/includes/math.json index edc72b914acb92..8a1c7c9ae1c555 100644 --- a/utils/build/includes/math.json +++ b/utils/build/includes/math.json @@ -5,6 +5,7 @@ "src/math/Vector2.js", "src/math/Vector3.js", "src/math/Vector4.js", + "src/math/Euler.js", "src/math/Line3.js", "src/math/Box2.js", "src/math/Box3.js",