Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

AABB/Frustum test works correctly but using the same method for OBB does not work?!

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

Here I have an AABB/Frustum test to see if an AABB is contained or intersecting a bounding frustum:
        public bool Contains(CD_AxisAlignedBoundingBox aABB)
        {
            for (int i = 0; i < 6; i++)
            {
                // Compute the projection interval radius of b onto L(t) = b.c + t * p.n (calc extents distance relative to plane normal)               
                float r = Math.Abs(aABB.Extents_HalfWidth.X * Plane.Normal.X) + 
                    Math.Abs(aABB.Extents_HalfWidth.Y * Plane.Normal.Y) + 
                    Math.Abs(aABB.Extents_HalfWidth.Z * Plane.Normal.Z);

                // Compute distance of AABB center from plane 
                float distance = Vector3.Dot(Plane.Normal, aABB.Position) + Plane.D;

                if (distance > r)
                {
                    // AABB is outside this plane and therefore is not in the frustum
                    return false;
                }
            }

            // AABB is inside or intersecting the bounding frustum
            return true;
        }

If I use the same principle for an OBB it doesn't work:
        public bool Contains(CD_OrientedBoundingBox oBB)
        {
            for (int i = 0; i < 6; i++)
            {
                // Compute the projection interval radius of b onto L(t) = b.c + t * p.n
                float r = oBB.Extents_HalfWidth.X * Math.Abs(Vector3.Dot(Plane.Normal, oBB.Axis_X)) +
                    oBB.Extents_HalfWidth.Y * Math.Abs(Vector3.Dot(Plane.Normal, oBB.Axis_Y)) +
                    oBB.Extents_HalfWidth.Z * Math.Abs(Vector3.Dot(Plane.Normal, oBB.Axis_Z));

                // Compute the distance of the OBB centre from plane
                float distance = Vector3.Dot(Plane.Normal, oBB.Position) + Plane.D;

                if (distance > r)
                {
                    // OBB is outside this plane and therefore is not in the frustum
                    return false;
                }
            }

            return true;
        }

Can anyone suggest why? Thank you.

Share this post


Link to post
Share on other sites
Advertisement
At first look at least, the code appears to be correct.

In what way is it not working? What is the debugger telling you?

Share this post


Link to post
Share on other sites
Argh, the problem is that my brain is half asleep and I need to go to bed!

Sorry to have posted this, it can be deleted; the problem is solved.

I was testing for containment of the wrong bounding volume (AABB instead of OBB) when drawing the OBB bounding volume.

Yes, I am a tired idiot! :)

Thanks

Share this post


Link to post
Share on other sites
Quote:
How to calculate Axis_X/Axis_Y/Axis_Z of the bounding box for OBB frustum test?
They are the first three rows or columns (depending on convention) of the rotation or transform matrix associated with the OBB. (If the orientation for the OBB is stored in some other form, such as a quaternion or set of Euler angles, you will need to convert to matrix form first and then extract the axes.)

Share this post


Link to post
Share on other sites
Almost: in that example, it would be the first three rows, not the first three columns.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!