A lot of people don't know, apparently, that you can use an Axis Aligned Bounding Box as an Oriented Bounding Box. The math works out the exact same. The only difference is that you need to transform the corners first using the rotation and translation matrix. Here is some example code:
public static BoundingBox CreateOrientedBoundingBox(Vector3 min, Vector3 max, Matrix transform)
{
Vector3[] corners = new Vector3[]
{
Vector3.TransformCoordinate(new Vector3(min.X, max.Y, max.Z), transform),
Vector3.TransformCoordinate(new Vector3(max.X, max.Y, max.Z), transform),
Vector3.TransformCoordinate(new Vector3(max.X, min.Y, max.Z), transform),
Vector3.TransformCoordinate(new Vector3(min.X, min.Y, max.Z), transform),
Vector3.TransformCoordinate(new Vector3(min.X, max.Y, min.Z), transform),
Vector3.TransformCoordinate(new Vector3(max.X, max.Y, min.Z), transform),
Vector3.TransformCoordinate(new Vector3(max.X, min.Y, min.Z), transform),
Vector3.TransformCoordinate(new Vector3(min.X, min.Y, min.Z), transform)
};
return BoundingBox.FromPoints(corners);
}
Of which a transformation matrix fed into it would be defined as:
Matrix transform = VoidwalkerMath.CreateRotationMatrix(this.Rotation) * Matrix.Translation(this.Location);
Also, for the sake of clarity and completion, I create a rotation matrix as such:
/// <summary>
/// Converts degrees to radians.
/// </summary>
/// <param name="degrees">The angle in degrees.</param>
public static float ToRadians(float degrees)
{
return degrees / 360.0f * TwoPi;
}
/// <summary>
/// Creates a rotation matrix using degrees.
/// </summary>
/// <param name="xDegrees"></param>
/// <param name="yDegrees"></param>
/// <param name="zDegrees"></param>
/// <returns></returns>
public static Matrix CreateRotationMatrix(float xDegrees, float yDegrees, float zDegrees)
{
return
Matrix.RotationX(ToRadians(xDegrees)) *
Matrix.RotationY(ToRadians(yDegrees)) *
Matrix.RotationZ(ToRadians(zDegrees));
}
Then you use it with the same collision tests as a traditional AABB. I currently have this working in my game for Frustum culling. So to alleviate/bust this myth: Yes. An AABB can be used as an OBB; the only difference is how the points are transformed.
Update: Here is a visual example of this. Two Crates. The left one is rotated, the right one is not. Both are AABBS.
