Game Development Reference
In-Depth Information
Update the display...
// Report results
if (status == 1)
Display DIRECT HIT message to the user...
if (status == 2)
Display MISSED TARGET message to the user...
if (status == 3)
Display SIMULATION TIMED OUT message to the user...
The first task is to simply get the new values for the variables shown on the main window.
After that, the program enters a while loop, stepping through increments of time and
recalculating the position of the shell projectile using the formula for the displacement
vector, s , shown earlier. The shell position at the current time is calculated in the function
DoSimulation . Immediately after calling DoSimulation , the program updates the il‐
lustrations on the main window, showing the shell's trajectory. DoSimulation returns
0 , keeping the while loop going, if there has not yet been a collision or if the time has
not yet reached the preset time-out value.
Once the while loop terminates by DoSimulation returning nonzero, the program
checks the return value from this function call to see if a hit has occurred between the
shell and the ground or the shell and the target. Just so the program does not get stuck
in this while loop, DoSimulation will return a value of 3 , indicating that it is taking too
Now let's look at what's happing in the function DoSimulation (we've also included here
the global variables that are used in DoSimulation ).
// Define a custom type to represent
// the three components of a 3D vector, where
// i represents the x component, j represents
// the y component, and k represents the z
// component
typedef struct TVectorTag
double i;
double j;
double k;
} TVector;
// Now define the variables required for this simulation
double Vm; // Magnitude of muzzle velocity, m/s
Search Nedrilad ::

Custom Search