Game Development Reference
In-Depth Information
segment and so B is the nearest point on the line segment to P. If both
ends have positive cosines then we can use these cosines to return a
linear ratio. If the cosine at A is large, then the angle is small and the angle
at B nears 90°, then the nearest point to P on the line segment AB must
be near the B end. We sum the two cosine values and set this as the
denominator of a fraction; the numerator becomes the cosine of the start
end. The point P is therefore found as follows.
Assuming that the unit vector in the direction AB is A and the unit vector
in direction BA is B , unit vectors in the direction AP and BP are N and M
respectively. Then
A N
A N + B M
P
= A + AB *
Not a square root in sight, so computationally inexpensive!
Getting down to detail
If the basic bounding box test returns a likely collision, then you may need
to determine whether the collision is actually taking place more precisely.
One technique involves splitting up the mesh into smaller segments. If
you are using a single mesh character driven by animated point sets, then
you are already close to the segmenting you need. Simply check the axis-
aligned bounding boxes for each
segment in the character to see if a
collision is taking place. If this level
of accuracy is still not enough for
your purposes, then you may want,
finally, to get down to the polygon
level to determine if a collision has
occurred.
The standard technique at the
polygon level is to attempt to find a
separating plane between two
objects. If there is a plane between
two objects then clearly they do not
intersect. The first stage in finding
such a plane is to use all the faces
in the collision target as the possi-
ble separating planes. To test
whether a face can act as a sepa-
rating plane, use the dot product of
Figure 13.9 Using segment bounding
boxes.