2
0
Эх сурвалжийг харах

@gero3 reported that Matrix4.getInverse() was incorrect when the operand was the same as this. Fixed with unit test.

Ben Houston 12 жил өмнө
parent
commit
3fc64d7577

+ 2 - 2
src/math/Matrix4.js

@@ -638,8 +638,8 @@ THREE.Matrix4.prototype = {
 		te[11] = n13*n22*n41 - n12*n23*n41 - n13*n21*n42 + n11*n23*n42 + n12*n21*n43 - n11*n22*n43;
 		te[15] = n12*n23*n31 - n13*n22*n31 + n13*n21*n32 - n11*n23*n32 - n12*n21*n33 + n11*n22*n33;
 
-		var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 4 ] + me[ 2 ] * te[ 8 ] + me[ 3 ] * te[ 12 ];
-
+		var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
+	
 		if ( det == 0 ) {
 
 			var msg = "Matrix4.getInverse(): can't invert matrix, determinant is 0";

+ 7 - 1
test/unit/math/Matrix4.js

@@ -193,9 +193,15 @@ test( "getInverse", function() {
 		var m = testMatrices[i];
 
 		var mInverse = new THREE.Matrix4().getInverse( m );
+		var mSelfInverse = m.clone();
+		mSelfInverse.getInverse( mSelfInverse );
+
+
+		// self-inverse should the same as inverse
+		ok( matrixEquals4( mSelfInverse, mInverse ), "Passed!" );
 
 		// the determinant of the inverse should be the reciprocal
-		ok( Math.abs( m.determinant() * mInverse.determinant() - 1  ) < 0.0001, "Passed!" );
+		ok( Math.abs( m.determinant() * mInverse.determinant() - 1 ) < 0.0001, "Passed!" );
 
 		var mProduct = new THREE.Matrix4().multiplyMatrices( m, mInverse );