Game Development Reference
In-Depth Information
simulating. This might be the ground, the walls of a level, or any other immovable
object. We could represent these as objects of infinite mass, but it would be a waste of
time: by definition they never move.
If we have a collision between one object and some piece of immovable scenery,
then we can't calculate the separating velocity in terms of the vector between the loca-
tion of each object: we only have one object. In other words we can't use the ( p a
p b )
term in equation 7.2; we need to replace it.
The ( p a
p b ) term gives us the direction in which the separating velocity is occur-
ring. The separating velocity is calculated by the dot product of the relative velocity
of the two objects and this term. If we don't have two objects, we can ask that the
direction be given to us explicitly. It is the direction in which the two objects are col-
liding and is usually called the “collision normal” or “contact normal.” Because it is a
direction, the vector should always have a magnitude of 1.
In cases where we have two particles colliding, the contact normal will always be
given by
( p a
p b )
By convention we always give the contact normal from object a 's perspective. In this
case, from a 's perspective, the contact is incoming from b ,soweuse p a
n
=
p b .Togive
the direction of collision from b 's point of view we could simply multiply by
1. In
practice we don't do this explicitly, but factor this inversion into the code used to
calculate the separating velocity for b . You'll notice this in the code we implement
later in the chapter: a minus sign appears in b 's calculations.
When a particle is colliding with the ground, we only have an object a (the parti-
cle) and no object b .Inthiscasefromobject a 's perspective, the contact normal will
be
0
1
0
n
=
assuming that the ground is level at the point of collision.
When we leave particles and begin to work with full rigid bodies, having an ex-
plicit contact normal becomes crucial even for inter-object collisions. Without pre-
empting later chapters, figure 7.1 gives a taste of the situation we might come across.
Here the two colliding objects, by virtue of their shapes, have a contact normal in
almost exactly the opposite direction from that we'd expect if we simply considered
their locations. The objects arch over each other, and the contact is acting to prevent
them from moving apart rather than keeping them together. At the end of this chap-
ter we'll look at similar situations for particles, which can be used to represent rods
and other stiff connections.
With the correct contact normal, equation 7.2 becomes
p a ˙
˙
v s =
(
p b )
·
n
[7.4]
Search Nedrilad ::




Custom Search