Game Development Reference
In-Depth Information
{
Vector Fb; // stores the sum of forces
Vector Mb; // stores the sum of moments
Vector Thrust; // thrust vector
// reset forces and moments:
vForces.x = 0.0f;
vForces.y = 0.0f;
vForces.z = 0.0f; // always zero in 2D
vMoment.x = 0.0f; // always zero in 2D
vMoment.y = 0.0f; // always zero in 2D
vMoment.z = 0.0f;
Fb.x = 0.0f;
Fb.y = 0.0f;
Fb.z = 0.0f;
Mb.x = 0.0f;
Mb.y = 0.0f;
Mb.z = 0.0f;
// Define the thrust vector, which acts through the craft's CG
Thrust.x = 1.0f;
Thrust.y = 0.0f;
Thrust.z = 0.0f; // zero in 2D
Thrust *= ThrustForce;
// Calculate forces and moments in body space:
Vector vLocalVelocity;
float fLocalSpeed;
Vector vDragVector;
float tmp;
Vector vResultant;
Vector vtmp;
// Calculate the aerodynamic drag force:
// Calculate local velocity:
// The local velocity includes the velocity due to
// linear motion of the craft,
// plus the velocity at each element
// due to the rotation of the craft.
vtmp = vAngularVelocity^CD; // rotational part
vLocalVelocity = vVelocityBody + vtmp;
// Calculate local air speed
fLocalSpeed = vLocalVelocity.Magnitude();
// Find the direction in which drag will act.
// Drag always acts in line with the relative