Skip to content

Instantly share code, notes, and snippets.

@trongthanh
Forked from jsermeno/perspectiveProject.js
Created October 18, 2011 04:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save trongthanh/1294618 to your computer and use it in GitHub Desktop.
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
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