Pārlūkot izejas kodu

Combine Vector3.applyMatrix4 and applyProjection

Franklin Ta 8 gadi atpakaļ
vecāks
revīzija
643f292e95
1 mainītis faili ar 12 papildinājumiem un 12 dzēšanām
  1. 12 12
      src/math/Vector3.js

+ 12 - 12
src/math/Vector3.js

@@ -293,14 +293,22 @@ Vector3.prototype = {
 
 	applyMatrix4: function ( m ) {
 
-		// input: THREE.Matrix4 affine matrix
-
 		var x = this.x, y = this.y, z = this.z;
 		var e = m.elements;
 
 		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 ];
+
+		if ( w !== 1 ) {
+
+			var d = 1 / w; // perspective divide
+			this.x *= d;
+			this.y *= d;
+			this.z *= d;
+
+		}
 
 		return this;
 
@@ -308,17 +316,9 @@ Vector3.prototype = {
 
 	applyProjection: function ( m ) {
 
-		// input: THREE.Matrix4 projection matrix
+		console.warn( 'THREE.Vector3: .applyProjection() is deprecated. Use .applyMatrix4( m ) instead.' );
 
-		var x = this.x, y = this.y, z = this.z;
-		var e = m.elements;
-		var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
-
-		this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ]  * z + e[ 12 ] ) * d;
-		this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ]  * z + e[ 13 ] ) * d;
-		this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
-
-		return this;
+		return this.applyMatrix4( m );
 
 	},