Game Development Reference
In-Depth Information
The first line computes the moment due to the drag force by taking the vector cross
product of the position vector, to the center of drag, with the drag force vector. The
second line adds this force to the variable, accumulating these moments.
With the drag calculation complete, CalcLoads proceeds to calculate the forces and
moments due to the bow thrusters, which may be active or inactive at any given time.
Fb += PThrust;
vtmp = CPT^PThrust;
Mb += vtmp;
The first line aggregates the port bow thruster force into Fb . PThrust is a force vector
computed in the SetThrusters method in response to your keyboard input. The next
two lines compute and aggregate the moment due to the thruster force. A similar set of
code lines follows, computing the force and moment due to the starboard bow thruster.
Next, the propeller thrust force is added to the running total of forces. Remember, since
the propeller thrust force acts through the center of gravity, there is no moment to worry
about. Thus, all we need is:
Fb += Thrust; // no moment since line of action is through CG
Finally, the total force is transformed from local coordinates to world coordinates via a
vector rotation given the orientation of the hovercraft, and the total forces and moments
are stored so they are available when it comes time to integrate the equations of motion
at each time step.
As you can see, computing loads on a rigid body is a bit more complex than what you
saw earlier when dealing with particles. This, of course, is due to the nature of rigid
bodies being able to rotate. What's nice, though, is that all this new complexity is en‐
capsulated in CalcLoads , and the rest of the simulator is pretty much the same as when
we're dealing with particles.
Transforming Coordinates
Let's talk about transformation from local to world coordinates a bit more since you'll
see this sort of transform again in a few places. When computing forces acting on the
rigid body, we want those forces in a vector form relative to the coordinates that are
fixed with respect to the hovercraft (e.g., relative to the body's center of gravity with the
x-axis pointing toward the front of the body and the y-axis pointing toward the starboard
side). This simplifies our calculations of forces and moments. However, when integrat‐
ing the equation of motion to see how the body translates in world coordinates, we use
the equations of motion in world coordinates, requiring us to represent the aggregate
force in world coordinates. That's why we rotated the aggregate force at the end of the