-
-
Save trongthanh/1294618 to your computer and use it in GitHub Desktop.
Three.js Transform 3D coordinates to screen coordinates and back in perspective projection - http://catchvar.com/threejs-game-transforming-isometric-screen-co
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 | |
projector = new THREE.Projector(), | |
p3D = new THREE.Vector3(25, 15, 9), | |
p2D; | |
p2D = projector.projectVector(p3D, camera); | |
p3D = projector.unprojectVector(p2D, camera); | |
//need extra steps to convert p2D to window's coordinates | |
p2D.x = (p2D.x + 1)/2 * window.innerWidth; | |
p2D.y = - (p2D.y - 1)/2 * window.innerHeight; | |
var popout = document.getElementById('popout'); | |
popout.style.left = p2D.x + 'px'; | |
popout.style.top = p2D.y + 'px'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment