Tutorial: Particle Systems


Explosions

There are many application of particle systems in computer graphics. One is for explosion special effects.

A particle system can be implemented as a collection of particles, each particle following projectile motion using numerical integration.

Start with 3D cannon and cannonball, along with scene viewer. Detect when cannonball is at the top of the trajectory by detecting when the y component of the velocity first goes negative. Then have it explode in to a set of particles, each individually following its own projectile motion path. Set the initial velocity of each particle to be that of the missile when it explodes plus a random amount in the x, y and z directions, e.g.

  for (int i = 0; i < numParticles; i++) {
    p[i].state.r = m->state.r;
    p[i].state.v = m->state.v;
    
    p[i].state.v.x += (rand01() * 2.0 - 1.0) * ExpSpeed;
    p[i].state.v.y += (rand01() * 2.0 - 1.0) * ExpSpeed;
    p[i].state.v.z += (rand01() * 2.0 - 1.0) * ExpSpeed;

    p[i].inflight = true;

  }
  

rand01 generates floating point random numbers [0, 1], i.e. between 0 and 1.

float rand01()
{
  return rand() / (float)RAND_MAX;
  
}
  

In the Island Defence game particle systems can be used when a missile hits the island, a boat, or the water. They can also be used for the missile defence system, where a refined collision detection could be based on colliding each individual particle with the missile, rather than just using a sphere - as an example of how more and more detailed refinements and polish can be introduced, each requiring more work for diminishing return.