Game Development Reference
* can be used for multiple particles.
class ParticleDrag : public ParticleForceGenerator
/** Holds the velocity drag coefficient. */
/** Holds the velocity squared drag coefficient. */
/** Creates the generator with the given coefficients. */
ParticleDrag(real k1, real k2);
/** Applies the drag force to the given particle. */
virtual void updateForce(Particle *particle, real duration);
Excerpt from src/pfgen.cpp
void ParticleDrag::updateForce(Particle* particle, real duration)
// Calculate the total drag coefficient.
real dragCoeff = force.magnitude();
dragCoeff = k1 * dragCoeff + k2 * dragCoeff * dragCoeff;
// Calculate the final force and apply it.
force *= -dragCoeff;
Once again the force is calculated based only on the properties of the object it is
passed. The only pieces of data stored by the class are the values for the two constants.
As before, one instance of this class could be shared among any number of objects
that have the same drag coefficients.
This drag model is considerably more complex than the simple damping we used
in chapter 3. It can be used to model the kind of drag that a golf ball experiences
in flight, for example. For the aerodynamics needed in a flight simulator, however, it
may not be sufficient; we will return to flight simulator aerodynamics in chapter 11.