Game Development Reference
In-Depth Information
F IGURE 17.7
The cross section of force across a compression wave.
distance of an object from the center of the blast, f a is the applied force, and f b is the
peak blast force, which we'll calculate in a moment. The equation simply provides a
linear fall-off of force on either side of the wave. The force cross section is shown in
figure 17.7. Note that the force is always acting outward from the center of the blast.
We need to calculate the peak force for this equation. The force applied to an ob-
ject depends on both its aerodynamic drag (since the compression wave is primarily a
moving-air effect) and its current velocity. We could do this by simply using the aero-
dynamic effects from chapter 11, but if you aren't using that already, it is probably
overkill.
We can approximate the force effect by applying a force that depends on the dif-
ference between the object's velocity and the wavefront. To get exploding objects to
spin as they are moved, we apply the force off-center. This can be as simple as select-
ing a random, off-center point for each object when the force generator is created.
The same point should be used from frame to frame to prevent objects from looking
like they are jiggling in mid-air. It also means that once the point is pushed so it is
in line with the force vector, the object stops rotating. Otherwise objects could rotate
faster and faster under the influence of the explosion, and that looks odd.
With the concussion wave implemented the explosion force generator looks like
this:
Excerpt from include/cyclone/fgen.h
/**
* A force generator showing a three-component explosion effect.
* This force generator is intended to represent a single
* explosion effect for multiple rigid bodies. The force generator
* can also act as a particle force generator.
*/