Game Development Reference
In-Depth Information
Figure 13-2. Swinging rope
The example consists of a rope comprising 10 particles and 9 springs. At the start of the
simulation, the rope, originally extended straight out to the right, falls under the influ‐
ence of gravity, swinging left and right until it comes to rest (hanging straight down).
The dots represent particles and the lines represent springs. The topmost particle is
fixed, and the illustration on the left in Figure 13-2 shows the rope swinging down from
right to left while the illustration on the right shows the rope swinging back from left
to right.
This example uses all the same code and techniques presented in Chapter 7 through
Chapter 9 for simulating particles and rigid bodies. Really, the only difference is that we
have to compute a new force—the spring force on each object. But before we do that,
we have to define and initialize the springs.
Spring structure and variables
The following code sample shows the spring data structure we set up to store each
spring's information:
typedef struct _Spring {
int End1;
int End2;
float k;
float d;
Search Nedrilad ::

Custom Search