Game Development Reference
In-Depth Information
11.4 Bounding Volumes
Sometimes we want to compute a bounding volume of a mesh. Two
common examples of the bounding volumes used are spheres and
boxes. Other examples are cylinders, ellipsoids, lozenges, and capsules.
Figure 11.4 shows a mesh with a bounding sphere and the same mesh
with a bounding box. For this section we work only with bounding
boxes and bounding spheres.
Figure 11.4: A mesh
rendered with its
bounding sphere
and bounding box.
A sphere can be
defined by its center
point and radius. A
box can be defined
by its minimum and
maximum points.
Bounding boxes/spheres are often used to speed up visibility tests and
collision tests, among other things. For example, we can say that a
mesh is not visible if its bounding box/sphere is not visible. A box/
sphere visibility test is much cheaper than individually testing the visi-
bility of each triangle in the mesh. For a collision example, suppose that
a missile is fired in the scene and we want to determine if the missile
hit an object in the scene. Since the objects are made up of triangles,
we could iterate through each triangle of each object and test if the mis-
sile (modeled mathematically by a ray) hit a triangle of the object. This
approach would require many ray/triangle intersection tests one for
each triangle of each object in the scene. A more efficient approach
would be to compute the bounding box/sphere of each mesh and then
do one ray/box or ray/sphere intersection test per object. We can then
say that the object is hit if the ray intersected its bounding volume.
This is a fair approximation; if more precision is necessary, we can use
the ray/box or ray/sphere to quickly reject objects that are obviously
not going to be hit and then apply a more precise test to objects that
have a good chance of being hit. Objects that have a good chance of
being hit are objects whose bounding volumes were hit.
The D3DX library provides functions to calculate the bounding
sphere of a mesh and the bounding box of a mesh. These functions take
an array of vertices as input to compute the bounding sphere or box.
Search WWH ::




Custom Search