Game Development Reference
In-Depth Information
Now that a generic PropPlane class has been created, it is a simple matter to declare subclasses
of it that represent specific types of airplanes. All that the airplane-specific subclasses have to
do is to pass the proper input parameters to the PropPlane constructor. All of the methods and
fields needed to describe the state and behavior of the airplane have already been implemented
in the PropPlane class.
The Flight Simulator will model the flight of a Cessna Skyhawk, so we will write a class
named CessnaSkyhawk that will represent the airplane. The only thing the CessnaSkyhawk class
does is to declare a constructor that calls the PropPlane constructor passing it the proper input
values for a Cessna Skyhawk.
public class CessnaSkyhawk extends PropPlane
{
// Cessna Skyhawk data
// wingArea = 16.2 = wing wetted area, m^2
// wingSpan = 10.9 = wing span, m
// tailArea = 2.0 = tail wetted area, m^2
// clSlope0 = 0.0889 = slope of Cl-alpha curve
// cl0 = 0.178 = Cl value when alpha = 0
// clSlope1 = -0.1 = slope of post-stall Cl-alpha curve
// cl1 = 3.2 = intercept of post-stall Cl-alpha curve
// alphaClMax = 16.0 = alpha at Cl(max)
// cdp = 0.034 = parasitic drag coefficient
// eff = 0.77 = induced drag efficiency coefficient
// mass = 1114.0 = airplane mass, kg
// enginePower = 119310.0 = peak engine power, W
// engineRps = 40.0 = engine turnover rate, rev/s
// propDiameter = 1.905 = propeller diameter, m
// a = 1.83 = propeller efficiency curve fit coefficient
// b = -1.32 = propeller efficiency curve fit coefficient
// The CessnaSkyhawk constructor calls the
// PropPlane constructor.
public CessnaSkyhawk(double x, double y, double z,
double vx, double vy, double vz, double time) {
super(x, y, z, vx, vy, vz, time, 16.2, 10.9, 2.0,
0.0889, 0.178, -0.1, 3.2, 16.0, 0.034, 0.77,
1114.0, 119310.0, 40.0, 1.905, 1.83, -1.32);
}
}
The GUI aspects of the Flight Simulator are implemented in a class named FlightSimulator .
The code listing for the FlightSimulator class is quite long, and it is similar to all of the other
GUIs previously created in this topic. Details of the FlightSimulator class will not be discussed
here, but you can download the complete code listing from the Apress website.
When your airplane takes off and reaches a reasonable altitude, try turning the plane by
setting a nonzero bank angle. To stop the simulation, you can press the Reset button or you can
cut throttle, set the angle of attack to be negative, and auger your Skyhawk into the ground.
Search WWH ::




Custom Search