Browse Source

worldToLocal() and localToWorld() coordinates conversion for Object3D.

I struggled with this for quite a while, but I think this should be the right thing - having convenience methods for switching between the scene/world/global/absolute coordinates to the local/child/relative coordinates right with Object3D, which is part of the scene graph, rather than the Vector class.

Related issues: #1752, #1043, commits 025fb6243afed67811ee514e5dc11b382336c67c and baf0f65e1db76cc95e3d1a3cf759861b807fa177
zz85 13 years ago
parent
commit
da0373a746
1 changed files with 14 additions and 0 deletions
  1. 14 0
      src/core/Object3D.js

+ 14 - 0
src/core/Object3D.js

@@ -263,6 +263,20 @@ THREE.Object3D.prototype = {
 
 
 		}
 		}
 
 
+	},
+
+	worldToLocal: function ( vector ) {
+
+		if ( !this.__inverseMatrixWorld ) this.__inverseMatrixWorld = new THREE.Matrix4();
+
+		return this.__inverseMatrixWorld.getInverse( this.matrixWorld ).multiplyVector3( vector );
+
+	},
+
+	localToWorld: function ( vector ) {
+
+		return this.matrixWorld.multiplyVector3( vector );
+
 	}
 	}
 
 
 };
 };