Pārlūkot izejas kodu

Changed lookAt() functions so they don't overwrite the object matrix. Added quaternion support to Object3D.applyMatrix()

WestLangley 12 gadi atpakaļ
vecāks
revīzija
0aa53f0af9
2 mainītis faili ar 56 papildinājumiem un 30 dzēšanām
  1. 13 10
      src/cameras/Camera.js
  2. 43 20
      src/core/Object3D.js

+ 13 - 10
src/cameras/Camera.js

@@ -1,7 +1,8 @@
 /**
 /**
  * @author mrdoob / http://mrdoob.com/
  * @author mrdoob / http://mrdoob.com/
  * @author mikael emtinger / http://gomo.se/
  * @author mikael emtinger / http://gomo.se/
- */
+ * @author WestLangley / http://github.com/WestLangley
+*/
 
 
 THREE.Camera = function () {
 THREE.Camera = function () {
 
 
@@ -16,24 +17,26 @@ THREE.Camera = function () {
 
 
 THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
 THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
 
 
-THREE.Camera.prototype.lookAt = function ( vector ) {
+THREE.Camera.prototype.lookAt = function () {
 
 
-	// TODO: Add hierarchy support.
+	// This routine does not support cameras with rotated and/or translated parent(s)
 
 
-	this.matrix.lookAt( this.position, vector, this.up );
+	var m1 = new THREE.Matrix4();
 
 
-	if ( this.rotationAutoUpdate === true ) {
+	return function ( vector ) {
 
 
-		if ( this.useQuaternion === false )  {
+		m1.lookAt( this.position, vector, this.up );
 
 
-			this.rotation.setEulerFromRotationMatrix( this.matrix, this.eulerOrder );
+		if ( this.useQuaternion === true )  {
+
+			this.quaternion.setFromRotationMatrix( m1 );
 
 
 		} else {
 		} else {
 
 
-			this.quaternion.copy( this.matrix.decompose()[ 1 ] );
+			this.rotation.setEulerFromRotationMatrix( m1, this.eulerOrder );
 
 
 		}
 		}
 
 
-	}
+	};
 
 
-};
+}();

+ 43 - 20
src/core/Object3D.js

@@ -2,6 +2,7 @@
  * @author mrdoob / http://mrdoob.com/
  * @author mrdoob / http://mrdoob.com/
  * @author mikael emtinger / http://gomo.se/
  * @author mikael emtinger / http://gomo.se/
  * @author alteredq / http://alteredqualia.com/
  * @author alteredq / http://alteredqualia.com/
+ * @author WestLangley / http://github.com/WestLangley
  */
  */
 
 
 THREE.Object3D = function () {
 THREE.Object3D = function () {
@@ -51,18 +52,33 @@ THREE.Object3D.prototype = {
 
 
 	constructor: THREE.Object3D,
 	constructor: THREE.Object3D,
 
 
-	applyMatrix: function ( matrix ) {
+	applyMatrix: function () {
 
 
-		this.matrix.multiplyMatrices( matrix, this.matrix );
+		var m1 = new THREE.Matrix4();
 
 
-		this.scale.getScaleFromMatrix( this.matrix );
+		return function ( matrix ) {
 
 
-		var mat = new THREE.Matrix4().extractRotation( this.matrix );
-		this.rotation.setEulerFromRotationMatrix( mat, this.eulerOrder );
+			this.matrix.multiplyMatrices( matrix, this.matrix );
 
 
-		this.position.getPositionFromMatrix( this.matrix );
+			this.position.getPositionFromMatrix( this.matrix );
 
 
-	},
+			this.scale.getScaleFromMatrix( this.matrix );
+
+			m1.extractRotation( this.matrix );
+
+			if ( this.useQuaternion === true )  {
+
+				this.quaternion.setFromRotationMatrix( m1 );
+
+			} else {
+
+				this.rotation.setEulerFromRotationMatrix( m1, this.eulerOrder );
+
+			}
+
+		}
+
+	}(),
 
 
 	translate: function ( distance, axis ) {
 	translate: function ( distance, axis ) {
 
 
@@ -95,33 +111,41 @@ THREE.Object3D.prototype = {
 
 
 	},
 	},
 
 
-	worldToLocal: function ( vector ) {
+	worldToLocal: function () {
 
 
-		return vector.applyMatrix4( THREE.Object3D.__m1.getInverse( this.matrixWorld ) );
+		var m1 = new THREE.Matrix4();
 
 
-	},
+		return function ( vector ) {
+
+			return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
+
+		};
 
 
-	lookAt: function ( vector ) {
+	}(),
 
 
-		// TODO: Add hierarchy support.
+	lookAt: function () {
 
 
-		this.matrix.lookAt( vector, this.position, this.up );
+		// This routine does not support objects with rotated and/or translated parent(s)
 
 
-		if ( this.rotationAutoUpdate ) {
+		var m1 = new THREE.Matrix4();
 
 
-			if ( this.useQuaternion === false )  {
+		return function ( vector ) {
 
 
-				this.rotation.setEulerFromRotationMatrix( this.matrix, this.eulerOrder );
+			m1.lookAt( vector, this.position, this.up );
+
+			if ( this.useQuaternion === true )  {
+
+				this.quaternion.setFromRotationMatrix( m1 );
 
 
 			} else {
 			} else {
 
 
-				this.quaternion.copy( this.matrix.decompose()[ 1 ] );
+				this.rotation.setEulerFromRotationMatrix( m1, this.eulerOrder );
 
 
 			}
 			}
 
 
-		}
+		};
 
 
-	},
+	}(),
 
 
 	add: function ( object ) {
 	add: function ( object ) {
 
 
@@ -353,7 +377,6 @@ THREE.Object3D.prototype = {
 
 
 };
 };
 
 
-THREE.Object3D.__m1 = new THREE.Matrix4();
 THREE.Object3D.defaultEulerOrder = 'XYZ',
 THREE.Object3D.defaultEulerOrder = 'XYZ',
 
 
 THREE.Object3DIdCount = 0;
 THREE.Object3DIdCount = 0;