Game Development Reference
In-Depth Information
So how do we figure out whether two objects have collided? First we need to think about when
to check for collisions. If our objects follow a simple physics model, as discussed in the previous
section, we could check for collisions after we move all our objects for the current frame and
time step.
Bounding Shapes
Once we have the final positions of our objects, we can perform collision testing, which boils
down to testing for overlap. But what is it that overlaps? Each of our objects needs to have
some mathematically defined form or shape that provides bounds for it. The correct term in this
case is bounding shape . Figure 8-8 shows a few choices for bounding shapes.
Figure 8-8. Various bounding shapes around Bob
The properties of the three types of bounding shapes in Figure 8-8 are as follows:
ï?® Triangle mesh : This bounds the object as tightly as possible by
approximating its silhouette with a few triangles. It requires the most storage
space, and it's hard to construct and expensive to test against. It gives the
most precise results, however. We won't necessarily use the same triangles
for rendering, but simply store them for collision detection. The mesh can
be stored as a list of vertices, with each subsequent three vertices forming a
triangle. To conserve memory, we could also use indexed vertex lists.
ï?® Axis-aligned bounding box : This bounds the object via a rectangle that is
axis aligned, which means that the bottom and top edges are always aligned
with the x axis, and the left and right edges are always aligned with the y
axis. This is also fast to test against, but less precise than a triangle mesh.
A bounding box is usually stored in the form of the position of its lower-left
corner, plus its width and height. (In the case of 2D, this is also referred to as
a bounding rectangle .)
ï?® Bounding circle : This bounds the object with the smallest circle that can
contain the object. It's very fast to test against, but it is the least precise
bounding shape. The circle is usually stored in the form of its center position
and its radius.
Every object in our game gets a bounding shape that encloses it, in addition to its position,
scale, and orientation. Of course, we need to adjust the bounding shape's position, scale, and
orientation according to the object's position, scale, and orientation when we move the object,
say, in a physics integration step.
 
Search WWH ::




Custom Search