Browse Source

Added Matrix3.getNormalMatrix( m ) and Vector3.transformDirection( m )

WestLangley 12 years ago
parent
commit
e998138a39
2 changed files with 28 additions and 1 deletions
  1. 9 1
      src/math/Matrix3.js
  2. 19 0
      src/math/Vector3.js

+ 9 - 1
src/math/Matrix3.js

@@ -166,7 +166,6 @@ THREE.extend( THREE.Matrix3.prototype, {
 
 
 	},
 	},
 
 
-
 	transpose: function () {
 	transpose: function () {
 
 
 		var tmp, m = this.elements;
 		var tmp, m = this.elements;
@@ -179,6 +178,15 @@ THREE.extend( THREE.Matrix3.prototype, {
 
 
 	},
 	},
 
 
+	getNormalMatrix: function ( m ) {
+
+		// input: THREE.Matrix4
+
+		this.getInverse( m ).transpose();
+
+		return this;
+
+	},
 
 
 	transposeIntoArray: function ( r ) {
 	transposeIntoArray: function ( r ) {
 
 

+ 19 - 0
src/math/Vector3.js

@@ -297,6 +297,25 @@ THREE.extend( THREE.Vector3.prototype, {
 
 
 	}(),
 	}(),
 
 
+	transformDirection: function ( m ) {
+
+		// input: THREE.Matrix4 affine matrix
+		// vector interpreted as a direction
+
+		var x = this.x, y = this.y, z = this.z;
+
+		var e = m.elements;
+
+		this.x = e[0] * x + e[4] * y + e[8]  * z;
+		this.y = e[1] * x + e[5] * y + e[9]  * z;
+		this.z = e[2] * x + e[6] * y + e[10] * z;
+
+		this.normalize();
+
+		return this;
+
+	},
+
 	divide: function ( v ) {
 	divide: function ( v ) {
 
 
 		this.x /= v.x;
 		this.x /= v.x;