Game Development Reference
In-Depth Information
// Compute the total drag force and the dirctional
// drag components.
double Fd = 0.5*getDensity()*getArea()*getCd()*va*va;
double Fdx = -Fd*vax/va;
double Fdy = -Fd*vay/va;
double Fdz = -Fd*vaz/va;
// Compute the velocity magnitude.
double v = Math.sqrt(vx*vx + vy*vy + vz*vz) + 1.0e-8;
// Evaluate the Magnus force terms.
double Cl = -0.05 + Math.sqrt(0.0025 +
0.36*Math.abs(getRadius()*getOmega()/v));
double Fm = 0.5*getDensity()*getArea()*Cl*v*v;
double Fmx = (vy*getRz() - getRy()*vz)*Fm/v;
double Fmy = -(vx*getRz() - getRx()*vz)*Fm/v;
double Fmz = (vx*getRy() - getRx()*vy)*Fm/v;
// 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;
}
}
The GUI for this version of the Golf Game is implemented in a class named GolfGame .
The GolfGame class is so similar to the GUI classes developed in Chapter 5 that only the
actionPerformed method that is called when the Fire button is pressed will be discussed here.
The first thing the method does is to define some parameters for the golf ball and extract the
input values for velocities, density, spin axis, and distance-to-hole from the text fields. The drag
coefficient for the golf ball is assumed to be a constant 0.22.
// The actionPerformed() method is called when
// the Fire button is pressed.
public void actionPerformed(ActionEvent event) {
// Define golf ball parameters.
double ballMass = 0.0459;
double radius = 0.02135;
double area = Math.PI*radius*radius;
double cd = 0.22; // Drag coefficient
double e = 0.78; // Coefficient of restitution
Search WWH ::




Custom Search