Game Development Reference
In-Depth Information
The method now turns to the computation of the Magnus force. The velocity magnitude is
computed and the overall Magnus force is computed from Equation (5.28). The lift coefficient
is calculated from Equation (5.29). This particular lift coefficient equation is valid only for a
sphere. If the shape of the projectile being modeled is not spherical, the line of code that computes
C L would have to be changed. Based on the total Magnus force, the directional components of
Magnus force are determined from Equation (5.31).
// Compute the velocity magnitude.
double v = Math.sqrt(vx*vx + vy*vy + vz*vz) + 1.0e-8;
// Evaluate the Magnus force terms.
double Cl = radius*omega/v;
double Fm = 0.5*getDensity()*getArea()*Cl*v*v;
double Fmx = (vy*rz - ry*vz)*Fm/v;
double Fmy = -(vx*rz - rx*vz)*Fm/v;
double Fmz = (vx*ry - rx*vy)*Fm/v;
The gravitational, drag, and Magnus force terms are added to the right-hand sides of the
ODEs that describe the equations of motion.
// Compute the right-hand sides of the six ODEs.
dQ[0] = ds*(Fdx + Fmx)/getMass();
dQ[1] = ds*vx;
dQ[2] = ds*(Fdy + Fmy)/getMass();
dQ[3] = ds*vy;
dQ[4] = ds*(G + (Fdz + Fmz)/getMass());
dQ[5] = ds*vz;
return dQ;
}
}
Well, we've done it. The SpinProjectile class models the general motion of a projectile
under the influence of gravity, aerodynamic drag, wind, and spin. The SpinProjectile ,
WindProjectile , DragProjectile , and SimpleProjectile classes can be used to model the
motion of just about any projectile that you will come across in your game programming. In
the next section, we'll create one last version of the Golf Game that will include spin effects on
the flight of the golf ball.
Golf Game Version 4
Using the SpinProjectile class, one final version of the Golf Game will be created that will
model the flight of a golf ball under the forces of gravity, drag, wind, and spin. Because the
SpinProjectile class uses the same data structure as the previous projectile classes, very little
has to be done to the GUI class to incorporate SpinProjectile objects. The GUI class is named
GolfGame4 , and a typical screen shot of the game is shown in Figure 5-16. There are five new text
fields allowing the user to specify the angular velocity of the golf ball, the golf ball radius, and
the vectors that define the spin axis. The default setting is for the ball to spin about the y-axis.
Search WWH ::




Custom Search