Game Development Reference
After these calculations, the rest of UpdateSimulation is the same as that shown earlier;
the function integrates the equations of motion and renders the scene.
Upon running this simulation, you'll see the linked chain swing down and to the left
and then back and forth until the motion dampens out. You'll also notice there's some
stretch to the springs between the objects that appears to increase as you look from the
lower link to the upper link. This is indeed a non-uniform stretch in the springs, which
makes sense when you consider that the upper spring has more weight, thus more force,
pulling down on it than does the lower spring.
As in this rope example, you can tune the spring and damping constants to minimize
the spring stretch if that gap created by the stretched spring bothers you. You must keep
in mind numerical stability if your springs are too stiff, and here again, you must im‐
plement a robust integrator.
So far we've used springs only to attach objects in a way that keeps the attachment points
together but allows the objects to rotate about the attachment point. This is a so-called
pinned joint . If you want a fixed joint that minimizes the amount of rotation between
the connected objects, you can add another spring to restrain the connected objects'
Figure 13-6 illustrates an example comprising two rigid objects connected at their ends,
forming a ninety-degree angle. The uppermost end of the first object is connected to a
fixed point in space as in our rope and linked-chain examples. Under gravity, the as‐
sembly would rotate and swing around this fixed point. However, unlike the linked-
chain example, the extra spring prevents the lower link from pivoting around the other
end of the first link, as illustrated in Figure 13-7 .
Figure 13-6. Rotation restraint setup