Game Development Reference
In-Depth Information
CHAPTER 8
Particles
In this chapter we'll show you how to apply what you've learned in Chapter 7 in a simple
particle simulator. Before getting to the specifics of the example we'll present, let's con‐
sider particles in general. Particles are simple idealizations that can be used to simulate
all sorts of phenomena or special effects within a game. For example, particle simulations
are often used to simulate smoke, fire, and explosions. They can also be used to simulate
water, dust clouds, and swarms of insects, among many other things. Really, your imag‐
ination is the only limit. Particles lend themselves to simulating both discrete objects
like bouncing balls and continua like water. Plus, you can easily ascribe an array of
attributes to particles depending on what you're modeling.
For example, say, you're modeling fire using particles. Each particle will rise in the air,
and as it cools its color will change until it fades away. You can tie the particle's color to
its temperature, which is modeled using thermodynamics. The attribute you'd want to
track is the particle's temperature. In a previous work,
(O'Reilly), this topic's coauthor David M. Bourg used particles to represent swarms of
insects that would swarm, flock, chase, and evade depending on the artificial intelligence
(AI). The AI controlled their behavior, which was then implemented as a system of
particles using principles very similar to what you'll see in this chapter.
Particles are not limited to collections of independent objects either. Later in this topic,
you'll learn how to connect particles together using springs to create deformable objects
such as cloth. Particles are extremely versatile, and you'll do well to learn how to leverage
their simplicity.
You can use particles to model sand in a simple phone application that simulates an
hourglass. Couple this sand model with the accelerometer techniques you'll learn about
in Chapter 21 , and you'll be able to make the sand flow by turning the phone over.
You can easily use particles to simulate bullets flying out of a gun. Imagine a Gatling
gun spewing forth a hail of lead, all simulated using simple particles. Speaking of spew‐