|
@@ -102,60 +102,6 @@ THREE.Matrix4.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- multiplyVector3: function ( v ) {
|
|
|
-
|
|
|
- var vx = v.x, vy = v.y, vz = v.z,
|
|
|
- d = 1 / ( this.n41 * vx + this.n42 * vy + this.n43 * vz + this.n44 );
|
|
|
-
|
|
|
- v.x = ( this.n11 * vx + this.n12 * vy + this.n13 * vz + this.n14 ) * d;
|
|
|
- v.y = ( this.n21 * vx + this.n22 * vy + this.n23 * vz + this.n24 ) * d;
|
|
|
- v.z = ( this.n31 * vx + this.n32 * vy + this.n33 * vz + this.n34 ) * d;
|
|
|
-
|
|
|
- return v;
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- multiplyVector4: function ( v ) {
|
|
|
-
|
|
|
- var vx = v.x, vy = v.y, vz = v.z, vw = v.w;
|
|
|
-
|
|
|
- v.x = this.n11 * vx + this.n12 * vy + this.n13 * vz + this.n14 * vw;
|
|
|
- v.y = this.n21 * vx + this.n22 * vy + this.n23 * vz + this.n24 * vw;
|
|
|
- v.z = this.n31 * vx + this.n32 * vy + this.n33 * vz + this.n34 * vw;
|
|
|
- v.w = this.n41 * vx + this.n42 * vy + this.n43 * vz + this.n44 * vw;
|
|
|
-
|
|
|
- return v;
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- rotateAxis: function ( v ) {
|
|
|
-
|
|
|
- var vx = v.x, vy = v.y, vz = v.z;
|
|
|
-
|
|
|
- v.x = vx * this.n11 + vy * this.n12 + vz * this.n13;
|
|
|
- v.y = vx * this.n21 + vy * this.n22 + vz * this.n23;
|
|
|
- v.z = vx * this.n31 + vy * this.n32 + vz * this.n33;
|
|
|
-
|
|
|
- v.normalize();
|
|
|
-
|
|
|
- return v;
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- crossVector: function ( a ) {
|
|
|
-
|
|
|
- var v = new THREE.Vector4();
|
|
|
-
|
|
|
- v.x = this.n11 * a.x + this.n12 * a.y + this.n13 * a.z + this.n14 * a.w;
|
|
|
- v.y = this.n21 * a.x + this.n22 * a.y + this.n23 * a.z + this.n24 * a.w;
|
|
|
- v.z = this.n31 * a.x + this.n32 * a.y + this.n33 * a.z + this.n34 * a.w;
|
|
|
-
|
|
|
- v.w = ( a.w ) ? this.n41 * a.x + this.n42 * a.y + this.n43 * a.z + this.n44 * a.w : 1;
|
|
|
-
|
|
|
- return v;
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
multiply: function ( a, b ) {
|
|
|
|
|
|
var a11 = a.n11, a12 = a.n12, a13 = a.n13, a14 = a.n14,
|
|
@@ -192,6 +138,12 @@ THREE.Matrix4.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
+ multiplySelf: function ( m ) {
|
|
|
+
|
|
|
+ return this.multiply( this, m );
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
multiplyToArray: function ( a, b, r ) {
|
|
|
|
|
|
this.multiply( a, b );
|
|
@@ -205,14 +157,6 @@ THREE.Matrix4.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- multiplySelf: function ( m ) {
|
|
|
-
|
|
|
- this.multiply( this, m );
|
|
|
-
|
|
|
- return this;
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
multiplyScalar: function ( s ) {
|
|
|
|
|
|
this.n11 *= s; this.n12 *= s; this.n13 *= s; this.n14 *= s;
|
|
@@ -224,6 +168,60 @@ THREE.Matrix4.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
+ multiplyVector3: function ( v ) {
|
|
|
+
|
|
|
+ var vx = v.x, vy = v.y, vz = v.z,
|
|
|
+ d = 1 / ( this.n41 * vx + this.n42 * vy + this.n43 * vz + this.n44 );
|
|
|
+
|
|
|
+ v.x = ( this.n11 * vx + this.n12 * vy + this.n13 * vz + this.n14 ) * d;
|
|
|
+ v.y = ( this.n21 * vx + this.n22 * vy + this.n23 * vz + this.n24 ) * d;
|
|
|
+ v.z = ( this.n31 * vx + this.n32 * vy + this.n33 * vz + this.n34 ) * d;
|
|
|
+
|
|
|
+ return v;
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ multiplyVector4: function ( v ) {
|
|
|
+
|
|
|
+ var vx = v.x, vy = v.y, vz = v.z, vw = v.w;
|
|
|
+
|
|
|
+ v.x = this.n11 * vx + this.n12 * vy + this.n13 * vz + this.n14 * vw;
|
|
|
+ v.y = this.n21 * vx + this.n22 * vy + this.n23 * vz + this.n24 * vw;
|
|
|
+ v.z = this.n31 * vx + this.n32 * vy + this.n33 * vz + this.n34 * vw;
|
|
|
+ v.w = this.n41 * vx + this.n42 * vy + this.n43 * vz + this.n44 * vw;
|
|
|
+
|
|
|
+ return v;
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ rotateAxis: function ( v ) {
|
|
|
+
|
|
|
+ var vx = v.x, vy = v.y, vz = v.z;
|
|
|
+
|
|
|
+ v.x = vx * this.n11 + vy * this.n12 + vz * this.n13;
|
|
|
+ v.y = vx * this.n21 + vy * this.n22 + vz * this.n23;
|
|
|
+ v.z = vx * this.n31 + vy * this.n32 + vz * this.n33;
|
|
|
+
|
|
|
+ v.normalize();
|
|
|
+
|
|
|
+ return v;
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ crossVector: function ( a ) {
|
|
|
+
|
|
|
+ var v = new THREE.Vector4();
|
|
|
+
|
|
|
+ v.x = this.n11 * a.x + this.n12 * a.y + this.n13 * a.z + this.n14 * a.w;
|
|
|
+ v.y = this.n21 * a.x + this.n22 * a.y + this.n23 * a.z + this.n24 * a.w;
|
|
|
+ v.z = this.n31 * a.x + this.n32 * a.y + this.n33 * a.z + this.n34 * a.w;
|
|
|
+
|
|
|
+ v.w = ( a.w ) ? this.n41 * a.x + this.n42 * a.y + this.n43 * a.z + this.n44 * a.w : 1;
|
|
|
+
|
|
|
+ return v;
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
determinant: function () {
|
|
|
|
|
|
var n11 = this.n11, n12 = this.n12, n13 = this.n13, n14 = this.n14,
|
|
@@ -448,7 +446,7 @@ THREE.Matrix4.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- setPosition: function( v ) {
|
|
|
+ setPosition: function ( v ) {
|
|
|
|
|
|
this.n14 = v.x;
|
|
|
this.n24 = v.y;
|
|
@@ -458,58 +456,58 @@ THREE.Matrix4.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- getPosition: function() {
|
|
|
+ getPosition: function () {
|
|
|
|
|
|
- if ( ! this.position ) {
|
|
|
-
|
|
|
- this.position = new THREE.Vector3();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- this.position.set( this.n14, this.n24, this.n34 );
|
|
|
-
|
|
|
- return this.position;
|
|
|
+ return THREE.Matrix4.__v1.set( this.n14, this.n24, this.n34 );
|
|
|
|
|
|
},
|
|
|
|
|
|
- getColumnX: function() {
|
|
|
-
|
|
|
- if ( ! this.columnX ) {
|
|
|
+ getColumnX: function () {
|
|
|
|
|
|
- this.columnX = new THREE.Vector3();
|
|
|
+ return THREE.Matrix4.__v1.set( this.n11, this.n21, this.n31 );
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- this.columnX.set( this.n11, this.n21, this.n31 );
|
|
|
-
|
|
|
- return this.columnX;
|
|
|
},
|
|
|
|
|
|
- getColumnY: function() {
|
|
|
+ getColumnY: function () {
|
|
|
|
|
|
- if ( ! this.columnY ) {
|
|
|
+ return THREE.Matrix4.__v1.set( this.n12, this.n22, this.n32 );
|
|
|
|
|
|
- this.columnY = new THREE.Vector3();
|
|
|
-
|
|
|
- }
|
|
|
+ },
|
|
|
|
|
|
- this.columnY.set( this.n12, this.n22, this.n32 );
|
|
|
+ getColumnZ: function() {
|
|
|
|
|
|
- return this.columnY;
|
|
|
+ return THREE.Matrix4.__v1.set( this.n13, this.n23, this.n33 );
|
|
|
|
|
|
},
|
|
|
|
|
|
- getColumnZ: function() {
|
|
|
+ getInverse: function ( m ) {
|
|
|
|
|
|
- if ( ! this.columnZ ) {
|
|
|
+ // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
|
|
|
|
|
|
- this.columnZ = new THREE.Vector3();
|
|
|
+ var n11 = m.n11, n12 = m.n12, n13 = m.n13, n14 = m.n14,
|
|
|
+ n21 = m.n21, n22 = m.n22, n23 = m.n23, n24 = m.n24,
|
|
|
+ n31 = m.n31, n32 = m.n32, n33 = m.n33, n34 = m.n34,
|
|
|
+ n41 = m.n41, n42 = m.n42, n43 = m.n43, n44 = m.n44;
|
|
|
|
|
|
- }
|
|
|
+ this.n11 = n23*n34*n42 - n24*n33*n42 + n24*n32*n43 - n22*n34*n43 - n23*n32*n44 + n22*n33*n44;
|
|
|
+ this.n12 = n14*n33*n42 - n13*n34*n42 - n14*n32*n43 + n12*n34*n43 + n13*n32*n44 - n12*n33*n44;
|
|
|
+ this.n13 = n13*n24*n42 - n14*n23*n42 + n14*n22*n43 - n12*n24*n43 - n13*n22*n44 + n12*n23*n44;
|
|
|
+ this.n14 = n14*n23*n32 - n13*n24*n32 - n14*n22*n33 + n12*n24*n33 + n13*n22*n34 - n12*n23*n34;
|
|
|
+ this.n21 = n24*n33*n41 - n23*n34*n41 - n24*n31*n43 + n21*n34*n43 + n23*n31*n44 - n21*n33*n44;
|
|
|
+ this.n22 = n13*n34*n41 - n14*n33*n41 + n14*n31*n43 - n11*n34*n43 - n13*n31*n44 + n11*n33*n44;
|
|
|
+ this.n23 = n14*n23*n41 - n13*n24*n41 - n14*n21*n43 + n11*n24*n43 + n13*n21*n44 - n11*n23*n44;
|
|
|
+ this.n24 = n13*n24*n31 - n14*n23*n31 + n14*n21*n33 - n11*n24*n33 - n13*n21*n34 + n11*n23*n34;
|
|
|
+ this.n31 = n22*n34*n41 - n24*n32*n41 + n24*n31*n42 - n21*n34*n42 - n22*n31*n44 + n21*n32*n44;
|
|
|
+ this.n32 = n14*n32*n41 - n12*n34*n41 - n14*n31*n42 + n11*n34*n42 + n12*n31*n44 - n11*n32*n44;
|
|
|
+ this.n33 = n13*n24*n41 - n14*n22*n41 + n14*n21*n42 - n11*n24*n42 - n12*n21*n44 + n11*n22*n44;
|
|
|
+ this.n34 = n14*n22*n31 - n12*n24*n31 - n14*n21*n32 + n11*n24*n32 + n12*n21*n34 - n11*n22*n34;
|
|
|
+ this.n41 = n23*n32*n41 - n22*n33*n41 - n23*n31*n42 + n21*n33*n42 + n22*n31*n43 - n21*n32*n43;
|
|
|
+ this.n42 = n12*n33*n41 - n13*n32*n41 + n13*n31*n42 - n11*n33*n42 - n12*n31*n43 + n11*n32*n43;
|
|
|
+ this.n43 = n13*n22*n41 - n12*n23*n41 - n13*n21*n42 + n11*n23*n42 + n12*n21*n43 - n11*n22*n43;
|
|
|
+ this.n44 = n12*n23*n31 - n13*n22*n31 + n13*n21*n32 - n11*n23*n32 - n12*n21*n33 + n11*n22*n33;
|
|
|
+ this.multiplyScalar( 1 / m.determinant() );
|
|
|
|
|
|
- this.columnZ.set( this.n13, this.n23, this.n33 );
|
|
|
-
|
|
|
- return this.columnZ;
|
|
|
+ return this;
|
|
|
|
|
|
},
|
|
|
|
|
@@ -742,58 +740,33 @@ THREE.Matrix4.prototype = {
|
|
|
this.n24 = m.n24;
|
|
|
this.n34 = m.n34;
|
|
|
|
|
|
+ return this;
|
|
|
+
|
|
|
},
|
|
|
|
|
|
- extractRotation: function ( m, s ) {
|
|
|
+ extractRotation: function ( m ) {
|
|
|
|
|
|
- var invScaleX = 1 / s.x, invScaleY = 1 / s.y, invScaleZ = 1 / s.z;
|
|
|
+ var vector = THREE.Matrix4.__v1;
|
|
|
|
|
|
- this.n11 = m.n11 * invScaleX;
|
|
|
- this.n21 = m.n21 * invScaleX;
|
|
|
- this.n31 = m.n31 * invScaleX;
|
|
|
+ var scaleX = 1 / vector.set( m.n11, m.n21, m.n31 ).length();
|
|
|
+ var scaleY = 1 / vector.set( m.n12, m.n22, m.n32 ).length();
|
|
|
+ var scaleZ = 1 / vector.set( m.n13, m.n23, m.n33 ).length();
|
|
|
|
|
|
- this.n12 = m.n12 * invScaleY;
|
|
|
- this.n22 = m.n22 * invScaleY;
|
|
|
- this.n32 = m.n32 * invScaleY;
|
|
|
+ this.n11 = m.n11 * scaleX;
|
|
|
+ this.n21 = m.n21 * scaleX;
|
|
|
+ this.n31 = m.n31 * scaleX;
|
|
|
|
|
|
- this.n13 = m.n13 * invScaleZ;
|
|
|
- this.n23 = m.n23 * invScaleZ;
|
|
|
- this.n33 = m.n33 * invScaleZ;
|
|
|
+ this.n12 = m.n12 * scaleY;
|
|
|
+ this.n22 = m.n22 * scaleY;
|
|
|
+ this.n32 = m.n32 * scaleY;
|
|
|
|
|
|
- }
|
|
|
+ this.n13 = m.n13 * scaleZ;
|
|
|
+ this.n23 = m.n23 * scaleZ;
|
|
|
+ this.n33 = m.n33 * scaleZ;
|
|
|
|
|
|
-};
|
|
|
+ return this;
|
|
|
|
|
|
-THREE.Matrix4.makeInvert = function ( m1, m2 ) {
|
|
|
-
|
|
|
- // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
|
|
|
-
|
|
|
- var n11 = m1.n11, n12 = m1.n12, n13 = m1.n13, n14 = m1.n14,
|
|
|
- n21 = m1.n21, n22 = m1.n22, n23 = m1.n23, n24 = m1.n24,
|
|
|
- n31 = m1.n31, n32 = m1.n32, n33 = m1.n33, n34 = m1.n34,
|
|
|
- n41 = m1.n41, n42 = m1.n42, n43 = m1.n43, n44 = m1.n44;
|
|
|
-
|
|
|
- if ( m2 === undefined ) m2 = new THREE.Matrix4();
|
|
|
-
|
|
|
- m2.n11 = n23*n34*n42 - n24*n33*n42 + n24*n32*n43 - n22*n34*n43 - n23*n32*n44 + n22*n33*n44;
|
|
|
- m2.n12 = n14*n33*n42 - n13*n34*n42 - n14*n32*n43 + n12*n34*n43 + n13*n32*n44 - n12*n33*n44;
|
|
|
- m2.n13 = n13*n24*n42 - n14*n23*n42 + n14*n22*n43 - n12*n24*n43 - n13*n22*n44 + n12*n23*n44;
|
|
|
- m2.n14 = n14*n23*n32 - n13*n24*n32 - n14*n22*n33 + n12*n24*n33 + n13*n22*n34 - n12*n23*n34;
|
|
|
- m2.n21 = n24*n33*n41 - n23*n34*n41 - n24*n31*n43 + n21*n34*n43 + n23*n31*n44 - n21*n33*n44;
|
|
|
- m2.n22 = n13*n34*n41 - n14*n33*n41 + n14*n31*n43 - n11*n34*n43 - n13*n31*n44 + n11*n33*n44;
|
|
|
- m2.n23 = n14*n23*n41 - n13*n24*n41 - n14*n21*n43 + n11*n24*n43 + n13*n21*n44 - n11*n23*n44;
|
|
|
- m2.n24 = n13*n24*n31 - n14*n23*n31 + n14*n21*n33 - n11*n24*n33 - n13*n21*n34 + n11*n23*n34;
|
|
|
- m2.n31 = n22*n34*n41 - n24*n32*n41 + n24*n31*n42 - n21*n34*n42 - n22*n31*n44 + n21*n32*n44;
|
|
|
- m2.n32 = n14*n32*n41 - n12*n34*n41 - n14*n31*n42 + n11*n34*n42 + n12*n31*n44 - n11*n32*n44;
|
|
|
- m2.n33 = n13*n24*n41 - n14*n22*n41 + n14*n21*n42 - n11*n24*n42 - n12*n21*n44 + n11*n22*n44;
|
|
|
- m2.n34 = n14*n22*n31 - n12*n24*n31 - n14*n21*n32 + n11*n24*n32 + n12*n21*n34 - n11*n22*n34;
|
|
|
- m2.n41 = n23*n32*n41 - n22*n33*n41 - n23*n31*n42 + n21*n33*n42 + n22*n31*n43 - n21*n32*n43;
|
|
|
- m2.n42 = n12*n33*n41 - n13*n32*n41 + n13*n31*n42 - n11*n33*n42 - n12*n31*n43 + n11*n32*n43;
|
|
|
- m2.n43 = n13*n22*n41 - n12*n23*n41 - n13*n21*n42 + n11*n23*n42 + n12*n21*n43 - n11*n22*n43;
|
|
|
- m2.n44 = n12*n23*n31 - n13*n22*n31 + n13*n21*n32 - n11*n23*n32 - n12*n21*n33 + n11*n22*n33;
|
|
|
- m2.multiplyScalar( 1 / m1.determinant() );
|
|
|
-
|
|
|
- return m2;
|
|
|
+ }
|
|
|
|
|
|
};
|
|
|
|