Game Development Reference
In-Depth Information
void updateForces(real duration);
};
}
I have used the C++ standard template library's growable array, vector . The imple-
mentations of the first three methods are simple wrappers around corresponding
methods in the vector data structure.
At each frame, before the update is performed, the force generators are all called.
They will be adding forces to the accumulator which can be used later to calculate
each particle's acceleration:
Excerpt from src/pfgen.cpp
#include <cyclone/pfgen.h>
using namespace cyclone;
void ParticleForceRegistry::updateForces(real duration)
{
Registry::iterator i = registrations.begin();
for (; i != registrations.end(); i++)
{
i->fg->updateForce(i->particle, duration);
}
}
5.2.3
AG RAVITY F ORCE G ENERATOR
We can replace our previous implementation of gravity by a force generator. Rather
than apply a constant acceleration at each frame, gravity is represented as a force
generator attached to each particle. The implementation looks like this:
Excerpt from include/cyclone/pfgen.h
/**
* A force generator that applies a gravitational force. One instance
* can be used for multiple particles.
*/
class ParticleGravity : public ParticleForceGenerator
{
/** Holds the acceleration due to gravity. */
Vector3 gravity;
public:
/** Creates the generator with the given acceleration. */
Search Nedrilad ::




Custom Search