Game Development Reference
In-Depth Information
// Update linear velocity from the acceleration.
velocity.addScaledVector(resultingAcc, duration);
// Impose drag.
velocity *= real_pow(damping, duration);
// Clear the forces.
clearAccumulator();
}
void Particle::clearAccumulator()
{
forceAccum.clear();
}
We then add a method that can be called to add a new force into the accumulator:
Excerpt from include/cyclone/particle.h
class Particle
{
// ... Other Particle code as before ...
/**
* Adds the given force to the particle, to be applied at the
* next iteration only.
*
* @param force The force to apply.
*/
void addForce(const Vector3 &force);
};
Excerpt from src/particle.cpp
void Particle::addForce(const Vector3 &force)
{
forceAccum += force;
}
This accumulation stage needs to be completed just before the particle is integrated.
All the forces that apply need to have the chance to add themselves to the accumulator.
We can do this by manually adding code to our frame update loop that adds the
appropriate forces. This is appropriate for forces that will only occur for a few frames.
Most forces will apply to an object over an extended period of time.
Search Nedrilad ::




Custom Search