Game Development Reference
In-Depth Information
used along with the linear equation of motion to compute the linear displacement of
the rigid body, while the moments will be used with the angular equation of motion to
compute the orientation of the body.
The function then goes on to define a vector representing the propeller thrust, Thrust .
The propeller thrust vector acts in the positive (local) x-direction and has a magnitude
defined by ThrustForce , which the user sets via the keyboard interface (we'll get to that
later). Note that if ThrustForce is negative, then the thrust will actually be a reversing
thrust instead of a forward thrust.
After defining the thrust vector, this function goes on to calculate the aerodynamic drag
acting on the hovercraft. These calculations are very similar to those discussed in
Chapter 17 . The first thing to do is determine the relative velocity at the center of drag,
considering both linear and angular motion. You'll need the magnitude of the relative
velocity vector when calculating the magnitude of the drag force, and you'll need the
direction of the relative velocity vector to determine the direction of the drag force since
it always opposes the velocity vector. The line vtmp = vAngularVelocity^CD computes
the linear velocity at the drag center by taking the vector cross product of the angular
velocity vector with the position vector of the drag center, CD . The result is stored in a
temporary vector, vtmp , and then added vectorially to the body velocity vector, vVelo
cityBody . The result of this vector addition is a velocity vector representing the velocity
of the point defined by CD , including contributions from the body's linear and angular
motion. We compute the actual drag force, which acts in line with but in a direction
opposing the velocity vector, in a manner similar to that for particles, using a simple
formula relating the drag force to the speed squared, density of air, projected area, and
a drag coefficient. The following code performs this calculation:
vLocalVelocity.Normalize();
vDragVector = -vLocalVelocity;
// Determine the resultant force on the element.
tmp = 0.5f * rho * fLocalSpeed*fLocalSpeed
* ProjectedArea;
vResultant = vDragVector * _LINEARDRAGCOEFFICIENT * tmp;
Note that the drag coefficient, LINEARDRAGCOEFFICIENT , is defined as follows:
#define LINEARDRAGCOEFFICIENT 1.25f
Once the drag force is determined, it gets aggregated in the total force vector as follows:
Fb += vResultant;
In addition to aggregating this force, we must aggregate the moment due to that force
in the total moment vector as follows:
vtmp = CD^vResultant;
Mb += vtmp;