Sign in to follow this  
Mythar

RayPick ?

Recommended Posts

Hi all, my ray picker works just fine, but I ran into a small problem. Lets say im walking around in a 3D env. and click an object in front of me. I now do a ray (based on the x,y of the screen etc.) BUT as it just happens, there is another object just behind me, that is partly visible. My ray now picks the triangle with the shortest distance, and as the partly visible object behind me has a triangle with the shortest distance, the object behind me is selected, and not the object in front of me, that I was clicking on. I tryed doing a directional vector calc. but i cant get it to work. Dose any have a good idea, of how to make this work ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Mythar
You meen like this :

VectorDotProduct(rayDir, DirectionVector(rayOrigin, ObjOrigin)) ?

(this allways results in -NAN)

A dot product is 3 multiplications and 3 additions. It can't possibly create a NAN unless one of the components of the 2 involved vectors is NAN. From your calculation above, this can happen if DirectionVector tries to normalize a zero-length vector, perhaps (if RayOrigin and ObjOrigin are the exact same). What you do is this:

D3DXVECTOR3 ray_to_object = object_origin - ray_origin;
if(D3DXVec3Dot(&ray_to_object, &ray_direction) < 0)
{
// Ignore object (i.e. return false or something)
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this