Game Development Reference
In-Depth Information
F IGURE 4.3
Screenshot of the fireworks demo.
4.2
F IREWORKS
Our second example may appear less useful but demonstrates a common application
of particle physics used in the majority of games. Fireworks are just a very ostenta-
tious application of a particle system that could be used to display explosions, flowing
water, and even smoke and fire.
The fireworks demo on the CD allows you to create an interactive fireworks dis-
play. You can see a display in progress in figure 4.3.
4.2.1
T HE F IREWORKS D ATA
In our fireworks display we need to add extra data to the basic particle structure. First
we need to know what kind of particle it represents. Fireworks consist of a number
of payloads: the initial rocket may burst into several lightweight mini-fireworks that
explode again after a short delay. We represent the type of firework by an integer
value.
Second we need to know the age of the particle. Fireworks consist of a chain re-
action of pyrotechnics, with carefully timed fuses. A rocket will first ignite its rocket
motor; then, after a short time of flight, the motor will burn out as the explosion
stage detonates. This may scatter additional units, which all have a fuse of the same
length, allowing the final bursts to occur at roughly the same time (not exactly the
same time, however, as that would look odd). To support this we keep an age for each
particle and update it at each frame.
The Firework structure can be implemented in this way:
Excerpt from src/demos/fireworks/fireworks.cpp
/**
* Fireworks are particles, with additional data for rendering and
* evolution.
*/
Search Nedrilad ::




Custom Search