Game Development Reference
In-Depth Information
dQ[3] = ds*vy;
dQ[4] = ds*(G - Fd*vz/(mass*v));
dQ[5] = ds*vz;
return dQ;
}
}
Because it can reuse so much code from the SimpleProjectile and ODE classes, the
DragProjectile class is quite short, only requiring 90 lines of code including comment state-
ments. In the next section, the DragProjectile class will be incorporated into a new version of
the Golf Game that will include drag effects.
Golf Game Version 2
Version 2 of the Golf Game uses the DragProjectile class to include drag effects in the simula-
tion. The class that implements the GUI is called GolfGame2 . A sample screen shot of the GUI
display is shown in Figure 5-8. In addition to the velocity and distance-to-hole text fields, there
are now text fields to input the mass, area, drag coefficient, and density. These parameters are
used to compute the drag force on the golf ball. Everything else about Golf Game version 2 is
the same as with the original Golf Game. The objective is to hit the ball so it lands within 10 m
of the flag.
Figure 5-8. A typical Golf Game version 2 display
Search WWH ::




Custom Search