Browse Source

Implemented @WestLangley Vector3.reflect() from #4340.

Mr.doob 11 years ago
parent
commit
f5b359ced3
1 changed files with 5 additions and 4 deletions
  1. 5 4
      src/math/Vector3.js

+ 5 - 4
src/math/Vector3.js

@@ -689,13 +689,14 @@ THREE.extend( THREE.Vector3.prototype, {
 
 	reflect: function () {
 
-		var v1 = new THREE.Vector3();
+		// reflect incident vector off plane orthogonal to normal
+		// normal is assumed to have unit length
 
-		return function ( vector ) {
+		var v1 = new THREE.Vector3();
 
-		    v1.copy( this ).projectOnVector( vector ).multiplyScalar( 2 );
+		return function ( normal ) {
 
-		    return this.subVectors( v1, this );
+			return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
 
 		}