Game Development Reference
// Check if the particle is now invalid.
if (shot->particle.getPosition().y < 0.0f ||
shot->startTime+5000 < TimingData::get().lastFrameTimestamp ||
shot->particle.getPosition().z > 200.0f)
// We simply set the shot type to be unused, so the
// memory it occupies can be reused by another shot.
shot->type = UNUSED;
It simply calls the integrator on each particle in turn. After it has updated the particle,
it checks to see whether the particle is below 0 height, in which case it is removed. The
particle will also be removed if it is a long way from the firing point (100 m) or if it
has been in flight for more than 5 seconds.
In a real game you would use some kind of collision detection system to check on
whether the projectile had collided with anything. Additional game logic could then
be used to reduce the hit points of the target character or add a bullet-hole graphic to
Because we have no detailed collision model at this stage, it is difficult to show
the effect of the energy in each projectile. When combined with the collisions and
contacts in later parts of this topic, this is obvious. I've provided a version of the
demo (see screenshot in figure 4.2) called bigballistics that includes objects to shoot
at, which are simulated using the full physics engine. You can clearly see in this version
the realism of impacts with the different types of projectile.
F IGURE 4.2
Screenshot of the bigballistic demo.