Game Development Reference
In-Depth Information
should really become apparent when introducing constraints and coupled rigid
bodies in a moment.
11.3.2 Handling Constraints
We now describe by example howmore complex constraints can be implemented.
Assume that we have two particles that we wish to keep at a fixed distance
from each other, in effect simulating a stick. Just as in the above case, where
collisions were handled by projecting the particles in question out of the offend-
ing obstacles, we carry out a similar procedure here: if a particle invalidates a
constraint after the Verlet time step routine has been called, we simply move the
particle by as little as possible in order to satisfy the constraint once again. In
the case of the stick this means pulling or pushing the particles directly towards
or away from each other (depending on whether their distance is too large or too
small; see Figure 11.1 ) .
For each pair of constrained particle positions x i
and x j
, the following cal-
culations must be carried out:
d = x j x i ,
(11.1)
u = r
||
|| 1 . 0 d ,
(11.2)
d
1
2 u ,
x i
= x i
(11.3)
= x j + 1
x j
2 u ,
(11.4)
where r is the rest length of the stick and u is the missing displacement between
the two particles.
Assume now that we also want the particles to satisfy the cube constraints
discussed in the previous subsection. By running the above code to fix the stick
Distance too large
Correct distance
Distance too small
Figure 11.1. Moving the particles to fix an invalid distance.