Computer graphics/2013-2014/Laboratory 11

Particle engine
Particles engines can be used to simulate effects such as water, fire, cloud, comet tails, etc.

Each particle can be seen as a billboard (a texture always facing the camera) with several additional properties as:


 * physics related:
 * The position vector: (positionX, positionY, positionZ)
 * The speed vector: (speedX, speedY, speedY)
 * The acceleration vector: (accelerationX, accelerationY, accelerationZ)
 * display related:
 * Color, material, texture, etc.
 * Fading and fading factor -- how visible is the particle
 * Life: which should be decremented and when it reaches 0 the particle should be destroyed or reused

The physical laws are quite easy:
 * at each step we update the speed by using the acceleration and the position by using the speed
 * the time is considered constant (usually 1):


 * usually the particles go in the opposite direction of their source; thus we could initialize their speed with the speed of the source, but negative
 * usually the particles are emitted to form a cone

Drawing a single particle
Drawing the particle is quite easy. We simply need to draw a QUAD based on the particle position and to apply a texture on it:

Observations:
 * usually the number of particles is constant:
 * when a particle dies a new one is created. This is usually done by reusing and reinitializing the particle
 * the bigger the time variable is, the smaller the number of frames is needed, but the movement is more fragmented

NOTE: In this particular case the particle is not a billboard!

Calling the Particle engine
Once the Particle class is created we only need to create a few of them and render them on the screen. To do this add in the main (J)OGL application:

Exercise

 * Create a simple particle engine which emits particles only on the OY axis. The camera should be fixed and located at a conveniently distance from the source of the particles. Make each particle a billboard.
 * Create a simple scene containing a cube. Inside the cube we have 5 spheres bouncing of the edges. Each time two (or more) spheres touch each other they disappear.