Odd ray intersect behavior

Started by
-1 comments, last by Oblivion165 13 years, 2 months ago
EDIT: Of course after fighting it for 3 days I figure it out 5 minutes after I post. The correct way to do it was to calculate a direction based off the source and taget vectors.


public Ray CalculateRay(Vector3 src, Vector3 tar)
{
Vector3 direction = (tar - src);
return new Ray(src,direction);
}

[attachment=1346:RayFixed.png]

It looks like a mess but it works on every test I threw at it. Posted this solution incase someone has a similar problem.


............ Original Post:


Hi there, I'm having some odd ray to bounding box intersection issues. I have working picking code and its pixel perfect but when I use rays in this manor, it claims collisions where it shouldn't and doesn't where it should. (Box one the end of the top row should be shadowed by the one to its left)

I'm working on some basic lights and using rays to determine shadows etc.

[attachment=1344:RayOdd.png]

As you can see in this one, the rays start at the top of the box only and goes directly to the light source:
(I am not checking for collision on the origin squares bounding box)

[attachment=1345:RayOdd2.png]

Now to me it looks like the ray intersect is calculating it as if the ray were pointing straight up in the air with no angle. The ones below the top layer collide with the cube above it but ones at the top don't collide with the ones next to them.

I have verified that the bounding boxes are perfectly aligned to each cube and the only thing i can see is that the picking code uses matrix data to align itself. Do i need to adjust the rays for the world matrix or some such? Right now I'm making rays by simply Ray ry = new Ray(SourceVector3, TargetVector3) and that's it.

This topic is closed to new replies.

Advertisement