/// \param elapsedTime Amount of time that has elapsed (in seconds) since last update
void ParticleEffect::update(float elapsedTime)
{
    m_fElapsedTime = elapsedTime; // store time in class composition in case
    // other update functions need it

    killParticles();  // cull old particles
    birthParticles(); // create new particles

    for(int i=0; i<m_nLiveParticleCount; i++)
    {
        Particle *part = &(m_Particles[m_drawOrder[i]]);

        // Here we use v = v + gt - vdt where v is velocity, g is gravity and d is
        // drag. This is a bad approximation but it works.
        // We also use p = p + vt, again this is a bad approximation, but fast
        part->velocity +=
            (m_vecGravity - part->velocity * part->drag) * m_fElapsedTime;
        part->position += part->velocity * m_fElapsedTime;
    }

    // call additional update functions
    for(UpdateFuncIter iter = m_UpdateFunc.begin(); iter != m_UpdateFunc.end(); iter++)
    {
        (*this.*(*iter))(); // really ugly looking code to call all relevant update functions
    }
}
Exemple #2
0
void ParticleField::Update() {
  updateForces();
  updateParticles();
  killParticles();
  spawnParticles();
}