Game Development Reference
In-Depth Information
FireworkRule::Payload * payload = rule->payloads + i;
create(payload->type, payload->count, firework);
}
}
}
}
These code fragments are taken from the fireworks demo on the CD. You can
create your own fireworks display using the number keys to launch new fireworks
(there are nine basic firework types).
Exactly the same kind of particle system is used in many game engines. By setting
the gravity of particles to a very low value, or even having gravity pull some kinds
of particle upward, we can create smoke, fire, flowing water, explosions, sparks, rain,
and many, many other effects.
The difference between each type of particle is simply one of rendering. Particles
are normally drawn as a flat bitmap on screen rather than as a three-dimensional
model. This is the approach I've used in the demo.
Most production particle systems also allow particles to rotate. Not the full three-
dimensional rotation we will cover later in this topic, but a screen rotation so that each
particle bitmap is not drawn with the same orientation on screen. It can be useful to
have this rotation change over time. I will not try to implement the technique in this
book. It is a relatively easy tweak to add a constant speed rotation to particles, and I'll
leave it as an exercise for those who need it.
4.3
S UMMARY
The particle physics engine is primarily suitable for special effects—namely, the bal-
listics of projectile weapons and particle systems and the visual effects for explosions.
In this chapter we've used a particle system to render fireworks. There are tens of
other uses too. Most games have some kind of particle system at work (often com-
pletely separate from the main physics engine). By setting particles with different
properties for gravity, drag, and initial velocity, it is possible to simulate everything
from flowing water to smoke, from fireballs to fireworks.
Eventually, however, single particles won't be enough. We'll need full three-
dimensional objects. In part II of this topic we'll look at one way to simulate objects:
by building structures out of particles connected by springs, rods, and cables. To han-
dle these structures we'll need to consider more forces than just gravity on particles.
Chapter 5 introduces this.
Search Nedrilad ::




Custom Search