RayPick ?
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 ?
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.
You meen like this :
VectorDotProduct(rayDir, DirectionVector(rayOrigin, ObjOrigin)) ?
(this allways results in -NAN)
VectorDotProduct(rayDir, DirectionVector(rayOrigin, ObjOrigin)) ?
(this allways results in -NAN)
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)
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement