Skip to content

Commit

Permalink
complete Euler class, update examples, update Object3D, update unit t…
Browse files Browse the repository at this point in the history
…ests.
  • Loading branch information
bhouston committed Apr 30, 2013
1 parent 4ff0959 commit a16a9f6
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 250 deletions.
4 changes: 2 additions & 2 deletions examples/css3d_molecules.html
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/js/controls/FlyControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );


};
Expand Down
16 changes: 8 additions & 8 deletions examples/js/controls/TransformControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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 {

Expand Down Expand Up @@ -431,7 +431,7 @@ THREE.TransformControls = function ( camera, domElement, doc ) {

}

object.rotation.setEulerFromQuaternion( tempQuaternion );
object.rotation.setFromQuaternion( tempQuaternion );

} else if ( this.space == 'world' ) {

Expand Down Expand Up @@ -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" ) {

Expand All @@ -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' ) {

Expand All @@ -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' ) {

Expand All @@ -842,7 +842,7 @@ THREE.TransformControls = function ( camera, domElement, doc ) {

tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );

scope.object.rotation.setEulerFromQuaternion( tempQuaternion );
scope.object.rotation.setFromQuaternion( tempQuaternion );

}

Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_geometry_extrude_splines.html
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_multiple_windows.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

};
Expand Down
2 changes: 1 addition & 1 deletion src/cameras/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ THREE.Camera.prototype.lookAt = function () {

} else {

this.rotation.setEulerFromRotationMatrix( m1, this.eulerOrder );
this.rotation.setFromRotationMatrix( m1, this.rotation.Order );

}

Expand Down
18 changes: 8 additions & 10 deletions src/core/Object3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,7 +74,7 @@ THREE.Object3D.prototype = {

} else {

this.rotation.setEulerFromRotationMatrix( m1, this.eulerOrder );
this.rotation.setFromRotationMatrix( m1, this.rotation.order );

}

Expand All @@ -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 );

}

Expand All @@ -131,7 +130,7 @@ THREE.Object3D.prototype = {

} else {

v1.applyEuler( this.rotation, this.eulerOrder );
v1.applyEuler( this.rotation );

}

Expand Down Expand Up @@ -220,7 +219,7 @@ THREE.Object3D.prototype = {

} else {

this.rotation.setEulerFromRotationMatrix( m1, this.eulerOrder );
this.rotation.setFromRotationMatrix( m1, this.rotation.order );

}

Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
Expand Down
40 changes: 32 additions & 8 deletions src/math/Euler3.js → src/math/Euler.js
Original file line number Diff line number Diff line change
@@ -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 ) {

Expand Down Expand Up @@ -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 );

}

Expand Down
34 changes: 17 additions & 17 deletions src/math/Matrix4.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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 );

Expand Down
Loading

0 comments on commit a16a9f6

Please sign in to comment.