[ParticlesES MIDlet PIC] JOGL-ES Chapter 3.   A Particle System

 

[ This chapter does not appear in the book. ]

A particle system is a collection of simple elements (particles) moving through 3D space, their behavior governed by physical properties, such as gravity, friction, their mass, age, and proximity to other objects.

Particle systems hit the big time in the movie Star Trek II: The Wrath of Khan (or Khaaaaaannnn), where they were used to create a planet-engulfing wall of fire. Since then, they've become commonplace in games, employed for explosions, smoke, fog, blood, snow, clouds, laser beams, and many other effects.

The particle system shown at the top of this page generates an unending fountain of fireballs which gradually burn out and disappear.

The MIDlet, ParticlesES, utilizes the OES_point_sprite and OES_point_size_array core extensions in OpenGL ES 1.1, which allows each particle to be represented by a point sprite.

The particles come in different sizes, and are a mix of red and a fireball texture. Over time, each particle becomes more transparent, and eventually disappears. The 'death' of a particle is triggered either by it reaching a certain age or when it drops through the floor. The particle isn't dead for long - it's immediately reinitialized and ejected from the fountain's starting position on the floor.

[ParticlesES MIDlet PIC 2] The screenshot on the right shows the fountain from a different viewpoint, illustrating that point sprites behave like billboards, automatically turning to face the viewer without the need for programmer intervention.

The sizes of the particles are adjusted depending on how close the camera is to the fountain's floor position. The particles are bigger in the second screenshot than the first because the camera is nearer the fountain. This behavior requires code in the Particles class since, by default, a point sprite's size doesn't vary with the camera distance.

A slightly tricky form of alpha blending is employed when rendering the particles, to ensure they blend correctly, and that other objects in the scene (e.g. the textured cube) are drawn properly.

 

Downloads


Navigation:


Dr. Andrew Davison
E-mail: ad@fivedots.coe.psu.ac.th
Back to my home page