From e82c1ccd54fa88dbccc280cb3035acdea071fe56 Mon Sep 17 00:00:00 2001 From: ide user ide_gero3 Date: Tue, 10 Apr 2012 16:14:35 +0000 Subject: [PATCH] first update towards typedarray usage in matrices\n This was done with some simple replaces it doesn't work yet --- src/core/Frustum.js | 14 +- src/core/Matrix3.js | 22 +- src/core/Matrix4.js | 592 +++++++++--------- src/core/Projector.js | 6 +- src/core/Quaternion.js | 14 +- src/core/Vector3.js | 18 +- src/extras/controls/RollControls.js | 38 +- src/extras/renderers/AnaglyphWebGLRenderer.js | 12 +- .../renderers/ParallaxBarrierWebGLRenderer.js | 12 +- .../renderers/plugins/LensFlarePlugin.js | 2 +- src/extras/renderers/plugins/SpritePlugin.js | 2 +- src/objects/LOD.js | 2 +- src/renderers/CanvasRenderer.js | 12 +- 13 files changed, 373 insertions(+), 373 deletions(-) diff --git a/src/core/Frustum.js b/src/core/Frustum.js index 1ce0c72650..33c0ac2bf8 100644 --- a/src/core/Frustum.js +++ b/src/core/Frustum.js @@ -23,12 +23,12 @@ THREE.Frustum.prototype.setFromMatrix = function ( m ) { var i, plane, planes = this.planes; - planes[ 0 ].set( m.n41 - m.n11, m.n42 - m.n12, m.n43 - m.n13, m.n44 - m.n14 ); - planes[ 1 ].set( m.n41 + m.n11, m.n42 + m.n12, m.n43 + m.n13, m.n44 + m.n14 ); - planes[ 2 ].set( m.n41 + m.n21, m.n42 + m.n22, m.n43 + m.n23, m.n44 + m.n24 ); - planes[ 3 ].set( m.n41 - m.n21, m.n42 - m.n22, m.n43 - m.n23, m.n44 - m.n24 ); - planes[ 4 ].set( m.n41 - m.n31, m.n42 - m.n32, m.n43 - m.n33, m.n44 - m.n34 ); - planes[ 5 ].set( m.n41 + m.n31, m.n42 + m.n32, m.n43 + m.n33, m.n44 + m.n34 ); + planes[ 0 ].set( m.elements[3] - m.elements[0], m.elements[7] - m.elements[4], m.elements[11] - m.elements[8], m.elements[15] - m.elements[12] ); + planes[ 1 ].set( m.elements[3] + m.elements[0], m.elements[7] + m.elements[4], m.elements[11] + m.elements[8], m.elements[15] + m.elements[12] ); + planes[ 2 ].set( m.elements[3] + m.elements[1], m.elements[7] + m.elements[5], m.elements[11] + m.elements[9], m.elements[15] + m.elements[13] ); + planes[ 3 ].set( m.elements[3] - m.elements[1], m.elements[7] - m.elements[5], m.elements[11] - m.elements[9], m.elements[15] - m.elements[13] ); + planes[ 4 ].set( m.elements[3] - m.elements[2], m.elements[7] - m.elements[6], m.elements[11] - m.elements[10], m.elements[15] - m.elements[14] ); + planes[ 5 ].set( m.elements[3] + m.elements[2], m.elements[7] + m.elements[6], m.elements[11] + m.elements[10], m.elements[15] + m.elements[14] ); for ( i = 0; i < 6; i ++ ) { @@ -49,7 +49,7 @@ THREE.Frustum.prototype.contains = function ( object ) { for ( var i = 0; i < 6; i ++ ) { - distance = planes[ i ].x * matrix.n14 + planes[ i ].y * matrix.n24 + planes[ i ].z * matrix.n34 + planes[ i ].w; + distance = planes[ i ].x * matrix.elements[12] + planes[ i ].y * matrix.elements[13] + planes[ i ].z * matrix.elements[14] + planes[ i ].w; if ( distance <= radius ) return false; } diff --git a/src/core/Matrix3.js b/src/core/Matrix3.js index e8844f16ab..57400f4aa8 100644 --- a/src/core/Matrix3.js +++ b/src/core/Matrix3.js @@ -17,17 +17,17 @@ THREE.Matrix3.prototype = { // input: THREE.Matrix4 // ( based on http://code.google.com/p/webgl-mjs/ ) - var a11 = matrix.n33 * matrix.n22 - matrix.n32 * matrix.n23; - var a21 = - matrix.n33 * matrix.n21 + matrix.n31 * matrix.n23; - var a31 = matrix.n32 * matrix.n21 - matrix.n31 * matrix.n22; - var a12 = - matrix.n33 * matrix.n12 + matrix.n32 * matrix.n13; - var a22 = matrix.n33 * matrix.n11 - matrix.n31 * matrix.n13; - var a32 = - matrix.n32 * matrix.n11 + matrix.n31 * matrix.n12; - var a13 = matrix.n23 * matrix.n12 - matrix.n22 * matrix.n13; - var a23 = - matrix.n23 * matrix.n11 + matrix.n21 * matrix.n13; - var a33 = matrix.n22 * matrix.n11 - matrix.n21 * matrix.n12; - - var det = matrix.n11 * a11 + matrix.n21 * a12 + matrix.n31 * a13; + var a11 = matrix.elements[10] * matrix.elements[5] - matrix.elements[6] * matrix.elements[9]; + var a21 = - matrix.elements[10] * matrix.elements[1] + matrix.elements[2] * matrix.elements[9]; + var a31 = matrix.elements[6] * matrix.elements[1] - matrix.elements[2] * matrix.elements[5]; + var a12 = - matrix.elements[10] * matrix.elements[4] + matrix.elements[6] * matrix.elements[8]; + var a22 = matrix.elements[10] * matrix.elements[0] - matrix.elements[2] * matrix.elements[8]; + var a32 = - matrix.elements[6] * matrix.elements[0] + matrix.elements[2] * matrix.elements[4]; + var a13 = matrix.elements[9] * matrix.elements[4] - matrix.elements[5] * matrix.elements[8]; + var a23 = - matrix.elements[9] * matrix.elements[0] + matrix.elements[1] * matrix.elements[8]; + var a33 = matrix.elements[5] * matrix.elements[0] - matrix.elements[1] * matrix.elements[4]; + + var det = matrix.elements[0] * a11 + matrix.elements[1] * a12 + matrix.elements[2] * a13; // no inverse diff --git a/src/core/Matrix4.js b/src/core/Matrix4.js index 11e1c4d937..3e63efd277 100644 --- a/src/core/Matrix4.js +++ b/src/core/Matrix4.js @@ -28,10 +28,10 @@ THREE.Matrix4.prototype = { set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) { - this.n11 = n11; this.n12 = n12; this.n13 = n13; this.n14 = n14; - this.n21 = n21; this.n22 = n22; this.n23 = n23; this.n24 = n24; - this.n31 = n31; this.n32 = n32; this.n33 = n33; this.n34 = n34; - this.n41 = n41; this.n42 = n42; this.n43 = n43; this.n44 = n44; + this.elements[0] = n11; this.elements[4] = n12; this.elements[8] = n13; this.elements[12] = n14; + this.elements[1] = n21; this.elements[5] = n22; this.elements[9] = n23; this.elements[13] = n24; + this.elements[2] = n31; this.elements[6] = n32; this.elements[10] = n33; this.elements[14] = n34; + this.elements[3] = n41; this.elements[7] = n42; this.elements[11] = n43; this.elements[15] = n44; return this; @@ -56,10 +56,10 @@ THREE.Matrix4.prototype = { this.set( - m.n11, m.n12, m.n13, m.n14, - m.n21, m.n22, m.n23, m.n24, - m.n31, m.n32, m.n33, m.n34, - m.n41, m.n42, m.n43, m.n44 + m.elements[0], m.elements[4], m.elements[8], m.elements[12], + m.elements[1], m.elements[5], m.elements[9], m.elements[13], + m.elements[2], m.elements[6], m.elements[10], m.elements[14], + m.elements[3], m.elements[7], m.elements[11], m.elements[15] ); @@ -93,9 +93,9 @@ THREE.Matrix4.prototype = { y.cross( z, x ); - this.n11 = x.x; this.n12 = y.x; this.n13 = z.x; - this.n21 = x.y; this.n22 = y.y; this.n23 = z.y; - this.n31 = x.z; this.n32 = y.z; this.n33 = z.z; + this.elements[0] = x.x; this.elements[4] = y.x; this.elements[8] = z.x; + this.elements[1] = x.y; this.elements[5] = y.y; this.elements[9] = z.y; + this.elements[2] = x.z; this.elements[6] = y.z; this.elements[10] = z.z; return this; @@ -103,35 +103,35 @@ THREE.Matrix4.prototype = { multiply: function ( a, b ) { - var a11 = a.n11, a12 = a.n12, a13 = a.n13, a14 = a.n14; - var a21 = a.n21, a22 = a.n22, a23 = a.n23, a24 = a.n24; - var a31 = a.n31, a32 = a.n32, a33 = a.n33, a34 = a.n34; - var a41 = a.n41, a42 = a.n42, a43 = a.n43, a44 = a.n44; + var a11 = a.elements[0], a12 = a.elements[4], a13 = a.elements[8], a14 = a.elements[12]; + var a21 = a.elements[1], a22 = a.elements[5], a23 = a.elements[9], a24 = a.elements[13]; + var a31 = a.elements[2], a32 = a.elements[6], a33 = a.elements[10], a34 = a.elements[14]; + var a41 = a.elements[3], a42 = a.elements[7], a43 = a.elements[11], a44 = a.elements[15]; - var b11 = b.n11, b12 = b.n12, b13 = b.n13, b14 = b.n14; - var b21 = b.n21, b22 = b.n22, b23 = b.n23, b24 = b.n24; - var b31 = b.n31, b32 = b.n32, b33 = b.n33, b34 = b.n34; - var b41 = b.n41, b42 = b.n42, b43 = b.n43, b44 = b.n44; + var b11 = b.elements[0], b12 = b.elements[4], b13 = b.elements[8], b14 = b.elements[12]; + var b21 = b.elements[1], b22 = b.elements[5], b23 = b.elements[9], b24 = b.elements[13]; + var b31 = b.elements[2], b32 = b.elements[6], b33 = b.elements[10], b34 = b.elements[14]; + var b41 = b.elements[3], b42 = b.elements[7], b43 = b.elements[11], b44 = b.elements[15]; - this.n11 = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41; - this.n12 = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42; - this.n13 = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43; - this.n14 = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44; + this.elements[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41; + this.elements[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42; + this.elements[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43; + this.elements[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44; - this.n21 = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41; - this.n22 = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42; - this.n23 = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43; - this.n24 = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44; + this.elements[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41; + this.elements[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42; + this.elements[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43; + this.elements[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44; - this.n31 = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41; - this.n32 = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42; - this.n33 = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43; - this.n34 = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44; + this.elements[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41; + this.elements[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42; + this.elements[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43; + this.elements[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44; - this.n41 = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41; - this.n42 = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42; - this.n43 = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43; - this.n44 = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44; + this.elements[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41; + this.elements[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42; + this.elements[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43; + this.elements[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44; return this; @@ -147,10 +147,10 @@ THREE.Matrix4.prototype = { this.multiply( a, b ); - r[ 0 ] = this.n11; r[ 1 ] = this.n21; r[ 2 ] = this.n31; r[ 3 ] = this.n41; - r[ 4 ] = this.n12; r[ 5 ] = this.n22; r[ 6 ] = this.n32; r[ 7 ] = this.n42; - r[ 8 ] = this.n13; r[ 9 ] = this.n23; r[ 10 ] = this.n33; r[ 11 ] = this.n43; - r[ 12 ] = this.n14; r[ 13 ] = this.n24; r[ 14 ] = this.n34; r[ 15 ] = this.n44; + r[ 0 ] = this.elements[0]; r[ 1 ] = this.elements[1]; r[ 2 ] = this.elements[2]; r[ 3 ] = this.elements[3]; + r[ 4 ] = this.elements[4]; r[ 5 ] = this.elements[5]; r[ 6 ] = this.elements[6]; r[ 7 ] = this.elements[7]; + r[ 8 ] = this.elements[8]; r[ 9 ] = this.elements[9]; r[ 10 ] = this.elements[10]; r[ 11 ] = this.elements[11]; + r[ 12 ] = this.elements[12]; r[ 13 ] = this.elements[13]; r[ 14 ] = this.elements[14]; r[ 15 ] = this.elements[15]; return this; @@ -158,10 +158,10 @@ THREE.Matrix4.prototype = { multiplyScalar: function ( s ) { - this.n11 *= s; this.n12 *= s; this.n13 *= s; this.n14 *= s; - this.n21 *= s; this.n22 *= s; this.n23 *= s; this.n24 *= s; - this.n31 *= s; this.n32 *= s; this.n33 *= s; this.n34 *= s; - this.n41 *= s; this.n42 *= s; this.n43 *= s; this.n44 *= s; + this.elements[0] *= s; this.elements[4] *= s; this.elements[8] *= s; this.elements[12] *= s; + this.elements[1] *= s; this.elements[5] *= s; this.elements[9] *= s; this.elements[13] *= s; + this.elements[2] *= s; this.elements[6] *= s; this.elements[10] *= s; this.elements[14] *= s; + this.elements[3] *= s; this.elements[7] *= s; this.elements[11] *= s; this.elements[15] *= s; return this; @@ -170,11 +170,11 @@ THREE.Matrix4.prototype = { multiplyVector3: function ( v ) { var vx = v.x, vy = v.y, vz = v.z; - var d = 1 / ( this.n41 * vx + this.n42 * vy + this.n43 * vz + this.n44 ); + var d = 1 / ( this.elements[3] * vx + this.elements[7] * vy + this.elements[11] * vz + this.elements[15] ); - 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; + v.x = ( this.elements[0] * vx + this.elements[4] * vy + this.elements[8] * vz + this.elements[12] ) * d; + v.y = ( this.elements[1] * vx + this.elements[5] * vy + this.elements[9] * vz + this.elements[13] ) * d; + v.z = ( this.elements[2] * vx + this.elements[6] * vy + this.elements[10] * vz + this.elements[14] ) * d; return v; @@ -184,10 +184,10 @@ THREE.Matrix4.prototype = { 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; + v.x = this.elements[0] * vx + this.elements[4] * vy + this.elements[8] * vz + this.elements[12] * vw; + v.y = this.elements[1] * vx + this.elements[5] * vy + this.elements[9] * vz + this.elements[13] * vw; + v.z = this.elements[2] * vx + this.elements[6] * vy + this.elements[10] * vz + this.elements[14] * vw; + v.w = this.elements[3] * vx + this.elements[7] * vy + this.elements[11] * vz + this.elements[15] * vw; return v; @@ -197,9 +197,9 @@ THREE.Matrix4.prototype = { 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.x = vx * this.elements[0] + vy * this.elements[4] + vz * this.elements[8]; + v.y = vx * this.elements[1] + vy * this.elements[5] + vz * this.elements[9]; + v.z = vx * this.elements[2] + vy * this.elements[6] + vz * this.elements[10]; v.normalize(); @@ -211,11 +211,11 @@ THREE.Matrix4.prototype = { 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.x = this.elements[0] * a.x + this.elements[4] * a.y + this.elements[8] * a.z + this.elements[12] * a.w; + v.y = this.elements[1] * a.x + this.elements[5] * a.y + this.elements[9] * a.z + this.elements[13] * a.w; + v.z = this.elements[2] * a.x + this.elements[6] * a.y + this.elements[10] * a.z + this.elements[14] * a.w; - v.w = ( a.w ) ? this.n41 * a.x + this.n42 * a.y + this.n43 * a.z + this.n44 * a.w : 1; + v.w = ( a.w ) ? this.elements[3] * a.x + this.elements[7] * a.y + this.elements[11] * a.z + this.elements[15] * a.w : 1; return v; @@ -223,10 +223,10 @@ THREE.Matrix4.prototype = { determinant: function () { - var n11 = this.n11, n12 = this.n12, n13 = this.n13, n14 = this.n14; - var n21 = this.n21, n22 = this.n22, n23 = this.n23, n24 = this.n24; - var n31 = this.n31, n32 = this.n32, n33 = this.n33, n34 = this.n34; - var n41 = this.n41, n42 = this.n42, n43 = this.n43, n44 = this.n44; + var n11 = this.elements[0], n12 = this.elements[4], n13 = this.elements[8], n14 = this.elements[12]; + var n21 = this.elements[1], n22 = this.elements[5], n23 = this.elements[9], n24 = this.elements[13]; + var n31 = this.elements[2], n32 = this.elements[6], n33 = this.elements[10], n34 = this.elements[14]; + var n41 = this.elements[3], n42 = this.elements[7], n43 = this.elements[11], n44 = this.elements[15]; //TODO: make this more efficient //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm ) @@ -269,13 +269,13 @@ THREE.Matrix4.prototype = { var tmp; - tmp = this.n21; this.n21 = this.n12; this.n12 = tmp; - tmp = this.n31; this.n31 = this.n13; this.n13 = tmp; - tmp = this.n32; this.n32 = this.n23; this.n23 = tmp; + tmp = this.elements[1]; this.elements[1] = this.elements[4]; this.elements[4] = tmp; + tmp = this.elements[2]; this.elements[2] = this.elements[8]; this.elements[8] = tmp; + tmp = this.elements[6]; this.elements[6] = this.elements[9]; this.elements[9] = tmp; - tmp = this.n41; this.n41 = this.n14; this.n14 = tmp; - tmp = this.n42; this.n42 = this.n24; this.n24 = tmp; - tmp = this.n43; this.n43 = this.n34; this.n34 = tmp; + tmp = this.elements[3]; this.elements[3] = this.elements[12]; this.elements[12] = tmp; + tmp = this.elements[7]; this.elements[7] = this.elements[13]; this.elements[13] = tmp; + tmp = this.elements[11]; this.elements[11] = this.elements[14]; this.elements[14] = tmp; return this; @@ -283,10 +283,10 @@ THREE.Matrix4.prototype = { flattenToArray: function ( flat ) { - flat[ 0 ] = this.n11; flat[ 1 ] = this.n21; flat[ 2 ] = this.n31; flat[ 3 ] = this.n41; - flat[ 4 ] = this.n12; flat[ 5 ] = this.n22; flat[ 6 ] = this.n32; flat[ 7 ] = this.n42; - flat[ 8 ] = this.n13; flat[ 9 ] = this.n23; flat[ 10 ] = this.n33; flat[ 11 ] = this.n43; - flat[ 12 ] = this.n14; flat[ 13 ] = this.n24; flat[ 14 ] = this.n34; flat[ 15 ] = this.n44; + flat[ 0 ] = this.elements[0]; flat[ 1 ] = this.elements[1]; flat[ 2 ] = this.elements[2]; flat[ 3 ] = this.elements[3]; + flat[ 4 ] = this.elements[4]; flat[ 5 ] = this.elements[5]; flat[ 6 ] = this.elements[6]; flat[ 7 ] = this.elements[7]; + flat[ 8 ] = this.elements[8]; flat[ 9 ] = this.elements[9]; flat[ 10 ] = this.elements[10]; flat[ 11 ] = this.elements[11]; + flat[ 12 ] = this.elements[12]; flat[ 13 ] = this.elements[13]; flat[ 14 ] = this.elements[14]; flat[ 15 ] = this.elements[15]; return flat; @@ -294,25 +294,25 @@ THREE.Matrix4.prototype = { flattenToArrayOffset: function( flat, offset ) { - flat[ offset ] = this.n11; - flat[ offset + 1 ] = this.n21; - flat[ offset + 2 ] = this.n31; - flat[ offset + 3 ] = this.n41; + flat[ offset ] = this.elements[0]; + flat[ offset + 1 ] = this.elements[1]; + flat[ offset + 2 ] = this.elements[2]; + flat[ offset + 3 ] = this.elements[3]; - flat[ offset + 4 ] = this.n12; - flat[ offset + 5 ] = this.n22; - flat[ offset + 6 ] = this.n32; - flat[ offset + 7 ] = this.n42; + flat[ offset + 4 ] = this.elements[4]; + flat[ offset + 5 ] = this.elements[5]; + flat[ offset + 6 ] = this.elements[6]; + flat[ offset + 7 ] = this.elements[7]; - flat[ offset + 8 ] = this.n13; - flat[ offset + 9 ] = this.n23; - flat[ offset + 10 ] = this.n33; - flat[ offset + 11 ] = this.n43; + flat[ offset + 8 ] = this.elements[8]; + flat[ offset + 9 ] = this.elements[9]; + flat[ offset + 10 ] = this.elements[10]; + flat[ offset + 11 ] = this.elements[11]; - flat[ offset + 12 ] = this.n14; - flat[ offset + 13 ] = this.n24; - flat[ offset + 14 ] = this.n34; - flat[ offset + 15 ] = this.n44; + flat[ offset + 12 ] = this.elements[12]; + flat[ offset + 13 ] = this.elements[13]; + flat[ offset + 14 ] = this.elements[14]; + flat[ offset + 15 ] = this.elements[15]; return flat; @@ -320,15 +320,15 @@ THREE.Matrix4.prototype = { getPosition: function () { - return THREE.Matrix4.__v1.set( this.n14, this.n24, this.n34 ); + return THREE.Matrix4.__v1.set( this.elements[12], this.elements[13], this.elements[14] ); }, setPosition: function ( v ) { - this.n14 = v.x; - this.n24 = v.y; - this.n34 = v.z; + this.elements[12] = v.x; + this.elements[13] = v.y; + this.elements[14] = v.z; return this; @@ -336,19 +336,19 @@ THREE.Matrix4.prototype = { getColumnX: function () { - return THREE.Matrix4.__v1.set( this.n11, this.n21, this.n31 ); + return THREE.Matrix4.__v1.set( this.elements[0], this.elements[1], this.elements[2] ); }, getColumnY: function () { - return THREE.Matrix4.__v1.set( this.n12, this.n22, this.n32 ); + return THREE.Matrix4.__v1.set( this.elements[4], this.elements[5], this.elements[6] ); }, getColumnZ: function() { - return THREE.Matrix4.__v1.set( this.n13, this.n23, this.n33 ); + return THREE.Matrix4.__v1.set( this.elements[8], this.elements[9], this.elements[10] ); }, @@ -356,27 +356,27 @@ THREE.Matrix4.prototype = { // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm - var n11 = m.n11, n12 = m.n12, n13 = m.n13, n14 = m.n14; - var n21 = m.n21, n22 = m.n22, n23 = m.n23, n24 = m.n24; - var n31 = m.n31, n32 = m.n32, n33 = m.n33, n34 = m.n34; - var 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 = n12*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; + var n11 = m.elements[0], n12 = m.elements[4], n13 = m.elements[8], n14 = m.elements[12]; + var n21 = m.elements[1], n22 = m.elements[5], n23 = m.elements[9], n24 = m.elements[13]; + var n31 = m.elements[2], n32 = m.elements[6], n33 = m.elements[10], n34 = m.elements[14]; + var n41 = m.elements[3], n42 = m.elements[7], n43 = m.elements[11], n44 = m.elements[15]; + + this.elements[0] = n23*n34*n42 - n24*n33*n42 + n24*n32*n43 - n22*n34*n43 - n23*n32*n44 + n22*n33*n44; + this.elements[4] = n14*n33*n42 - n13*n34*n42 - n14*n32*n43 + n12*n34*n43 + n13*n32*n44 - n12*n33*n44; + this.elements[8] = n13*n24*n42 - n14*n23*n42 + n14*n22*n43 - n12*n24*n43 - n13*n22*n44 + n12*n23*n44; + this.elements[12] = n14*n23*n32 - n13*n24*n32 - n14*n22*n33 + n12*n24*n33 + n13*n22*n34 - n12*n23*n34; + this.elements[1] = n24*n33*n41 - n23*n34*n41 - n24*n31*n43 + n21*n34*n43 + n23*n31*n44 - n21*n33*n44; + this.elements[5] = n13*n34*n41 - n14*n33*n41 + n14*n31*n43 - n11*n34*n43 - n13*n31*n44 + n11*n33*n44; + this.elements[9] = n14*n23*n41 - n13*n24*n41 - n14*n21*n43 + n11*n24*n43 + n13*n21*n44 - n11*n23*n44; + this.elements[13] = n13*n24*n31 - n14*n23*n31 + n14*n21*n33 - n11*n24*n33 - n13*n21*n34 + n11*n23*n34; + this.elements[2] = n22*n34*n41 - n24*n32*n41 + n24*n31*n42 - n21*n34*n42 - n22*n31*n44 + n21*n32*n44; + this.elements[6] = n14*n32*n41 - n12*n34*n41 - n14*n31*n42 + n11*n34*n42 + n12*n31*n44 - n11*n32*n44; + this.elements[10] = n12*n24*n41 - n14*n22*n41 + n14*n21*n42 - n11*n24*n42 - n12*n21*n44 + n11*n22*n44; + this.elements[14] = n14*n22*n31 - n12*n24*n31 - n14*n21*n32 + n11*n24*n32 + n12*n21*n34 - n11*n22*n34; + this.elements[3] = n23*n32*n41 - n22*n33*n41 - n23*n31*n42 + n21*n33*n42 + n22*n31*n43 - n21*n32*n43; + this.elements[7] = n12*n33*n41 - n13*n32*n41 + n13*n31*n42 - n11*n33*n42 - n12*n31*n43 + n11*n32*n43; + this.elements[11] = n13*n22*n41 - n12*n23*n41 - n13*n21*n42 + n11*n23*n42 + n12*n21*n43 - n11*n22*n43; + this.elements[15] = n12*n23*n31 - n13*n22*n31 + n13*n21*n32 - n11*n23*n32 - n12*n21*n33 + n11*n22*n33; this.multiplyScalar( 1 / m.determinant() ); return this; @@ -396,102 +396,102 @@ THREE.Matrix4.prototype = { var ce = c * e, cf = c * f, de = d * e, df = d * f; - this.n11 = ce + df * b; - this.n12 = de * b - cf; - this.n13 = a * d; + this.elements[0] = ce + df * b; + this.elements[4] = de * b - cf; + this.elements[8] = a * d; - this.n21 = a * f; - this.n22 = a * e; - this.n23 = - b; + this.elements[1] = a * f; + this.elements[5] = a * e; + this.elements[9] = - b; - this.n31 = cf * b - de; - this.n32 = df + ce * b; - this.n33 = a * c; + this.elements[2] = cf * b - de; + this.elements[6] = df + ce * b; + this.elements[10] = a * c; break; case 'ZXY': var ce = c * e, cf = c * f, de = d * e, df = d * f; - this.n11 = ce - df * b; - this.n12 = - a * f; - this.n13 = de + cf * b; + this.elements[0] = ce - df * b; + this.elements[4] = - a * f; + this.elements[8] = de + cf * b; - this.n21 = cf + de * b; - this.n22 = a * e; - this.n23 = df - ce * b; + this.elements[1] = cf + de * b; + this.elements[5] = a * e; + this.elements[9] = df - ce * b; - this.n31 = - a * d; - this.n32 = b; - this.n33 = a * c; + this.elements[2] = - a * d; + this.elements[6] = b; + this.elements[10] = a * c; break; case 'ZYX': var ae = a * e, af = a * f, be = b * e, bf = b * f; - this.n11 = c * e; - this.n12 = be * d - af; - this.n13 = ae * d + bf; + this.elements[0] = c * e; + this.elements[4] = be * d - af; + this.elements[8] = ae * d + bf; - this.n21 = c * f; - this.n22 = bf * d + ae; - this.n23 = af * d - be; + this.elements[1] = c * f; + this.elements[5] = bf * d + ae; + this.elements[9] = af * d - be; - this.n31 = - d; - this.n32 = b * c; - this.n33 = a * c; + this.elements[2] = - d; + this.elements[6] = b * c; + this.elements[10] = a * c; break; case 'YZX': var ac = a * c, ad = a * d, bc = b * c, bd = b * d; - this.n11 = c * e; - this.n12 = bd - ac * f; - this.n13 = bc * f + ad; + this.elements[0] = c * e; + this.elements[4] = bd - ac * f; + this.elements[8] = bc * f + ad; - this.n21 = f; - this.n22 = a * e; - this.n23 = - b * e; + this.elements[1] = f; + this.elements[5] = a * e; + this.elements[9] = - b * e; - this.n31 = - d * e; - this.n32 = ad * f + bc; - this.n33 = ac - bd * f; + this.elements[2] = - d * e; + this.elements[6] = ad * f + bc; + this.elements[10] = ac - bd * f; break; case 'XZY': var ac = a * c, ad = a * d, bc = b * c, bd = b * d; - this.n11 = c * e; - this.n12 = - f; - this.n13 = d * e; + this.elements[0] = c * e; + this.elements[4] = - f; + this.elements[8] = d * e; - this.n21 = ac * f + bd; - this.n22 = a * e; - this.n23 = ad * f - bc; + this.elements[1] = ac * f + bd; + this.elements[5] = a * e; + this.elements[9] = ad * f - bc; - this.n31 = bc * f - ad; - this.n32 = b * e; - this.n33 = bd * f + ac; + this.elements[2] = bc * f - ad; + this.elements[6] = b * e; + this.elements[10] = bd * f + ac; break; default: // 'XYZ' var ae = a * e, af = a * f, be = b * e, bf = b * f; - this.n11 = c * e; - this.n12 = - c * f; - this.n13 = d; + this.elements[0] = c * e; + this.elements[4] = - c * f; + this.elements[8] = d; - this.n21 = af + be * d; - this.n22 = ae - bf * d; - this.n23 = - b * c; + this.elements[1] = af + be * d; + this.elements[5] = ae - bf * d; + this.elements[9] = - b * c; - this.n31 = bf - ae * d; - this.n32 = be + af * d; - this.n33 = a * c; + this.elements[2] = bf - ae * d; + this.elements[6] = be + af * d; + this.elements[10] = a * c; break; } @@ -509,17 +509,17 @@ THREE.Matrix4.prototype = { var yy = y * y2, yz = y * z2, zz = z * z2; var wx = w * x2, wy = w * y2, wz = w * z2; - this.n11 = 1 - ( yy + zz ); - this.n12 = xy - wz; - this.n13 = xz + wy; + this.elements[0] = 1 - ( yy + zz ); + this.elements[4] = xy - wz; + this.elements[8] = xz + wy; - this.n21 = xy + wz; - this.n22 = 1 - ( xx + zz ); - this.n23 = yz - wx; + this.elements[1] = xy + wz; + this.elements[5] = 1 - ( xx + zz ); + this.elements[9] = yz - wx; - this.n31 = xz - wy; - this.n32 = yz + wx; - this.n33 = 1 - ( xx + yy ); + this.elements[2] = xz - wy; + this.elements[6] = yz + wx; + this.elements[10] = 1 - ( xx + yy ); return this; @@ -537,9 +537,9 @@ THREE.Matrix4.prototype = { this.multiply( mRotation, mScale ); - this.n14 = translation.x; - this.n24 = translation.y; - this.n34 = translation.z; + this.elements[12] = translation.x; + this.elements[13] = translation.y; + this.elements[14] = translation.z; return this; @@ -553,9 +553,9 @@ THREE.Matrix4.prototype = { var y = THREE.Matrix4.__v2; var z = THREE.Matrix4.__v3; - x.set( this.n11, this.n21, this.n31 ); - y.set( this.n12, this.n22, this.n32 ); - z.set( this.n13, this.n23, this.n33 ); + x.set( this.elements[0], this.elements[1], this.elements[2] ); + y.set( this.elements[4], this.elements[5], this.elements[6] ); + z.set( this.elements[8], this.elements[9], this.elements[10] ); translation = ( translation instanceof THREE.Vector3 ) ? translation : new THREE.Vector3(); rotation = ( rotation instanceof THREE.Quaternion ) ? rotation : new THREE.Quaternion(); @@ -565,9 +565,9 @@ THREE.Matrix4.prototype = { scale.y = y.length(); scale.z = z.length(); - translation.x = this.n14; - translation.y = this.n24; - translation.z = this.n34; + translation.x = this.elements[12]; + translation.y = this.elements[13]; + translation.z = this.elements[14]; // scale the rotation part @@ -575,17 +575,17 @@ THREE.Matrix4.prototype = { matrix.copy( this ); - matrix.n11 /= scale.x; - matrix.n21 /= scale.x; - matrix.n31 /= scale.x; + matrix.elements[0] /= scale.x; + matrix.elements[1] /= scale.x; + matrix.elements[2] /= scale.x; - matrix.n12 /= scale.y; - matrix.n22 /= scale.y; - matrix.n32 /= scale.y; + matrix.elements[4] /= scale.y; + matrix.elements[5] /= scale.y; + matrix.elements[6] /= scale.y; - matrix.n13 /= scale.z; - matrix.n23 /= scale.z; - matrix.n33 /= scale.z; + matrix.elements[8] /= scale.z; + matrix.elements[9] /= scale.z; + matrix.elements[10] /= scale.z; rotation.setFromRotationMatrix( matrix ); @@ -595,9 +595,9 @@ THREE.Matrix4.prototype = { extractPosition: function ( m ) { - this.n14 = m.n14; - this.n24 = m.n24; - this.n34 = m.n34; + this.elements[12] = m.elements[12]; + this.elements[13] = m.elements[13]; + this.elements[14] = m.elements[14]; return this; @@ -607,21 +607,21 @@ THREE.Matrix4.prototype = { var vector = THREE.Matrix4.__v1; - 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(); + var scaleX = 1 / vector.set( m.elements[0], m.elements[1], m.elements[2] ).length(); + var scaleY = 1 / vector.set( m.elements[4], m.elements[5], m.elements[6] ).length(); + var scaleZ = 1 / vector.set( m.elements[8], m.elements[9], m.elements[10] ).length(); - this.n11 = m.n11 * scaleX; - this.n21 = m.n21 * scaleX; - this.n31 = m.n31 * scaleX; + this.elements[0] = m.elements[0] * scaleX; + this.elements[1] = m.elements[1] * scaleX; + this.elements[2] = m.elements[2] * scaleX; - this.n12 = m.n12 * scaleY; - this.n22 = m.n22 * scaleY; - this.n32 = m.n32 * scaleY; + this.elements[4] = m.elements[4] * scaleY; + this.elements[5] = m.elements[5] * scaleY; + this.elements[6] = m.elements[6] * scaleY; - this.n13 = m.n13 * scaleZ; - this.n23 = m.n23 * scaleZ; - this.n33 = m.n33 * scaleZ; + this.elements[8] = m.elements[8] * scaleZ; + this.elements[9] = m.elements[9] * scaleZ; + this.elements[10] = m.elements[10] * scaleZ; return this; @@ -633,10 +633,10 @@ THREE.Matrix4.prototype = { var x = v.x, y = v.y, z = v.z; - this.n14 = this.n11 * x + this.n12 * y + this.n13 * z + this.n14; - this.n24 = this.n21 * x + this.n22 * y + this.n23 * z + this.n24; - this.n34 = this.n31 * x + this.n32 * y + this.n33 * z + this.n34; - this.n44 = this.n41 * x + this.n42 * y + this.n43 * z + this.n44; + this.elements[12] = this.elements[0] * x + this.elements[4] * y + this.elements[8] * z + this.elements[12]; + this.elements[13] = this.elements[1] * x + this.elements[5] * y + this.elements[9] * z + this.elements[13]; + this.elements[14] = this.elements[2] * x + this.elements[6] * y + this.elements[10] * z + this.elements[14]; + this.elements[15] = this.elements[3] * x + this.elements[7] * y + this.elements[11] * z + this.elements[15]; return this; @@ -644,26 +644,26 @@ THREE.Matrix4.prototype = { rotateX: function ( angle ) { - var m12 = this.n12; - var m22 = this.n22; - var m32 = this.n32; - var m42 = this.n42; - var m13 = this.n13; - var m23 = this.n23; - var m33 = this.n33; - var m43 = this.n43; + var m12 = this.elements[4]; + var m22 = this.elements[5]; + var m32 = this.elements[6]; + var m42 = this.elements[7]; + var m13 = this.elements[8]; + var m23 = this.elements[9]; + var m33 = this.elements[10]; + var m43 = this.elements[11]; var c = Math.cos( angle ); var s = Math.sin( angle ); - this.n12 = c * m12 + s * m13; - this.n22 = c * m22 + s * m23; - this.n32 = c * m32 + s * m33; - this.n42 = c * m42 + s * m43; + this.elements[4] = c * m12 + s * m13; + this.elements[5] = c * m22 + s * m23; + this.elements[6] = c * m32 + s * m33; + this.elements[7] = c * m42 + s * m43; - this.n13 = c * m13 - s * m12; - this.n23 = c * m23 - s * m22; - this.n33 = c * m33 - s * m32; - this.n43 = c * m43 - s * m42; + this.elements[8] = c * m13 - s * m12; + this.elements[9] = c * m23 - s * m22; + this.elements[10] = c * m33 - s * m32; + this.elements[11] = c * m43 - s * m42; return this; @@ -671,26 +671,26 @@ THREE.Matrix4.prototype = { rotateY: function ( angle ) { - var m11 = this.n11; - var m21 = this.n21; - var m31 = this.n31; - var m41 = this.n41; - var m13 = this.n13; - var m23 = this.n23; - var m33 = this.n33; - var m43 = this.n43; + var m11 = this.elements[0]; + var m21 = this.elements[1]; + var m31 = this.elements[2]; + var m41 = this.elements[3]; + var m13 = this.elements[8]; + var m23 = this.elements[9]; + var m33 = this.elements[10]; + var m43 = this.elements[11]; var c = Math.cos( angle ); var s = Math.sin( angle ); - this.n11 = c * m11 - s * m13; - this.n21 = c * m21 - s * m23; - this.n31 = c * m31 - s * m33; - this.n41 = c * m41 - s * m43; + this.elements[0] = c * m11 - s * m13; + this.elements[1] = c * m21 - s * m23; + this.elements[2] = c * m31 - s * m33; + this.elements[3] = c * m41 - s * m43; - this.n13 = c * m13 + s * m11; - this.n23 = c * m23 + s * m21; - this.n33 = c * m33 + s * m31; - this.n43 = c * m43 + s * m41; + this.elements[8] = c * m13 + s * m11; + this.elements[9] = c * m23 + s * m21; + this.elements[10] = c * m33 + s * m31; + this.elements[11] = c * m43 + s * m41; return this; @@ -698,26 +698,26 @@ THREE.Matrix4.prototype = { rotateZ: function ( angle ) { - var m11 = this.n11; - var m21 = this.n21; - var m31 = this.n31; - var m41 = this.n41; - var m12 = this.n12; - var m22 = this.n22; - var m32 = this.n32; - var m42 = this.n42; + var m11 = this.elements[0]; + var m21 = this.elements[1]; + var m31 = this.elements[2]; + var m41 = this.elements[3]; + var m12 = this.elements[4]; + var m22 = this.elements[5]; + var m32 = this.elements[6]; + var m42 = this.elements[7]; var c = Math.cos( angle ); var s = Math.sin( angle ); - this.n11 = c * m11 + s * m12; - this.n21 = c * m21 + s * m22; - this.n31 = c * m31 + s * m32; - this.n41 = c * m41 + s * m42; + this.elements[0] = c * m11 + s * m12; + this.elements[1] = c * m21 + s * m22; + this.elements[2] = c * m31 + s * m32; + this.elements[3] = c * m41 + s * m42; - this.n12 = c * m12 - s * m11; - this.n22 = c * m22 - s * m21; - this.n32 = c * m32 - s * m31; - this.n42 = c * m42 - s * m41; + this.elements[4] = c * m12 - s * m11; + this.elements[5] = c * m22 - s * m21; + this.elements[6] = c * m32 - s * m31; + this.elements[7] = c * m42 - s * m41; return this; @@ -769,25 +769,25 @@ THREE.Matrix4.prototype = { var r23 = yz - xs; var r33 = zz + (1 - zz) * c; - var m11 = this.n11, m21 = this.n21, m31 = this.n31, m41 = this.n41; - var m12 = this.n12, m22 = this.n22, m32 = this.n32, m42 = this.n42; - var m13 = this.n13, m23 = this.n23, m33 = this.n33, m43 = this.n43; - var m14 = this.n14, m24 = this.n24, m34 = this.n34, m44 = this.n44; + var m11 = this.elements[0], m21 = this.elements[1], m31 = this.elements[2], m41 = this.elements[3]; + var m12 = this.elements[4], m22 = this.elements[5], m32 = this.elements[6], m42 = this.elements[7]; + var m13 = this.elements[8], m23 = this.elements[9], m33 = this.elements[10], m43 = this.elements[11]; + var m14 = this.elements[12], m24 = this.elements[13], m34 = this.elements[14], m44 = this.elements[15]; - this.n11 = r11 * m11 + r21 * m12 + r31 * m13; - this.n21 = r11 * m21 + r21 * m22 + r31 * m23; - this.n31 = r11 * m31 + r21 * m32 + r31 * m33; - this.n41 = r11 * m41 + r21 * m42 + r31 * m43; + this.elements[0] = r11 * m11 + r21 * m12 + r31 * m13; + this.elements[1] = r11 * m21 + r21 * m22 + r31 * m23; + this.elements[2] = r11 * m31 + r21 * m32 + r31 * m33; + this.elements[3] = r11 * m41 + r21 * m42 + r31 * m43; - this.n12 = r12 * m11 + r22 * m12 + r32 * m13; - this.n22 = r12 * m21 + r22 * m22 + r32 * m23; - this.n32 = r12 * m31 + r22 * m32 + r32 * m33; - this.n42 = r12 * m41 + r22 * m42 + r32 * m43; + this.elements[4] = r12 * m11 + r22 * m12 + r32 * m13; + this.elements[5] = r12 * m21 + r22 * m22 + r32 * m23; + this.elements[6] = r12 * m31 + r22 * m32 + r32 * m33; + this.elements[7] = r12 * m41 + r22 * m42 + r32 * m43; - this.n13 = r13 * m11 + r23 * m12 + r33 * m13; - this.n23 = r13 * m21 + r23 * m22 + r33 * m23; - this.n33 = r13 * m31 + r23 * m32 + r33 * m33; - this.n43 = r13 * m41 + r23 * m42 + r33 * m43; + this.elements[8] = r13 * m11 + r23 * m12 + r33 * m13; + this.elements[9] = r13 * m21 + r23 * m22 + r33 * m23; + this.elements[10] = r13 * m31 + r23 * m32 + r33 * m33; + this.elements[11] = r13 * m41 + r23 * m42 + r33 * m43; return this; @@ -797,10 +797,10 @@ THREE.Matrix4.prototype = { var x = v.x, y = v.y, z = v.z; - this.n11 *= x; this.n12 *= y; this.n13 *= z; - this.n21 *= x; this.n22 *= y; this.n23 *= z; - this.n31 *= x; this.n32 *= y; this.n33 *= z; - this.n41 *= x; this.n42 *= y; this.n43 *= z; + this.elements[0] *= x; this.elements[4] *= y; this.elements[8] *= z; + this.elements[1] *= x; this.elements[5] *= y; this.elements[9] *= z; + this.elements[2] *= x; this.elements[6] *= y; this.elements[10] *= z; + this.elements[3] *= x; this.elements[7] *= y; this.elements[11] *= z; return this; @@ -922,10 +922,10 @@ THREE.Matrix4.prototype = { var c = - ( far + near ) / ( far - near ); var d = - 2 * far * near / ( far - near ); - this.n11 = x; this.n12 = 0; this.n13 = a; this.n14 = 0; - this.n21 = 0; this.n22 = y; this.n23 = b; this.n24 = 0; - this.n31 = 0; this.n32 = 0; this.n33 = c; this.n34 = d; - this.n41 = 0; this.n42 = 0; this.n43 = - 1; this.n44 = 0; + this.elements[0] = x; this.elements[4] = 0; this.elements[8] = a; this.elements[12] = 0; + this.elements[1] = 0; this.elements[5] = y; this.elements[9] = b; this.elements[13] = 0; + this.elements[2] = 0; this.elements[6] = 0; this.elements[10] = c; this.elements[14] = d; + this.elements[3] = 0; this.elements[7] = 0; this.elements[11] = - 1; this.elements[15] = 0; return this; @@ -952,10 +952,10 @@ THREE.Matrix4.prototype = { var y = ( top + bottom ) / h; var z = ( far + near ) / p; - this.n11 = 2 / w; this.n12 = 0; this.n13 = 0; this.n14 = -x; - this.n21 = 0; this.n22 = 2 / h; this.n23 = 0; this.n24 = -y; - this.n31 = 0; this.n32 = 0; this.n33 = -2 / p; this.n34 = -z; - this.n41 = 0; this.n42 = 0; this.n43 = 0; this.n44 = 1; + this.elements[0] = 2 / w; this.elements[4] = 0; this.elements[8] = 0; this.elements[12] = -x; + this.elements[1] = 0; this.elements[5] = 2 / h; this.elements[9] = 0; this.elements[13] = -y; + this.elements[2] = 0; this.elements[6] = 0; this.elements[10] = -2 / p; this.elements[14] = -z; + this.elements[3] = 0; this.elements[7] = 0; this.elements[11] = 0; this.elements[15] = 1; return this; @@ -966,10 +966,10 @@ THREE.Matrix4.prototype = { return new THREE.Matrix4( - this.n11, this.n12, this.n13, this.n14, - this.n21, this.n22, this.n23, this.n24, - this.n31, this.n32, this.n33, this.n34, - this.n41, this.n42, this.n43, this.n44 + this.elements[0], this.elements[4], this.elements[8], this.elements[12], + this.elements[1], this.elements[5], this.elements[9], this.elements[13], + this.elements[2], this.elements[6], this.elements[10], this.elements[14], + this.elements[3], this.elements[7], this.elements[11], this.elements[15] ); diff --git a/src/core/Projector.js b/src/core/Projector.js index e86775be1f..862d73b49d 100644 --- a/src/core/Projector.js +++ b/src/core/Projector.js @@ -367,7 +367,7 @@ THREE.Projector = function() { if ( object instanceof THREE.Particle ) { - _vector4.set( objectMatrixWorld.n14, objectMatrixWorld.n24, objectMatrixWorld.n34, 1 ); + _vector4.set( objectMatrixWorld.elements[12], objectMatrixWorld.elements[13], objectMatrixWorld.elements[14], 1 ); _projScreenMatrix.multiplyVector4( _vector4 ); _vector4.z /= _vector4.w; @@ -381,8 +381,8 @@ THREE.Projector = function() { _particle.rotation = object.rotation.z; - _particle.scale.x = object.scale.x * Math.abs( _particle.x - ( _vector4.x + camera.projectionMatrix.n11 ) / ( _vector4.w + camera.projectionMatrix.n14 ) ); - _particle.scale.y = object.scale.y * Math.abs( _particle.y - ( _vector4.y + camera.projectionMatrix.n22 ) / ( _vector4.w + camera.projectionMatrix.n24 ) ); + _particle.scale.x = object.scale.x * Math.abs( _particle.x - ( _vector4.x + camera.projectionMatrix.elements[0] ) / ( _vector4.w + camera.projectionMatrix.elements[12] ) ); + _particle.scale.y = object.scale.y * Math.abs( _particle.y - ( _vector4.y + camera.projectionMatrix.elements[5] ) / ( _vector4.w + camera.projectionMatrix.elements[13] ) ); _particle.material = object.material; diff --git a/src/core/Quaternion.js b/src/core/Quaternion.js index 5b1251de64..1b9690ddff 100644 --- a/src/core/Quaternion.js +++ b/src/core/Quaternion.js @@ -92,13 +92,13 @@ THREE.Quaternion.prototype = { } var absQ = Math.pow( m.determinant(), 1.0 / 3.0 ); - this.w = Math.sqrt( Math.max( 0, absQ + m.n11 + m.n22 + m.n33 ) ) / 2; - this.x = Math.sqrt( Math.max( 0, absQ + m.n11 - m.n22 - m.n33 ) ) / 2; - this.y = Math.sqrt( Math.max( 0, absQ - m.n11 + m.n22 - m.n33 ) ) / 2; - this.z = Math.sqrt( Math.max( 0, absQ - m.n11 - m.n22 + m.n33 ) ) / 2; - this.x = copySign( this.x, ( m.n32 - m.n23 ) ); - this.y = copySign( this.y, ( m.n13 - m.n31 ) ); - this.z = copySign( this.z, ( m.n21 - m.n12 ) ); + this.w = Math.sqrt( Math.max( 0, absQ + m.elements[0] + m.elements[5] + m.elements[10] ) ) / 2; + this.x = Math.sqrt( Math.max( 0, absQ + m.elements[0] - m.elements[5] - m.elements[10] ) ) / 2; + this.y = Math.sqrt( Math.max( 0, absQ - m.elements[0] + m.elements[5] - m.elements[10] ) ) / 2; + this.z = Math.sqrt( Math.max( 0, absQ - m.elements[0] - m.elements[5] + m.elements[10] ) ) / 2; + this.x = copySign( this.x, ( m.elements[6] - m.elements[9] ) ); + this.y = copySign( this.y, ( m.elements[8] - m.elements[2] ) ); + this.z = copySign( this.z, ( m.elements[1] - m.elements[4] ) ); this.normalize(); return this; diff --git a/src/core/Vector3.js b/src/core/Vector3.js index 2d7c65ad2f..a88a82f910 100644 --- a/src/core/Vector3.js +++ b/src/core/Vector3.js @@ -262,9 +262,9 @@ THREE.Vector3.prototype = { getPositionFromMatrix: function ( m ) { - this.x = m.n14; - this.y = m.n24; - this.z = m.n34; + this.x = m.elements[12]; + this.y = m.elements[13]; + this.z = m.elements[14]; return this; @@ -276,9 +276,9 @@ THREE.Vector3.prototype = { var sy = scale ? scale.y : 1; var sz = scale ? scale.z : 1; - var m11 = m.n11 / sx, m12 = m.n12 / sy, m13 = m.n13 / sz; - var m21 = m.n21 / sx, m22 = m.n22 / sy, m23 = m.n23 / sz; - var m33 = m.n33 / sz; + var m11 = m.elements[0] / sx, m12 = m.elements[4] / sy, m13 = m.elements[8] / sz; + var m21 = m.elements[1] / sx, m22 = m.elements[5] / sy, m23 = m.elements[9] / sz; + var m33 = m.elements[10] / sz; this.y = Math.asin( m13 ); @@ -355,9 +355,9 @@ THREE.Vector3.prototype = { getScaleFromMatrix: function ( m ) { - var sx = this.set( m.n11, m.n21, m.n31 ).length(); - var sy = this.set( m.n12, m.n22, m.n32 ).length(); - var sz = this.set( m.n13, m.n23, m.n33 ).length(); + var sx = this.set( m.elements[0], m.elements[1], m.elements[2] ).length(); + var sy = this.set( m.elements[4], m.elements[5], m.elements[6] ).length(); + var sz = this.set( m.elements[8], m.elements[9], m.elements[10] ).length(); this.x = sx; this.y = sy; diff --git a/src/extras/controls/RollControls.js b/src/extras/controls/RollControls.js index 2db065bada..078bf72226 100644 --- a/src/extras/controls/RollControls.js +++ b/src/extras/controls/RollControls.js @@ -89,15 +89,15 @@ THREE.RollControls = function ( object, domElement ) { xTemp.cross( yTemp, zTemp ).normalize(); yTemp.cross( zTemp, xTemp ).normalize(); - this.object.matrix.n11 = xTemp.x; this.object.matrix.n12 = yTemp.x; this.object.matrix.n13 = zTemp.x; - this.object.matrix.n21 = xTemp.y; this.object.matrix.n22 = yTemp.y; this.object.matrix.n23 = zTemp.y; - this.object.matrix.n31 = xTemp.z; this.object.matrix.n32 = yTemp.z; this.object.matrix.n33 = zTemp.z; + this.object.matrix.elements[0] = xTemp.x; this.object.matrix.elements[4] = yTemp.x; this.object.matrix.elements[8] = zTemp.x; + this.object.matrix.elements[1] = xTemp.y; this.object.matrix.elements[5] = yTemp.y; this.object.matrix.elements[9] = zTemp.y; + this.object.matrix.elements[2] = xTemp.z; this.object.matrix.elements[6] = yTemp.z; this.object.matrix.elements[10] = zTemp.z; // calculate roll matrix rollMatrix.identity(); - rollMatrix.n11 = Math.cos( this.roll ); rollMatrix.n12 = -Math.sin( this.roll ); - rollMatrix.n21 = Math.sin( this.roll ); rollMatrix.n22 = Math.cos( this.roll ); + rollMatrix.elements[0] = Math.cos( this.roll ); rollMatrix.elements[4] = -Math.sin( this.roll ); + rollMatrix.elements[1] = Math.sin( this.roll ); rollMatrix.elements[5] = Math.cos( this.roll ); // multiply camera with roll @@ -106,34 +106,34 @@ THREE.RollControls = function ( object, domElement ) { // set position - this.object.matrix.n14 = this.object.position.x; - this.object.matrix.n24 = this.object.position.y; - this.object.matrix.n34 = this.object.position.z; + this.object.matrix.elements[12] = this.object.position.x; + this.object.matrix.elements[13] = this.object.position.y; + this.object.matrix.elements[14] = this.object.position.z; }; this.translateX = function ( distance ) { - this.object.position.x += this.object.matrix.n11 * distance; - this.object.position.y += this.object.matrix.n21 * distance; - this.object.position.z += this.object.matrix.n31 * distance; + this.object.position.x += this.object.matrix.elements[0] * distance; + this.object.position.y += this.object.matrix.elements[1] * distance; + this.object.position.z += this.object.matrix.elements[2] * distance; }; this.translateY = function ( distance ) { - this.object.position.x += this.object.matrix.n12 * distance; - this.object.position.y += this.object.matrix.n22 * distance; - this.object.position.z += this.object.matrix.n32 * distance; + this.object.position.x += this.object.matrix.elements[4] * distance; + this.object.position.y += this.object.matrix.elements[5] * distance; + this.object.position.z += this.object.matrix.elements[6] * distance; }; this.translateZ = function ( distance ) { - this.object.position.x -= this.object.matrix.n13 * distance; - this.object.position.y -= this.object.matrix.n23 * distance; - this.object.position.z -= this.object.matrix.n33 * distance; + this.object.position.x -= this.object.matrix.elements[8] * distance; + this.object.position.y -= this.object.matrix.elements[9] * distance; + this.object.position.z -= this.object.matrix.elements[10] * distance; }; @@ -142,7 +142,7 @@ THREE.RollControls = function ( object, domElement ) { // please note that the amount is NOT degrees, but a scale value - xTemp.set( this.object.matrix.n11, this.object.matrix.n21, this.object.matrix.n31 ); + xTemp.set( this.object.matrix.elements[0], this.object.matrix.elements[1], this.object.matrix.elements[2] ); xTemp.multiplyScalar( amount ); this.forward.subSelf( xTemp ); @@ -154,7 +154,7 @@ THREE.RollControls = function ( object, domElement ) { // please note that the amount is NOT degrees, but a scale value - yTemp.set( this.object.matrix.n12, this.object.matrix.n22, this.object.matrix.n32 ); + yTemp.set( this.object.matrix.elements[4], this.object.matrix.elements[5], this.object.matrix.elements[6] ); yTemp.multiplyScalar( amount ); this.forward.addSelf( yTemp ); diff --git a/src/extras/renderers/AnaglyphWebGLRenderer.js b/src/extras/renderers/AnaglyphWebGLRenderer.js index 6b1be04a12..b5fc95721a 100644 --- a/src/extras/renderers/AnaglyphWebGLRenderer.js +++ b/src/extras/renderers/AnaglyphWebGLRenderer.js @@ -126,16 +126,16 @@ if ( THREE.WebGLRenderer ) { // translate xOffset - eyeRight.n14 = eyeSep; - eyeLeft.n14 = -eyeSep; + eyeRight.elements[12] = eyeSep; + eyeLeft.elements[12] = -eyeSep; // for left eye xmin = -ymax * _aspect + eyeSepOnProjection; xmax = ymax * _aspect + eyeSepOnProjection; - projectionMatrix.n11 = 2 * _near / ( xmax - xmin ); - projectionMatrix.n13 = ( xmax + xmin ) / ( xmax - xmin ); + projectionMatrix.elements[0] = 2 * _near / ( xmax - xmin ); + projectionMatrix.elements[8] = ( xmax + xmin ) / ( xmax - xmin ); _cameraL.projectionMatrix.copy( projectionMatrix ); @@ -144,8 +144,8 @@ if ( THREE.WebGLRenderer ) { xmin = -ymax * _aspect - eyeSepOnProjection; xmax = ymax * _aspect - eyeSepOnProjection; - projectionMatrix.n11 = 2 * _near / ( xmax - xmin ); - projectionMatrix.n13 = ( xmax + xmin ) / ( xmax - xmin ); + projectionMatrix.elements[0] = 2 * _near / ( xmax - xmin ); + projectionMatrix.elements[8] = ( xmax + xmin ) / ( xmax - xmin ); _cameraR.projectionMatrix.copy( projectionMatrix ); diff --git a/src/extras/renderers/ParallaxBarrierWebGLRenderer.js b/src/extras/renderers/ParallaxBarrierWebGLRenderer.js index 8531cb59d0..1ddbd59e64 100644 --- a/src/extras/renderers/ParallaxBarrierWebGLRenderer.js +++ b/src/extras/renderers/ParallaxBarrierWebGLRenderer.js @@ -128,16 +128,16 @@ if ( THREE.WebGLRenderer ) { // translate xOffset - eyeRight.n14 = eyeSep; - eyeLeft.n14 = -eyeSep; + eyeRight.elements[12] = eyeSep; + eyeLeft.elements[12] = -eyeSep; // for left eye xmin = -ymax * _aspect + eyeSepOnProjection; xmax = ymax * _aspect + eyeSepOnProjection; - projectionMatrix.n11 = 2 * _near / ( xmax - xmin ); - projectionMatrix.n13 = ( xmax + xmin ) / ( xmax - xmin ); + projectionMatrix.elements[0] = 2 * _near / ( xmax - xmin ); + projectionMatrix.elements[8] = ( xmax + xmin ) / ( xmax - xmin ); _cameraL.projectionMatrix.copy( projectionMatrix ); @@ -146,8 +146,8 @@ if ( THREE.WebGLRenderer ) { xmin = -ymax * _aspect - eyeSepOnProjection; xmax = ymax * _aspect - eyeSepOnProjection; - projectionMatrix.n11 = 2 * _near / ( xmax - xmin ); - projectionMatrix.n13 = ( xmax + xmin ) / ( xmax - xmin ); + projectionMatrix.elements[0] = 2 * _near / ( xmax - xmin ); + projectionMatrix.elements[8] = ( xmax + xmin ) / ( xmax - xmin ); _cameraR.projectionMatrix.copy( projectionMatrix ); diff --git a/src/extras/renderers/plugins/LensFlarePlugin.js b/src/extras/renderers/plugins/LensFlarePlugin.js index 73ed87956c..94964a9199 100644 --- a/src/extras/renderers/plugins/LensFlarePlugin.js +++ b/src/extras/renderers/plugins/LensFlarePlugin.js @@ -164,7 +164,7 @@ THREE.LensFlarePlugin = function ( ) { flare = flares[ i ]; - tempPosition.set( flare.matrixWorld.n14, flare.matrixWorld.n24, flare.matrixWorld.n34 ); + tempPosition.set( flare.matrixWorld.elements[12], flare.matrixWorld.elements[13], flare.matrixWorld.elements[14] ); camera.matrixWorldInverse.multiplyVector3( tempPosition ); camera.projectionMatrix.multiplyVector3( tempPosition ); diff --git a/src/extras/renderers/plugins/SpritePlugin.js b/src/extras/renderers/plugins/SpritePlugin.js index bf54c270b6..3a2121cf95 100644 --- a/src/extras/renderers/plugins/SpritePlugin.js +++ b/src/extras/renderers/plugins/SpritePlugin.js @@ -130,7 +130,7 @@ THREE.SpritePlugin = function ( ) { if( ! sprite.useScreenCoordinates ) { sprite._modelViewMatrix.multiplyToArray( camera.matrixWorldInverse, sprite.matrixWorld, sprite._modelViewMatrixArray ); - sprite.z = - sprite._modelViewMatrix.n34; + sprite.z = - sprite._modelViewMatrix.elements[14]; } else { diff --git a/src/objects/LOD.js b/src/objects/LOD.js index 51ecc56abf..8978934f67 100644 --- a/src/objects/LOD.js +++ b/src/objects/LOD.js @@ -48,7 +48,7 @@ THREE.LOD.prototype.update = function ( camera ) { camera.matrixWorldInverse.getInverse( camera.matrixWorld ); var inverse = camera.matrixWorldInverse; - var distance = -( inverse.n31 * this.matrixWorld.n14 + inverse.n32 * this.matrixWorld.n24 + inverse.n33 * this.matrixWorld.n34 + inverse.n34 ); + var distance = -( inverse.elements[2] * this.matrixWorld.elements[12] + inverse.elements[6] * this.matrixWorld.elements[13] + inverse.elements[10] * this.matrixWorld.elements[14] + inverse.elements[14] ); this.LODs[ 0 ].object3D.visible = true; diff --git a/src/renderers/CanvasRenderer.js b/src/renderers/CanvasRenderer.js index 2099d5cc60..70d74f154b 100644 --- a/src/renderers/CanvasRenderer.js +++ b/src/renderers/CanvasRenderer.js @@ -544,16 +544,16 @@ THREE.CanvasRenderer = function ( parameters ) { var cameraMatrix = camera.matrixWorldInverse; _vector3.copy( element.vertexNormalsWorld[ uv1 ] ); - _uv1x = ( _vector3.x * cameraMatrix.n11 + _vector3.y * cameraMatrix.n12 + _vector3.z * cameraMatrix.n13 ) * 0.5 + 0.5; - _uv1y = - ( _vector3.x * cameraMatrix.n21 + _vector3.y * cameraMatrix.n22 + _vector3.z * cameraMatrix.n23 ) * 0.5 + 0.5; + _uv1x = ( _vector3.x * cameraMatrix.elements[0] + _vector3.y * cameraMatrix.elements[4] + _vector3.z * cameraMatrix.elements[8] ) * 0.5 + 0.5; + _uv1y = - ( _vector3.x * cameraMatrix.elements[1] + _vector3.y * cameraMatrix.elements[5] + _vector3.z * cameraMatrix.elements[9] ) * 0.5 + 0.5; _vector3.copy( element.vertexNormalsWorld[ uv2 ] ); - _uv2x = ( _vector3.x * cameraMatrix.n11 + _vector3.y * cameraMatrix.n12 + _vector3.z * cameraMatrix.n13 ) * 0.5 + 0.5; - _uv2y = - ( _vector3.x * cameraMatrix.n21 + _vector3.y * cameraMatrix.n22 + _vector3.z * cameraMatrix.n23 ) * 0.5 + 0.5; + _uv2x = ( _vector3.x * cameraMatrix.elements[0] + _vector3.y * cameraMatrix.elements[4] + _vector3.z * cameraMatrix.elements[8] ) * 0.5 + 0.5; + _uv2y = - ( _vector3.x * cameraMatrix.elements[1] + _vector3.y * cameraMatrix.elements[5] + _vector3.z * cameraMatrix.elements[9] ) * 0.5 + 0.5; _vector3.copy( element.vertexNormalsWorld[ uv3 ] ); - _uv3x = ( _vector3.x * cameraMatrix.n11 + _vector3.y * cameraMatrix.n12 + _vector3.z * cameraMatrix.n13 ) * 0.5 + 0.5; - _uv3y = - ( _vector3.x * cameraMatrix.n21 + _vector3.y * cameraMatrix.n22 + _vector3.z * cameraMatrix.n23 ) * 0.5 + 0.5; + _uv3x = ( _vector3.x * cameraMatrix.elements[0] + _vector3.y * cameraMatrix.elements[4] + _vector3.z * cameraMatrix.elements[8] ) * 0.5 + 0.5; + _uv3y = - ( _vector3.x * cameraMatrix.elements[1] + _vector3.y * cameraMatrix.elements[5] + _vector3.z * cameraMatrix.elements[9] ) * 0.5 + 0.5; patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uv1x, _uv1y, _uv2x, _uv2y, _uv3x, _uv3y, material.envMap ); -- GitLab