Game Development Reference

In-Depth Information

class Box : public Primitive

{

public:

Vector3 halfSize;

};

where
halfSize
gives the extent of the box along each axis. The total size of the box

alongeachaxisistwicethisvalue,asshowninfigure13.11.

The vertices of the box are then given as follows:

Vector3 vertices[8] =

{

Vector3(-halfSize.x -halfSize.y -halfSize.z),

Vector3(-halfSize.x -halfSize.y +halfSize.z),

Vector3(-halfSize.x +halfSize.y -halfSize.z),

Vector3(-halfSize.x +halfSize.y +halfSize.z),

Vector3(+halfSize.x -halfSize.y -halfSize.z),

Vector3(+halfSize.x -halfSize.y +halfSize.z),

Vector3(+halfSize.x +halfSize.y -halfSize.z),

Vector3(+halfSize.x +halfSize.y +halfSize.z)

};

for (unsigned i = 0; i < 8; i++)

{

vertices[i] = offset * vertices[i];

}

where
offset
is the rotation and translation matrix from the
Primitive
class.

The overall algorithm simply generates each vertex in turn and tests it against the

plane, adding a contact if necessary. The full algorithm is quite repetitive, so I won't

duplicate it here. You can find it on the CD.

F
IGURE
13.11

The half-sizes of a box.