Last active
August 29, 2015 14:07
-
-
Save Daniel-Wiedemann/8acc8b089b4fcf0fbe79 to your computer and use it in GitHub Desktop.
Local to World
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var parent = new THREE.Object3d(); | |
| var child = new THREE.Object3d(); | |
| parent.add(child); | |
| parent.position.y = 100; | |
| child.position.y = 200; | |
| // we get 200, because child.position returns us the local position | |
| console.log( child.position.y ); | |
| // we get 300, because child.localToWorld(new THREE.Vector3()) returns us the global position | |
| // the parameter for the localToWorld function is a THREE.Vector3() equal to THREE.Vector3(0,0,0) | |
| console.log( child.localToWorld( new THREE.Vector3() ).y ); | |
| // we get 400, the Vector will be add on the returned Vector. | |
| // Notice: this dosen´t change the position values. | |
| console.log( child.localToWorld( new THREE.Vector3(0,100,0) ).y ); | |
| // we get 300,it´s importend to clone, otherwise you get a Vector with zeros, | |
| // the reason is, that the vector will overriden without clone. | |
| var childPos = child.matrixWorld.getPosition().clone(); | |
| console.log( childPos.y ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment