Game Development Reference
In-Depth Information
Excerpt from include/cyclone/particle.h
class Particle
// ... Other Particle code as before ...
* Integrates the particle forward in time by the given amount.
* This function uses a Newton-Euler integration method, which is a
* linear approximation of the correct integral. For this reason it
* may be inaccurate in some cases.
void integrate(real duration);
Excerpt from src/particle.cpp
#include <assert.h>
#include <cyclone/particle.h>
using namespace cyclone;
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);
// Update linear velocity from the acceleration.
velocity.addScaledVector(resultingAcc, duration);
// Impose drag.
velocity *= real_pow(damping, duration);
I have added the integration method to the Particle class because it simply up-
dates the particles' internal data. It takes just a time interval and updates the position
and velocity of the particle, returning no data.
Search Nedrilad ::

Custom Search