Game Development Reference
In-Depth Information
Observe here that the displacement vector essentially gives the position of the shell's
center of mass at any given instant in time; thus, you can use this vector to plot the shell's
trajectory from the cannon to the target.
Hitting the Target
Now that you have the equations fully describing the shell's trajectory, you need to
consider the location of the target in order to determine when a direct hit occurs. To
show you how to do this, we've prepared a sample program that implements these
kinematic equations along with a simple bounding box collision detection method for
checking whether or not the shell has struck the target. Basically, at each time step where
we calculate the position of the shell after it has left the cannon, we check to see if this
position falls within the bounding dimensions of the target object represented by a cube.
The sample program is set up such that you can change all of the variables in the sim‐
ulation and view the effects of your changes. Figure 2-5 shows the main screen for the
cannon example program, with the governing variables shown on the left. The upper
illustration is a bird's-eye view looking down on the cannon and the target, while the
lower illustration is a profile (side) view.
Figure 2-5. Cannon sample program main window
 
Search Nedrilad ::




Custom Search