Jump to content
• Advertisement

OBB-Ray collision

This topic is 3901 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

I have OBB - OBB collision working, but somehow I am having trouble with detecting collision between an OBB and a semi infinite ray. For OBB - ray collision my plan is to transform the ray into the OBB's local space, and then just run simple ray - bounding box collision tests. This is my function that takes a ray and an OBB and should return a ray that run my collision test on:
public static Ray WorldToLocalRay(Ray worldRay, OBB currOBB)
{
Matrix inv = Matrix.Invert(currOBB.getWorld());
Vector3 rayStart = Vector3.Transform(worldRay.Position, inv);
Vector4 rayDir = Vector4.Transform(new Vector4(worldRay.Direction, 0), Matrix.Transpose(inv));
Ray localRay = new Ray(rayStart, new Vector3(rayDir.X, rayDir.Y, rayDir.Z));

return localRay;
}


But it is not working. Any advice would be greatly appreciated. Thanks in advance.

Share this post

Share on other sites
Advertisement
This:
Vector4 rayDir = Vector4.Transform(new Vector4(worldRay.Direction, 0), Matrix.Transpose(inv));
Looks wrong to me.

Is your OBB transform a rigid body transform (i.e. rotation and translation only)? If so, the following should work:
Vector4 rayDir = Vector4.Transform(new Vector4(worldRay.Direction, 0), inv);

Share this post

Share on other sites
Vector4 rayDir = Vector4.Transform(new Vector4(worldRay.Direction, 0), inv);

Did not work for me either. I believe my OBB transform a rigid body transform. The world matrix I am using in the code above is also being used to draw the bounding boxes using vector render.

Also about transforming the ray direction, I was under the impression that if you are transforming a normal you have to use the transpose of the inverse.

Here is the code i am using to draw my bounding boxes which works fine, if it helps:

vectorRender.SetWorldMatrix(myOBB.getWorld());BoundingBox boxd = myBox;boxd.Min -= myOBB.center;boxd.Max -= myOBB.center;vectorRender.DrawBoundingBox(boxd);

Share this post

Share on other sites

• Advertisement
• Advertisement

• Popular Contributors

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 11
• 10
• 13
• 103
• 11
• Forum Statistics

• Total Topics
632976
• Total Posts
3009672
• Who's Online (See full list)

There are no registered users currently online

×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!