|
@@ -13,20 +13,19 @@
|
|
|
|
|
|
THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
|
|
|
|
|
|
- this.elements = new Float32Array( 16 );
|
|
|
+ var te = this.elements = new Float32Array( 16 );
|
|
|
|
|
|
- this.set(
|
|
|
+ // TODO: if n11 is undefined, then just set to identity, otherwise copy all other values into matrix
|
|
|
+ // we should not support semi specification of Matrix4, it is just weird.
|
|
|
|
|
|
- ( n11 !== undefined ) ? n11 : 1, n12 || 0, n13 || 0, n14 || 0,
|
|
|
- n21 || 0, ( n22 !== undefined ) ? n22 : 1, n23 || 0, n24 || 0,
|
|
|
- n31 || 0, n32 || 0, ( n33 !== undefined ) ? n33 : 1, n34 || 0,
|
|
|
- n41 || 0, n42 || 0, n43 || 0, ( n44 !== undefined ) ? n44 : 1
|
|
|
-
|
|
|
- );
|
|
|
+ te[0] = ( n11 !== undefined ) ? n11 : 1; te[4] = n12 || 0; te[8] = n13 || 0; te[12] = n14 || 0;
|
|
|
+ te[1] = n21 || 0; te[5] = ( n22 !== undefined ) ? n22 : 1; te[9] = n23 || 0; te[13] = n24 || 0;
|
|
|
+ te[2] = n31 || 0; te[6] = n32 || 0; te[10] = ( n33 !== undefined ) ? n33 : 1; te[14] = n34 || 0;
|
|
|
+ te[3] = n41 || 0; te[7] = n42 || 0; te[11] = n43 || 0; te[15] = ( n44 !== undefined ) ? n44 : 1;
|
|
|
|
|
|
};
|
|
|
|
|
|
-THREE.Matrix4.prototype = {
|
|
|
+THREE.extend( THREE.Matrix4.prototype, {
|
|
|
|
|
|
constructor: THREE.Matrix4,
|
|
|
|
|
@@ -212,41 +211,45 @@ THREE.Matrix4.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- lookAt: function ( eye, target, up ) {
|
|
|
+ lookAt: function() {
|
|
|
|
|
|
- var te = this.elements;
|
|
|
+ var x = new THREE.Vector3(),
|
|
|
+ y = new THREE.Vector3(),
|
|
|
+ z = new THREE.Vector3();
|
|
|
+
|
|
|
+ return function ( eye, target, up ) {
|
|
|
|
|
|
- var x = THREE.Matrix4.__v1;
|
|
|
- var y = THREE.Matrix4.__v2;
|
|
|
- var z = THREE.Matrix4.__v3;
|
|
|
+ var te = this.elements;
|
|
|
+
|
|
|
+ z.subVectors( eye, target ).normalize();
|
|
|
|
|
|
- z.subVectors( eye, target ).normalize();
|
|
|
+ if ( z.length() === 0 ) {
|
|
|
|
|
|
- if ( z.length() === 0 ) {
|
|
|
+ z.z = 1;
|
|
|
|
|
|
- z.z = 1;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ x.crossVectors( up, z ).normalize();
|
|
|
|
|
|
- x.crossVectors( up, z ).normalize();
|
|
|
+ if ( x.length() === 0 ) {
|
|
|
|
|
|
- if ( x.length() === 0 ) {
|
|
|
+ z.x += 0.0001;
|
|
|
+ x.crossVectors( up, z ).normalize();
|
|
|
|
|
|
- z.x += 0.0001;
|
|
|
- x.crossVectors( up, z ).normalize();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ y.crossVectors( z, x );
|
|
|
|
|
|
- y.crossVectors( z, x );
|
|
|
|
|
|
+ te[0] = x.x; te[4] = y.x; te[8] = z.x;
|
|
|
+ te[1] = x.y; te[5] = y.y; te[9] = z.y;
|
|
|
+ te[2] = x.z; te[6] = y.z; te[10] = z.z;
|
|
|
|
|
|
- te[0] = x.x; te[4] = y.x; te[8] = z.x;
|
|
|
- te[1] = x.y; te[5] = y.y; te[9] = z.y;
|
|
|
- te[2] = x.z; te[6] = y.z; te[10] = z.z;
|
|
|
+ return this;
|
|
|
|
|
|
- return this;
|
|
|
+ };
|
|
|
|
|
|
- },
|
|
|
+ }(),
|
|
|
|
|
|
multiply: function ( m, n ) {
|
|
|
|
|
@@ -343,27 +346,31 @@ THREE.Matrix4.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- multiplyVector3Array: function ( a ) {
|
|
|
+ multiplyVector3Array: function() {
|
|
|
|
|
|
- var tmp = THREE.Matrix4.__v1;
|
|
|
+ var v1 = new THREE.Vector3();
|
|
|
+
|
|
|
+ return function ( a ) {
|
|
|
|
|
|
- for ( var i = 0, il = a.length; i < il; i += 3 ) {
|
|
|
+ for ( var i = 0, il = a.length; i < il; i += 3 ) {
|
|
|
|
|
|
- tmp.x = a[ i ];
|
|
|
- tmp.y = a[ i + 1 ];
|
|
|
- tmp.z = a[ i + 2 ];
|
|
|
+ v1.x = a[ i ];
|
|
|
+ v1.y = a[ i + 1 ];
|
|
|
+ v1.z = a[ i + 2 ];
|
|
|
|
|
|
- tmp.applyProjection( this );
|
|
|
+ v1.applyProjection( this );
|
|
|
|
|
|
- a[ i ] = tmp.x;
|
|
|
- a[ i + 1 ] = tmp.y;
|
|
|
- a[ i + 2 ] = tmp.z;
|
|
|
+ a[ i ] = v1.x;
|
|
|
+ a[ i + 1 ] = v1.y;
|
|
|
+ a[ i + 2 ] = v1.z;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- return a;
|
|
|
+ return a;
|
|
|
|
|
|
- },
|
|
|
+ };
|
|
|
+
|
|
|
+ }(),
|
|
|
|
|
|
rotateAxis: function ( v ) {
|
|
|
|
|
@@ -501,12 +508,18 @@ THREE.Matrix4.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- getPosition: function () {
|
|
|
+ getPosition: function() {
|
|
|
|
|
|
- var te = this.elements;
|
|
|
- return THREE.Matrix4.__v1.set( te[12], te[13], te[14] );
|
|
|
+ var v1 = new THREE.Vector3();
|
|
|
+
|
|
|
+ return function () {
|
|
|
|
|
|
- },
|
|
|
+ var te = this.elements;
|
|
|
+ return v1.set( te[12], te[13], te[14] );
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ }(),
|
|
|
|
|
|
setPosition: function ( v ) {
|
|
|
|
|
@@ -520,26 +533,44 @@ THREE.Matrix4.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- getColumnX: function () {
|
|
|
+ getColumnX: function() {
|
|
|
|
|
|
- var te = this.elements;
|
|
|
- return THREE.Matrix4.__v1.set( te[0], te[1], te[2] );
|
|
|
+ var v1 = new THREE.Vector3();
|
|
|
+
|
|
|
+ return function () {
|
|
|
|
|
|
- },
|
|
|
+ var te = this.elements;
|
|
|
+ return v1.set( te[0], te[1], te[2] );
|
|
|
|
|
|
- getColumnY: function () {
|
|
|
+ };
|
|
|
|
|
|
- var te = this.elements;
|
|
|
- return THREE.Matrix4.__v1.set( te[4], te[5], te[6] );
|
|
|
+ }(),
|
|
|
|
|
|
- },
|
|
|
+ getColumnY: function() {
|
|
|
+
|
|
|
+ var v1 = new THREE.Vector3();
|
|
|
+
|
|
|
+ return function () {
|
|
|
+
|
|
|
+ var te = this.elements;
|
|
|
+ return v1.set( te[4], te[5], te[6] );
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ }(),
|
|
|
|
|
|
getColumnZ: function() {
|
|
|
|
|
|
- var te = this.elements;
|
|
|
- return THREE.Matrix4.__v1.set( te[8], te[9], te[10] );
|
|
|
+ var v1 = new THREE.Vector3();
|
|
|
+
|
|
|
+ return function() {
|
|
|
|
|
|
- },
|
|
|
+ var te = this.elements;
|
|
|
+ return v1.set( te[8], te[9], te[10] );
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ }(),
|
|
|
|
|
|
getInverse: function ( m, throwOnInvertible ) {
|
|
|
|
|
@@ -596,75 +627,83 @@ THREE.Matrix4.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- compose: function ( translation, rotation, scale ) {
|
|
|
+ compose: function() {
|
|
|
|
|
|
- var te = this.elements;
|
|
|
- var mRotation = THREE.Matrix4.__m1;
|
|
|
- var mScale = THREE.Matrix4.__m2;
|
|
|
+ var mRotation = new THREE.Matrix4(),
|
|
|
+ mScale = new THREE.Matrix4();
|
|
|
+
|
|
|
+ return function ( translation, rotation, scale ) {
|
|
|
|
|
|
- mRotation.identity();
|
|
|
- mRotation.setRotationFromQuaternion( rotation );
|
|
|
+ var te = this.elements;
|
|
|
+
|
|
|
+ mRotation.identity();
|
|
|
+ mRotation.setRotationFromQuaternion( rotation );
|
|
|
|
|
|
- mScale.makeScale( scale.x, scale.y, scale.z );
|
|
|
+ mScale.makeScale( scale.x, scale.y, scale.z );
|
|
|
|
|
|
- this.multiplyMatrices( mRotation, mScale );
|
|
|
+ this.multiplyMatrices( mRotation, mScale );
|
|
|
|
|
|
- te[12] = translation.x;
|
|
|
- te[13] = translation.y;
|
|
|
- te[14] = translation.z;
|
|
|
+ te[12] = translation.x;
|
|
|
+ te[13] = translation.y;
|
|
|
+ te[14] = translation.z;
|
|
|
|
|
|
- return this;
|
|
|
+ return this;
|
|
|
|
|
|
- },
|
|
|
+ };
|
|
|
|
|
|
- decompose: function ( translation, rotation, scale ) {
|
|
|
+ }(),
|
|
|
|
|
|
- var te = this.elements;
|
|
|
+ decompose: function() {
|
|
|
|
|
|
- // grab the axis vectors
|
|
|
- var x = THREE.Matrix4.__v1;
|
|
|
- var y = THREE.Matrix4.__v2;
|
|
|
- var z = THREE.Matrix4.__v3;
|
|
|
+ var x = new THREE.Vector3(),
|
|
|
+ y = new THREE.Vector3(),
|
|
|
+ z = new THREE.Vector3(),
|
|
|
+ matrix = new THREE.Matrix4();
|
|
|
+
|
|
|
+ return function ( translation, rotation, scale ) {
|
|
|
|
|
|
- x.set( te[0], te[1], te[2] );
|
|
|
- y.set( te[4], te[5], te[6] );
|
|
|
- z.set( te[8], te[9], te[10] );
|
|
|
+ var te = this.elements;
|
|
|
|
|
|
- translation = ( translation instanceof THREE.Vector3 ) ? translation : new THREE.Vector3();
|
|
|
- rotation = ( rotation instanceof THREE.Quaternion ) ? rotation : new THREE.Quaternion();
|
|
|
- scale = ( scale instanceof THREE.Vector3 ) ? scale : new THREE.Vector3();
|
|
|
+ // grab the axis vectors
|
|
|
+ x.set( te[0], te[1], te[2] );
|
|
|
+ y.set( te[4], te[5], te[6] );
|
|
|
+ z.set( te[8], te[9], te[10] );
|
|
|
|
|
|
- scale.x = x.length();
|
|
|
- scale.y = y.length();
|
|
|
- scale.z = z.length();
|
|
|
+ translation = ( translation instanceof THREE.Vector3 ) ? translation : new THREE.Vector3();
|
|
|
+ rotation = ( rotation instanceof THREE.Quaternion ) ? rotation : new THREE.Quaternion();
|
|
|
+ scale = ( scale instanceof THREE.Vector3 ) ? scale : new THREE.Vector3();
|
|
|
|
|
|
- translation.x = te[12];
|
|
|
- translation.y = te[13];
|
|
|
- translation.z = te[14];
|
|
|
+ scale.x = x.length();
|
|
|
+ scale.y = y.length();
|
|
|
+ scale.z = z.length();
|
|
|
|
|
|
- // scale the rotation part
|
|
|
+ translation.x = te[12];
|
|
|
+ translation.y = te[13];
|
|
|
+ translation.z = te[14];
|
|
|
|
|
|
- var matrix = THREE.Matrix4.__m1;
|
|
|
+ // scale the rotation part
|
|
|
+
|
|
|
+ matrix.copy( this );
|
|
|
|
|
|
- matrix.copy( this );
|
|
|
+ matrix.elements[0] /= scale.x;
|
|
|
+ matrix.elements[1] /= scale.x;
|
|
|
+ matrix.elements[2] /= scale.x;
|
|
|
|
|
|
- matrix.elements[0] /= scale.x;
|
|
|
- matrix.elements[1] /= scale.x;
|
|
|
- matrix.elements[2] /= scale.x;
|
|
|
+ matrix.elements[4] /= scale.y;
|
|
|
+ matrix.elements[5] /= scale.y;
|
|
|
+ matrix.elements[6] /= scale.y;
|
|
|
|
|
|
- matrix.elements[4] /= scale.y;
|
|
|
- matrix.elements[5] /= scale.y;
|
|
|
- matrix.elements[6] /= scale.y;
|
|
|
+ matrix.elements[8] /= scale.z;
|
|
|
+ matrix.elements[9] /= scale.z;
|
|
|
+ matrix.elements[10] /= scale.z;
|
|
|
|
|
|
- matrix.elements[8] /= scale.z;
|
|
|
- matrix.elements[9] /= scale.z;
|
|
|
- matrix.elements[10] /= scale.z;
|
|
|
+ rotation.setFromRotationMatrix( matrix );
|
|
|
|
|
|
- rotation.setFromRotationMatrix( matrix );
|
|
|
+ return [ translation, rotation, scale ];
|
|
|
|
|
|
- return [ translation, rotation, scale ];
|
|
|
+ };
|
|
|
|
|
|
- },
|
|
|
+ }(),
|
|
|
|
|
|
extractPosition: function ( m ) {
|
|
|
|
|
@@ -679,34 +718,36 @@ THREE.Matrix4.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- extractRotation: function ( m ) {
|
|
|
+ extractRotation: function() {
|
|
|
|
|
|
- var te = this.elements;
|
|
|
- var me = m.elements;
|
|
|
+ var v1 = new THREE.Vector3();
|
|
|
+
|
|
|
+ return function ( m ) {
|
|
|
|
|
|
- var vector = THREE.Matrix4.__v1;
|
|
|
+ var te = this.elements;
|
|
|
+ var me = m.elements;
|
|
|
|
|
|
- var scaleX = 1 / vector.set( me[0], me[1], me[2] ).length();
|
|
|
- var scaleY = 1 / vector.set( me[4], me[5], me[6] ).length();
|
|
|
- var scaleZ = 1 / vector.set( me[8], me[9], me[10] ).length();
|
|
|
+ var scaleX = 1 / v1.set( me[0], me[1], me[2] ).length();
|
|
|
+ var scaleY = 1 / v1.set( me[4], me[5], me[6] ).length();
|
|
|
+ var scaleZ = 1 / v1.set( me[8], me[9], me[10] ).length();
|
|
|
|
|
|
- te[0] = me[0] * scaleX;
|
|
|
- te[1] = me[1] * scaleX;
|
|
|
- te[2] = me[2] * scaleX;
|
|
|
+ te[0] = me[0] * scaleX;
|
|
|
+ te[1] = me[1] * scaleX;
|
|
|
+ te[2] = me[2] * scaleX;
|
|
|
|
|
|
- te[4] = me[4] * scaleY;
|
|
|
- te[5] = me[5] * scaleY;
|
|
|
- te[6] = me[6] * scaleY;
|
|
|
+ te[4] = me[4] * scaleY;
|
|
|
+ te[5] = me[5] * scaleY;
|
|
|
+ te[6] = me[6] * scaleY;
|
|
|
|
|
|
- te[8] = me[8] * scaleZ;
|
|
|
- te[9] = me[9] * scaleZ;
|
|
|
- te[10] = me[10] * scaleZ;
|
|
|
+ te[8] = me[8] * scaleZ;
|
|
|
+ te[9] = me[9] * scaleZ;
|
|
|
+ te[10] = me[10] * scaleZ;
|
|
|
|
|
|
- return this;
|
|
|
+ return this;
|
|
|
|
|
|
- },
|
|
|
+ };
|
|
|
|
|
|
- //
|
|
|
+ }(),
|
|
|
|
|
|
translate: function ( v ) {
|
|
|
|
|
@@ -904,8 +945,6 @@ THREE.Matrix4.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- //
|
|
|
-
|
|
|
makeTranslation: function ( x, y, z ) {
|
|
|
|
|
|
this.set(
|
|
@@ -1076,11 +1115,4 @@ THREE.Matrix4.prototype = {
|
|
|
|
|
|
}
|
|
|
|
|
|
-};
|
|
|
-
|
|
|
-THREE.Matrix4.__v1 = new THREE.Vector3();
|
|
|
-THREE.Matrix4.__v2 = new THREE.Vector3();
|
|
|
-THREE.Matrix4.__v3 = new THREE.Vector3();
|
|
|
-
|
|
|
-THREE.Matrix4.__m1 = new THREE.Matrix4();
|
|
|
-THREE.Matrix4.__m2 = new THREE.Matrix4();
|
|
|
+} );
|