• 14
• 12
• 9
• 10
• 9

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

This topic is 3063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
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 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 on other sites
Hello.
How to calculate Axis_X/Axis_Y/Axis_Z of the bounding box for OBB frustum test?

##### 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.)

Like this:

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