
6.2 Spring-Like Force Generators 97
/**
* Holds the length of the bungee at the point it begins to
* generate a force.
*/
real restLength;
public:
/** Creates a new bungee with the given parameters. */
ParticleBungee(Particle *other,
real springConstant, real restLength);
/** Applies the spring force to the given particle. */
virtual void updateForce(Particle *particle, real duration);
};
Excerpt from file src/pfgen.cpp
void ParticleBungee::updateForce(Particle* particle, real duration)
{
// Calculate the vector of the spring.
Vector3 force;
particle->getPosition(&force);
force -= other->getPosition();
// Check if the bungee is compressed.
real magnitude = force.magnitud ...