mrdoob/three.js — Issue #1061: Ray Picking
Author: renegademaster88
Created: 2012-01-10 13:05:54+00:00
State: open

HI there, i am working on my Reticle, and i want to cast a ray from the center of the screen, and if there is an object under the ray change the color of the reticle.

I have tried using the projector and 2 methods for getting a ray

camera = new THREE.PerspectiveCamera (
50,
SCREEN_WIDTH / SCREEN_HEIGHT,
50,
1e7

);

//Method 1
this.projector = new THREE.Projector();
var vector = new THREE.Vector3(SCREEN_WIDTH/2, SCREEN_HEIGHT/2 ,0.5 );
this.projector.unprojectVector( vector, camera );
vector.subSelf( camera.position );
vector.normalize();
var ray = new THREE.Ray( camera.position, vector );

//Method 2
var screen_pos = new THREE.Vector3( 0.5, -0.5 ,0.5 );
var pick_ray = this.projector.pickingRay(screen_pos,camera);
return pick_ray;

But both seem to return a ray with the incorrect data - the ray should be from the camera coords looking directly down the X axis by default (0,-1,0).

Am i feeding the Vectors the wrong data? What inputs do pickingRay and unprojectVector need?
thanx