Game Development Reference
In-Depth Information
Explosion.p[i].angle = -angle + m * tb_Rnd(0,10);
} else
Explosion.p[i].angle = tb_Rnd(0,360);
f = (float) tb_Rnd(80, 100) / 100.0f;
Explosion.p[i].life = tb_Round(life * f);
Explosion.p[i].r = 255;//tb_Rnd(225, 255);
Explosion.p[i].g = 255;//tb_Rnd(85, 115);
Explosion.p[i].b = 255;//tb_Rnd(15, 45);
Explosion.p[i].time = 0;
Explosion.p[i].Active = TRUE;
Explosion.p[i].gravity = gravity;
As you can see, we've altered the statements that set the initial velocity of the particles
to be a random-number generator in a range anywhere from 0 to a velocity that would
consume the entire explosion's kinetic energy. The next line reduces the available kinetic
energy in the explosion by the amount just assigned to the particle. This way, you can
be sure that the outgoing explosion is never more powerful then the input. A more
interesting way to handle this would be to first initialize the particles with some given
mass distribution and to assign the velocities not randomly, but with a normal distri‐
bution. Numerical recipes in C can help you accomplish this.
Even though the preceding code does not take into account some of the more subtle
aspects of the transfer of kinetic energy, it will ensure that a small, slow-moving bullet
produces a smaller explosion than a big, fast-moving one. This is something that is
lacking in today's video games.
Polygon Explosions
While particle explosions are appropriate for small, uniform objects, they fail to give
appropriate realism when something is blown into identifiable chunks. This is why in
video games you rarely see a car explode and the door fly away to land next to you.
Instead, games usually handle objects like this with a particle explosion that obscures
the object while it is re-rendered in its now-exploded state with the missing pieces having
been apparently blown to smithereens.
If you do want to model a full explosion of solid bodies, you can reuse the particle code
for the translation aspects. Essentially the particles will now describe the center of gravity
of each solid body. You will have to add in an initial angular velocity and let the simu‐
lation, as described in Chapter 12 , handle their motion after that initial angle.
While we don't have room to go over another example here, we'll talk a little about the
input energy to such an explosion to help you bridge the gap. While we are on that
subject, let's recall that a bullet just doesn't have the energy required to blow something
apart. Even when you hit something with a tank-mounted gun, it really isn't the kinetic
Search Nedrilad ::

Custom Search