
5.2 Force Generators 85
/** Applies the gravitational force to the given particle. */
virtual void updateForce(Particle *particle, real duration);
};
Excerpt from file src/pfgen.cpp
void ParticleGravity::updateForce(Particle* particle, real duration)
{
// Check that we do not have infinite mass.
if (!particle->hasFiniteMass()) return;
// Apply the mass-scaled force to the particle.
particle->addForce(gravity * particle->getMass());
}
Note that the force is calculated based on the mass of the object passed into the
updateForce method. The only piece of data stored by the class is the acceleration due
to gravity. One instance of this class could be shared