Skip to content

Instantly share code, notes, and snippets.

@addisonj
Created July 27, 2011 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save addisonj/1110534 to your computer and use it in GitHub Desktop.
Save addisonj/1110534 to your computer and use it in GitHub Desktop.
App.Draw.findNode = function(e) {
var mousePos = new THREE.Vector3(0, 0, 1),
r,
matrix;
mousePos.x = (e.clientX / window.innerWidth) * 2 - 1;
mousePos.y = (e.clientY / window.innerHeight) * 2 + 1;
mousePos.z = 1;
r = new THREE.Ray();
r.origin = mousePos.clone();
matrix = this.camera.matrixWorld.clone();
matrix.multiplySelf(THREE.Matrix4.makeInvert(this.camera.projectionMatrix));
matrix.multiplyVector3(r.origin);
r.direction = r.origin.clone().subSelf(this.camera.position);
var c = THREE.Collisions.rayCastNearest(r);
return c;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment