Oriented Bounding Box
An Oriented Bounding Box (OBB), is the 3D equivalent of the 2D oriented rectangle. An OBB is defined by a position, half-extents, and some orientation. There are several ways to store the orientation for a bounding box. One way would be to store a vector which has each component corresponding to the angle of rotation on an axis. A better way is to treat the orientation as a 3D matrix, using the mat3
struct:
Getting ready
We are going to create a new structure to represent an Oriented Bounding Box. This new OBB
structure is going to be composed of a position, half extents, and some orientation. The position and size will be represented by vectors, but the rotation will be stored as a matrix. Storing the rotation as a matrix makes sense because no matter how we store the rotation, to render the OBB it will need to be converted into a matrix at some point.
How to do it
Follow these steps to implement a 3D oriented bounding box:
Declare the new
OBB
structure inGeometry3D.h
...