瀏覽代碼

Fix typo, add a unit test

Franklin Ta 8 年之前
父節點
當前提交
b23734b85a
共有 2 個文件被更改,包括 35 次插入2 次删除
  1. 2 2
      src/math/Vector3.js
  2. 33 0
      test/unit/math/Vector3.js

+ 2 - 2
src/math/Vector3.js

@@ -299,9 +299,9 @@ Vector3.prototype = {
 		this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ]  * z + e[ 12 ];
 		this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ]  * z + e[ 13 ];
 		this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
-		var w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ];
+		var w =  e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ];
 
-		return this.divideScalar( 1 / w );
+		return this.divideScalar( w );
 
 	},
 

+ 33 - 0
test/unit/math/Vector3.js

@@ -344,3 +344,36 @@ test( "equals", function() {
 	ok( a.equals( b ), "Passed!" );
 	ok( b.equals( a ), "Passed!" );
 });
+
+test( "applyMatrix4", function() {
+
+	var a = new THREE.Vector3( x, y, z );
+	var b = new THREE.Vector4( x, y, z, 1 );
+
+	var m = new THREE.Matrix4().makeRotationX( Math.PI );
+	a.applyMatrix4( m );
+	b.applyMatrix4( m );
+	ok( a.x == b.x / b.w, "Passed!" );
+	ok( a.y == b.y / b.w, "Passed!" );
+	ok( a.z == b.z / b.w, "Passed!" );
+
+	m = new THREE.Matrix4().makeTranslation( 3, 2, 1 );
+	a.applyMatrix4( m );
+	b.applyMatrix4( m );
+	ok( a.x == b.x / b.w, "Passed!" );
+	ok( a.y == b.y / b.w, "Passed!" );
+	ok( a.z == b.z / b.w, "Passed!" );
+
+	m = new THREE.Matrix4().set(
+		1, 0, 0, 0,
+		0, 1, 0, 0,
+		0, 0, 1, 0,
+		0, 0, 1, 0
+	);
+	a.applyMatrix4( m );
+	b.applyMatrix4( m );
+	ok( a.x == b.x / b.w, "Passed!" );
+	ok( a.y == b.y / b.w, "Passed!" );
+	ok( a.z == b.z / b.w, "Passed!" );
+
+});