Game Development Reference
In-Depth Information
if(tmp < −1) tmp = −1;
fAttackAngle = RadiansToDegrees((float) asin(tmp));
// Determine the resultant force (lift and drag) on the element.
tmp = 0.5f * rho * fLocalSpeed*fLocalSpeed * Element[i].fArea;
if (i == 6) // Tail/rudder
{
vResultant = (vLiftVector*RudderLiftCoefficient(fAttackAngle) +
vDragVector*RudderDragCoefficient(fAttackAngle))
* tmp;
} else
vResultant = (vLiftVector*LiftCoefficient(fAttackAngle,
Element[i].iFlap) +
vDragVector*DragCoefficient(fAttackAngle,
Element[i].iFlap) ) * tmp;
// Check for stall.
// We can easily determine stall by noting when the coefficient
// of lift is 0. In reality, stall warning devices give warnings well
// before the lift goes to 0 to give the pilot time to correct.
if (i<=0)
{
if (LiftCoefficient(fAttackAngle, Element[i].iFlap) == 0)
Stalling = true;
}
// Keep a running total of these resultant forces (total force)
Fb += vResultant;
// Calculate the moment about the CG of this element's force
// and keep a running total of these moments (total moment)
vtmp = Element[i].vCGCoords^vResultant;
Mb += vtmp;
}
// Now add the thrust
Fb += Thrust;
// Convert forces from model space to earth space
Airplane.vForces = QVRotate(Airplane.qOrientation, Fb);
// Apply gravity (g is defined as −32.174 ft/s^2)
Airplane.vForces.z += g * Airplane.fMass;
Airplane.vMoments += Mb;
}
The first thing this function does is reset the variables that hold the total force and
moment acting on the aircraft. Next, the thrust vector is set up. This is trivial in this
example since we're assuming that the thrust vector always points in the plus x-axis
direction (toward the nose) and passes through the aircraft center of gravity (so it does
not create a moment).