Game Development Reference
In-Depth Information
float InitialLength;
} Spring, *pSpring;
Specifically, this information includes:
A reference to the first particle to which the spring is connected
A reference to the second particle to which the spring is connected
The spring constant
The damping constant
The unstretched length of the spring
This structure is appropriate for connecting particles. We'll make a slight modification
to this structure later, when we get to the example where we're connecting rigid bodies.
There are define s and variables unique to this example that must be set up as follows:
#define _NUM_OBJECTS 10
#define _NUM_SPRINGS 9
#define _SPRING_K 1000
#define _SPRING_D 100
Particle Objects[_NUM_OBJECTS];
Spring Springs[_NUM_SPRINGS];
As stated earlier, there are 10 particles (objects) and 9 springs in this simulation. The
arrays Objects and Springs are used to keep track of them. We also set up a few
define s representing the spring and damping constants. The values shown here are
arbitrary, and you can change them to suit whatever behavior you desire. The higher
the spring constant, the stiffer the springs; whereas the lower the spring constant, the
stretchier the springs. Stretchy springs make your rope more elastic. Keep in mind while
tuning these values that if you make the spring constant too high, you'll probably have
to make the simulation time step smaller and/or use a robust integration scheme to
avoid numerical instabilities.
The damping constant controls how quickly the springiness of the springs dampens
out. You'll end up tuning this value to get the behavior you desire. A small value can
make the rope seem jittery, while a large value will make the stretchiness appear
smoother. Higher damping also helps alleviate numerical instabilities to some extent,
although it's no substitute for a robust integration scheme.
Search Nedrilad ::

Custom Search