Game Development Reference
In-Depth Information
case the different types of spring force generators) that are often quite similar to one
another. In the remainder of this topic I will avoid going through similar variations
in detail; you can find several suites of similar classes in the source code on the CD.
This first time, however, it is worth looking at some variations in detail.
The basic spring generator simply calculates the length of the spring using equa-
tion 6.2, and then uses Hook's law to calculate the force. It can be implemented like
Excerpt from include/cyclone/precision.h
/** Defines the precision of the absolute magnitude operator. */
#define real_abs fabsf
Excerpt from include/cyclone/pfgen.h
* A force generator that applies a spring force.
class ParticleSpring : public ParticleForceGenerator
/** The particle at the other end of the spring. */
Particle *other;
/** Holds the spring constant. */
real springConstant;
/** Holds the rest length of the spring. */
real restLength;
/** Creates a new spring with the given parameters. */
ParticleSpring(Particle *other,
real springConstant, real restLength);
/** Applies the spring force to the given particle. */
virtual void updateForce(Particle *particle, real duration);
Excerpt from src/pfgen.cpp
void ParticleSpring::updateForce(Particle* particle, real duration)
// Calculate the vector of the spring.
Vector3 force;
Search Nedrilad ::

Custom Search