Class Diagrams for Particles3D


Chapter 21. Particle Systems

Particle systems are an important component of many 3D games: when you see sparks flying, smoke swirling, fireworks exploding, snow falling, water shooting, or blood spurting, then it's probably being done with a particle system. A particle system consists of a large population of individual particles, perhaps hundreds of thousands, though many commercial games use far fewer depending on the effect required. The particle system is in charge of creating and deleting particles and updating their attributes over time.

A particle is typically rendered as a graphics primitive, such as a point or line, as opposed to a full-fledged 3D shape, such as a sphere or cylinder. This means that rendering overheads can be reduced, an important consideration when so many particles are involved. However, with the advent of more powerful graphics cards, particle systems have started to utilize polygons (e.g., particles made from triangles and quadrilaterals [quads]), which allow textures and lighting to be introduced.

The attributes of a particle vary depending on the kind of system required but typically include position, velocity, forces (e.g., gravity), age, color/texture, shape, size, and transparency. The code that updates a system usually affects particle attributes using time-based equations, but other approaches are possible. For instance, a particle's new position may be a random adjustment of its previous position.

Particle systems often have a generation shape, which specifies a bounding volume in which particles can be created. For example, a system for a water fountain will create particles within a small space near the fountain's base. Generation shapes have been extended to specify bounding volumes for particle updating and aging. For instance, if a particle moves outside the space, then it will begin to age and age more quickly as it moves further away. The aging could trigger a change in its size or color, all depending on the application's needs.

A central and practical issue with particle systems is efficiency since a system may be made up of so many particles. Efficiency influences how particles are updated, rendered, and reused (e.g., a dead particle may be reset to its initial attribute settings and started again). If particles use texturing, then the texture should be applied to the entire system. A particle is a passive entity: its attributes are changed by the particle system.

An offshoot of particle systems are flocking boids, which I consider in Chapter 22. A boid is more intelligent in the sense that it has its own internal state and behavior. For instance, a boid may examine the attributes of its nearest neighbors in the flock to adjust its velocity to avoid colliding with them.


Three particle systems are developed in this chapter: one where the particles are points, another using lines, and a third using quadrilaterals (quads). Figures 21-1, 21-2, and 21-3 show the three systems in action.

Figure 21-1. A particle system of points


The three systems are part of a single application, Particles3D:

The example code for this chapter is located in Particles3D/.


The coding illustrates the following techniques:


Geometry-based particle systems

I use Java 3D's PointArray, LineArray, and QuadArray geometries to implement the point-, line-, and quad-based particle systems.


Reduced data copying

Information is stored in BY_REFERENCE geometries, which avoids the need for a lot of data copying when a geometry is changed.

Figure 21-2. A particle system of lines


Figure 21-3. A particle system of quads



Shape management

Shape changes are handled by a subclass of Java 3D's GeometryUpdater interface.


Reusing textures

A single texture is applied to multiple quad particles, as opposed to using one texture for each quad, which would cause a massive increase in memory usage.


Transparent textures

The quad texture has transparent elements, allowing boring quadrilaterals to look more shapely (as in Figure 21-3).


Color and light blending

The quad particles combine texture, color, and lighting effects for extra realism.


The illusion of 3D

A particle system automatically rotates toward the viewer using Java 3D's OrientedShape3D. This means that a 2D geometry, such as a quad, appears to have 3D thickness. This produces the illusion of 3D without the need to create 3D shapes.



Killer Game Programming in Java
Killer Game Programming in Java
ISBN: 0596007302
EAN: 2147483647
Year: 2006
Pages: 340

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net