Game Development Reference
In-Depth Information
For particles D'Alembert's principle implies that, if we have a set of forces acting
on an object, we can replace all those forces with a single force, which is calculated by
f
=
f i
i
In other words, we simply add the forces together using vector addition, and we apply
the single force that results.
To make use of this result, we use a vector as a force accumulator. In each frame
we zero the vector and add each applied force in turn using vector addition. The final
value will be the resultant force to apply to the object. We add a method to the particle
that is called at the end of each integration step to clear the accumulator of the forces
that have just been applied:
Excerpt from include/cyclone/particle.h
class Particle
{
// ... Other Particle code as before ...
/**
* Holds the accumulated force to be applied at the next
* simulation iteration only. This value is zeroed at each
* integration step.
*/
Vector3 forceAccum;
/**
* Clears the forces applied to the particle. This will be
* called automatically after each integration step.
*/
void clearAccumulator();
};
Excerpt from src/particle.cpp
void Particle::integrate(real duration)
{
assert(duration > 0.0);
// Update linear position.
position.addScaledVector(velocity, duration);
// Work out the acceleration from the force.
Vector3 resultingAcc = acceleration;
resultingAcc.addScaledVector(forceAccum, inverseMass);
Search Nedrilad ::




Custom Search