# RayPick ?

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

## 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 on other sites
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 on other sites
You meen like this :

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

(this allways results in -NAN)

##### Share on other sites
Quote:
 Original post by MytharYou 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 on other sites
thx, works now :)

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633701
• Total Posts
3013437
×