Browse Source

Added Vector3.absoluteToRelative and Vector3.relativeToAbsolute. Thanks to @G3z for the initial suggestion. Thanks to @em for the naming hint. Fixes #1043.

Mr.doob 13 years ago
parent
commit
2c60d40901
1 changed files with 11 additions and 1 deletions
  1. 11 1
      src/core/Vector3.js

+ 11 - 1
src/core/Vector3.js

@@ -255,6 +255,17 @@ THREE.Vector3.prototype = {
 
 	},
 
+	relativeToAbsolute: function ( object ) {
+
+		return object.matrixWorld.multiplyVector3( this.clone() );
+
+	},
+
+	absoluteToRelative: function ( object ) {
+
+		return new THREE.Matrix4().getInverse( object.matrixWorld ).multiplyVector3( this.clone() );
+
+	},
 
 	distanceTo: function ( v ) {
 
@@ -268,7 +279,6 @@ THREE.Vector3.prototype = {
 
 	},
 
-
 	setPositionFromMatrix: function ( m ) {
 
 		this.x = m.n14;