Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 03 Feb 2011
Offline Last Active Jan 31 2013 11:58 PM

#4772577 Odd ray intersect behavior

Posted by Oblivion165 on 10 February 2011 - 04:07 PM

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);

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.


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)


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.