Game Development Reference
In-Depth Information
* can be used for multiple particles.
*/
class ParticleDrag : public ParticleForceGenerator
{
/** Holds the velocity drag coefficient. */
real k1;
/** Holds the velocity squared drag coefficient. */
real k2;
public:
/** 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)
{
Vector3 force;
particle->getVelocity(&force);
// Calculate the total drag coefficient.
real dragCoeff = force.magnitude();
dragCoeff = k1 * dragCoeff + k2 * dragCoeff * dragCoeff;
// Calculate the final force and apply it.
force.normalize();
force *= -dragCoeff;
particle->addForce(force);
}
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.
Search Nedrilad ::




Custom Search