Game Development Reference
In-Depth Information
double Alpha; // Angle from y-axis (upward) to the cannon.
// When this angle is 0, the cannon is pointing
// straight up, when it is 90 degrees, the cannon
// is horizontal
double Gamma; // Angle from x-axis, in the x-z plane to the cannon.
// When this angle is 0, the cannon is pointing in
// the positive x-direction, positive values of this angle
// are toward the positive z-axis
double L; // This is the length of the cannon, m
double Yb; // This is the base elevation of the cannon, m
double X; // The x-position of the center of the target, m
double Y; // The y-position of the center of the target, m
double Z; // The z-position of the center of the target, m
double Length; // The length of the target measured along the x-axis, m
double Width; // The width of the target measured along the z-axis, m
double Height; // The height of the target measure along the y-axis, m
TVector s; // The shell position (displacement) vector
double time; // The time from the instant the shell leaves
// the cannon, seconds
double tInc; // The time increment to use when stepping through
// the simulation, seconds
double g; // acceleration due to gravity, m/s^2
//-----------------------------------------------------------------------------//
// This function steps the simulation ahead in time. This is where the kinematic
// properties are calculated. The function will return 1 when the target is hit,
// and 2 when the shell hits the ground (x-z plane) before hitting the target;
// otherwise, the function returns 0.
//-----------------------------------------------------------------------------//
int DoSimulation(void)
//-----------------------------------------------------------------------------//
{
double cosX;
double cosY;
double cosZ;
double xe, ze;
double b, Lx, Ly, Lz;
double tx1, tx2, ty1, ty2, tz1, tz2;
// step to the next time in the simulation
time+=tInc;
// First calculate the direction cosines for the cannon orientation.
// In a real game, you would not want to put this calculation in this
// function since it is a waste of CPU time to calculate these values
// at each time step as they never change during the sim. We only put them
// here in this case so you can see all the calculation steps in a single
// function.