Game Development Reference
In-Depth Information
// Compute the drag force based on the frontal area
// of the rocket.
double area = 0.25*Math.PI*rocketDiameter*rocketDiameter;
double drag = 0.5*cd*density*vtotal*vtotal*area;
The gravitational acceleration will decrease as the rocket gets further and further away
from the surface of the earth. The gravitational acceleration is calculated using Equation (11.13).
// Compute the gravitational acceleration
// as a function of altitude.
double re = 6356766.0; // Radius of the earth in meters.
double g = 9.80665*re*re/Math.pow(re+z,2.0);
As was stated in the assumptions, the lift force is assumed to be zero.
// For this simulation, lift will be assumed to be zero.
double lift = 0.0;
Once the thrust, drag, gravity, and lift forces have been determined, these forces are rotated
into x- and z-components according to the sine and cosine of the pitch angle as shown in
Equations (11.1) and (11.2).
// Compute the force components in the x- and z-directions.
// The rocket will be assumed to be traveling in the x-z plane.
double Fx = (thrust - drag)*Math.cos(theta) - lift*Math.sin(theta);
double Fz = (thrust - drag)*Math.sin(theta) + lift*Math.cos(theta) -
mass*g;
The final thing the getRightHandSide method does is to load the appropriate terms into the
right-hand sides of the ten ODEs. The mass flow rate and rate of change of pitch angle are
assumed to be constant in this simulation.
// Load the right-hand sides of the ODEs.
dQ[0] = ds*(Fx/mass);
dQ[1] = ds*vx;
dQ[2] = 0.0; // y-component of accleration = 0
dQ[3] = 0.0;
dQ[4] = ds*(Fz/mass);
dQ[5] = ds*vz;
dQ[6] = 0.0; // Mass flow rate is constant
dQ[7] = -ds*(massFlowRate*numberOfEngines);
dQ[8] = 0.0; // d(theta)/dt is constant
dQ[9] = ds*omega;
return dQ;
}
}
The GUI for the Rocket Simulator is defined in a class named RocketSimulator . The class
is quite long and complicated, and only one aspect of it will be discussed here. The full
RocketSimulator class code listing can be downloaded from the Apress website. When the Launch
Search WWH ::




Custom Search