• Advertisement
Sign in to follow this  

RayPick ?

This topic is 4608 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Before you test any object, do a dot-product between the ray direction and the vector from the ray origin to the object's origin. If the result is less than 0, don't test the object, because it can only intersect the straight-line, not the ray.

Share this post


Link to post
Share on other sites
You meen like this :

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

(this allways results in -NAN)

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
Sign in to follow this  

  • Advertisement