Game Development Reference
F IGURE 6.2
A rope-bridge held up by springs.
ParticleSpring psB(&a, 1.0f, 2.0f);
A N A NCHORED S PRING G ENERATOR
In many cases we don't want to link two objects together with a spring; rather we
want one end of the spring to be at a fixed point in space. This might be the case for
the supporting cables on a springy rope-bridge, for example. One end of the spring is
attached to the bridge, the other is fixed in space; see figure 6.2 for an example of this.
In this case the form of the spring generator we created earlier will not work. We
can modify it so the generator expects a fixed location rather than an object to link
to. The force generator code is also modified to use the location directly rather than
looking it up in an object. The anchored force generator implementation looks like
Excerpt from include/cyclone/pfgen.h
* A force generator that applies a spring force, where
* one end is attached to a fixed point in space.
class ParticleAnchoredSpring : public ParticleForceGenerator
/** The location of the anchored end of the spring. */
/** Holds the spring constant. */
/** Holds the rest length of the spring. */