ソースを参照

Added some vars. The compiler is already optimising this so there is no point on doing this risky pattern anymore.

Mr.doob 13 年 前
コミット
f4b896e9f4
1 ファイル変更94 行追加94 行削除
  1. 94 94
      src/core/Matrix4.js

+ 94 - 94
src/core/Matrix4.js

@@ -71,7 +71,9 @@ THREE.Matrix4.prototype = {
 
 	lookAt: function ( eye, target, up ) {
 
-		var x = THREE.Matrix4.__v1, y = THREE.Matrix4.__v2, z = THREE.Matrix4.__v3;
+		var x = THREE.Matrix4.__v1;
+		var y = THREE.Matrix4.__v2;
+		var z = THREE.Matrix4.__v3;
 
 		z.sub( eye, target ).normalize();
 
@@ -103,15 +105,15 @@ THREE.Matrix4.prototype = {
 
 	multiply: function ( a, b ) {
 
-		var a11 = a.n11, a12 = a.n12, a13 = a.n13, a14 = a.n14,
-		a21 = a.n21, a22 = a.n22, a23 = a.n23, a24 = a.n24,
-		a31 = a.n31, a32 = a.n32, a33 = a.n33, a34 = a.n34,
-		a41 = a.n41, a42 = a.n42, a43 = a.n43, a44 = a.n44,
+		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;
 
-		b11 = b.n11, b12 = b.n12, b13 = b.n13, b14 = b.n14,
-		b21 = b.n21, b22 = b.n22, b23 = b.n23, b24 = b.n24,
-		b31 = b.n31, b32 = b.n32, b33 = b.n33, b34 = b.n34,
-		b41 = b.n41, b42 = b.n42, b43 = b.n43, b44 = b.n44;
+		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;
 
 		this.n11 = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
 		this.n12 = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
@@ -169,8 +171,8 @@ 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 );
+		var vx = v.x, vy = v.y, vz = v.z;
+		var 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;
@@ -223,10 +225,10 @@ THREE.Matrix4.prototype = {
 
 	determinant: function () {
 
-		var n11 = this.n11, n12 = this.n12, n13 = this.n13, n14 = this.n14,
-		n21 = this.n21, n22 = this.n22, n23 = this.n23, n24 = this.n24,
-		n31 = this.n31, n32 = this.n32, n33 = this.n33, n34 = this.n34,
-		n41 = this.n41, n42 = this.n42, n43 = this.n43, n44 = this.n44;
+		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;
 
 		//TODO: make this more efficient
 		//( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
@@ -355,10 +357,10 @@ 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,
-		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;
+		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;
@@ -384,10 +386,10 @@ THREE.Matrix4.prototype = {
 
 	setRotationFromEuler: function( v, order ) {
 
-		var x = v.x, y = v.y, z = v.z,
-		a = Math.cos( x ), b = Math.sin( x ),
-		c = Math.cos( y ), d = Math.sin( y ),
-		e = Math.cos( z ), f = Math.sin( z );
+		var x = v.x, y = v.y, z = v.z;
+		var a = Math.cos( x ), b = Math.sin( x );
+		var c = Math.cos( y ), d = Math.sin( y );
+		var e = Math.cos( z ), f = Math.sin( z );
 
 		switch ( order ) {
 
@@ -502,11 +504,11 @@ THREE.Matrix4.prototype = {
 
 	setRotationFromQuaternion: function( q ) {
 
-		var x = q.x, y = q.y, z = q.z, w = q.w,
-		x2 = x + x, y2 = y + y, z2 = z + z,
-		xx = x * x2, xy = x * y2, xz = x * z2,
-		yy = y * y2, yz = y * z2, zz = z * z2,
-		wx = w * x2, wy = w * y2, wz = w * z2;
+		var x = q.x, y = q.y, z = q.z, w = q.w;
+		var x2 = x + x, y2 = y + y, z2 = z + z;
+		var xx = x * x2, xy = x * y2, xz = x * z2;
+		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;
@@ -643,16 +645,16 @@ THREE.Matrix4.prototype = {
 
 	rotateX: function ( angle ) {
 
-		var m12 = this.n12,
-			m22 = this.n22,
-			m32 = this.n32,
-			m42 = this.n42,
-			m13 = this.n13,
-			m23 = this.n23,
-			m33 = this.n33,
-			m43 = this.n43,
-			c = Math.cos( angle ),
-			s = Math.sin( 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 c = Math.cos( angle );
+		var s = Math.sin( angle );
 
 		this.n12 = c * m12 + s * m13;
 		this.n22 = c * m22 + s * m23;
@@ -670,16 +672,16 @@ THREE.Matrix4.prototype = {
 
 	rotateY: function ( angle ) {
 
-		var m11 = this.n11,
-			m21 = this.n21,
-			m31 = this.n31,
-			m41 = this.n41,
-			m13 = this.n13,
-			m23 = this.n23,
-			m33 = this.n33,
-			m43 = this.n43,
-			c = Math.cos(angle),
-			s = Math.sin(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 c = Math.cos( angle );
+		var s = Math.sin( angle );
 
 		this.n11 = c * m11 - s * m13;
 		this.n21 = c * m21 - s * m23;
@@ -697,16 +699,16 @@ THREE.Matrix4.prototype = {
 
 	rotateZ: function ( angle ) {
 
-		var m11 = this.n11,
-			m21 = this.n21,
-			m31 = this.n31,
-			m41 = this.n41,
-			m12 = this.n12,
-			m22 = this.n22,
-			m32 = this.n32,
-			m42 = this.n42,
-			c = Math.cos(angle),
-			s = Math.sin(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 c = Math.cos( angle );
+		var s = Math.sin( angle );
 
 		this.n11 = c * m11 + s * m12;
 		this.n21 = c * m21 + s * m22;
@@ -740,42 +742,38 @@ THREE.Matrix4.prototype = {
 
 		}
 
-		var x = axis.x,
-			y = axis.y,
-			z = axis.z,
-			n = Math.sqrt(x * x + y * y + z * z);
+		var x = axis.x, y = axis.y, z = axis.z;
+		var n = Math.sqrt(x * x + y * y + z * z);
 
 		x /= n;
 		y /= n;
 		z /= n;
 
-		var xx = x * x,
-		yy = y * y,
-		zz = z * z,
-		c = Math.cos( angle ),
-		s = Math.sin( angle ),
-		oneMinusCosine = 1 - c,
-		xy = x * y * oneMinusCosine,
-		xz = x * z * oneMinusCosine,
-		yz = y * z * oneMinusCosine,
-		xs = x * s,
-		ys = y * s,
-		zs = z * s,
-
-		r11 = xx + (1 - xx) * c,
-		r21 = xy + zs,
-		r31 = xz - ys,
-		r12 = xy - zs,
-		r22 = yy + (1 - yy) * c,
-		r32 = yz + xs,
-		r13 = xz + ys,
-		r23 = yz - xs,
-		r33 = zz + (1 - zz) * c,
-
-		m11 = this.n11, m21 = this.n21, m31 = this.n31, m41 = this.n41,
-		m12 = this.n12, m22 = this.n22, m32 = this.n32, m42 = this.n42,
-		m13 = this.n13, m23 = this.n23, m33 = this.n33, m43 = this.n43,
-		m14 = this.n14, m24 = this.n24, m34 = this.n34, m44 = this.n44;
+		var xx = x * x, yy = y * y, zz = z * z;
+		var c = Math.cos( angle );
+		var s = Math.sin( angle );
+		var oneMinusCosine = 1 - c;
+		var xy = x * y * oneMinusCosine;
+		var xz = x * z * oneMinusCosine;
+		var yz = y * z * oneMinusCosine;
+		var xs = x * s;
+		var ys = y * s;
+		var zs = z * s;
+
+		var r11 = xx + (1 - xx) * c;
+		var r21 = xy + zs;
+		var r31 = xz - ys;
+		var r12 = xy - zs;
+		var r22 = yy + (1 - yy) * c;
+		var r32 = yz + xs;
+		var r13 = xz + ys;
+		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;
 
 		this.n11 = r11 * m11 + r21 * m12 + r31 * m13;
 		this.n21 = r11 * m21 + r21 * m22 + r31 * m23;
@@ -881,11 +879,11 @@ THREE.Matrix4.prototype = {
 
 		// Based on http://www.gamedev.net/reference/articles/article1199.asp
 
-		var c = Math.cos( angle ),
-		s = Math.sin( angle ),
-		t = 1 - c,
-		x = axis.x, y = axis.y, z = axis.z,
-		tx = t * x, ty = t * y;
+		var c = Math.cos( angle );
+		var s = Math.sin( angle );
+		var t = 1 - c;
+		var x = axis.x, y = axis.y, z = axis.z;
+		var tx = t * x, ty = t * y;
 
 		this.set(
 
@@ -967,10 +965,12 @@ THREE.Matrix4.prototype = {
 	clone: function () {
 
 		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
+
 		);
 
 	}