Game Development Reference
In-Depth Information
GetDlgItemText(hDlg, IDC_CW, str, 15);
Cw = atof(str);
.
.
.
}
After playing with this example program, you should readily see that the trajectory of
the projectile is noticeably different from that typically obtained in the original example.
By adjusting the values of the wind speed, direction, and drag coefficients, you can
dramatically affect the projectile's trajectory. If you set the wind speed to 0 and the drag
coefficients to 1, the trajectory will look like that obtained in the original example, where
wind and drag were not taken into account. Be careful, though: don't set the drag co‐
efficient to 0 because this will result in a “divide by zero” error. We didn't put the ex‐
ception handler in the program, but you can see that it will happen by looking at the
displacement vector formulas where the drag coefficient appears in the denominator of
several terms.
From a user's perspective, if this were a video game, the problem of hitting the target
becomes much more challenging when wind and drag are taken into account. The wind
element is particularly interesting because you can change the wind speed and direction
during game play, forcing the user to pay careful attention to the wind in order to
accurately hit the target.
Rigid-Body Kinetics
You already know from your study of kinematics in Chapter 2 that dealing with rigid
bodies adds rotation, or angular motion, into the mix of things to consider. As we stated
earlier, the equations of motion now consist of a set of equations that relate forces to
linear accelerations and another set of equations that relate moments to angular accel‐
erations. Alternatively, you can think of the equations of motion as relating forces to
the rate of change in linear momentum, and moments to the rate of change in angular
momentum, as discussed in Chapter 1 .
As in kinematics, the procedure for dealing with rigid-body kinetics problems involves
two distinct aspects: 1) tracking the translation of the body's center of mass, where the
body is treated as a particle, and 2) tracking the body's rotation, where you'll utilize the
principles of local coordinates and relative angular velocity and acceleration, as dis‐
cussed in Chapter 2 . Really, the only difference between rigid-body kinematics and
kinetics problems is that in kinetics problems we have forces to consider (including
their resulting moments).
The vector equations are repeated here for convenience:
F = m a
M cg = I α