Sign in to follow this  

OBB-Ray collision

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


Link to post
Share on other sites
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


Link to 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


Link to post
Share on other sites

This topic is 3592 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this