Game Development Reference
In-Depth Information
Finally, the spring force is applied to each particle connected by the spring. Remember,
the force is equal in magnitude but opposite in direction for each particle. The lines:
j = Springs[i].End1;
Objects[j].vSprings += F;
apply the spring force to the particle at the first end of the spring, whereas the lines:
j = Springs[i].End2;
Objects[j].vSprings -= F;
apply the opposite spring force to the particle at the second end of the spring.
That's it for computing and applying the spring forces. The remainder of the code is
business as usual, where we compute the force due to gravity and add it to the aggregate
spring force for each particle and then integrate the equations of motion. Finally, we
render the scene at each time step.
Connecting Rigid Bodies
As with particles, you can connect rigid bodies with springs to simulate some interesting
things. For example, you may want to simulate something as simple as a linked chain,
where each link is connected to the other in series. Or perhaps you want to simulate
connected body parts to simulate rag doll physics or maybe a golfer's swing. All these
require some means of connecting rigid bodies. In this section we'll show you how to
use linear spring-dampers, the same we've discussed already, to connect rigid bodies.
We'll start with a simple analog to the rope example discussed earlier. Instead of con‐
necting particles with springs to simulate a dangling rope, we'll connect rigid links to
simulate a dangling rope or chain. Later, we'll show you how linear springs can be used
to restrain angular motion.
In this example, each link is rigid in that it does not deform; however, the links are
connected by springs in a way that allows the ensemble to swing, stretch, and bend in
a manner similar to a hanging chain. Figure 13-4 illustrates our swinging linked chain
as it swings from right to left and then back toward the right.
Search Nedrilad ::

Custom Search