Game Development Reference
In-Depth Information
As was the case with the golf simulator we developed earlier in this chapter, the Free-Kick
Game requires two classes—the SoccerBall class that represents a soccer ball and a FreeKick
class that defines the GUI. We'll start by looking at the SoccerBall class.
Like the GolfBall class, the SoccerBall class is written as a subclass of the SpinProjectile
class. The SoccerBall class declares one field that will store the value of the air temperature,
which will be used to compute the Reynolds number later in the class. The SoccerBall
constructor simply calls the SpinProjectile constructor.
public class SoccerBall extends SpinProjectile
{
private double temperature;
public SoccerBall(double x0, double y0, double z0,
double vx0, double vy0, double vz0, double time,
double mass, double area, double density, double Cd,
double windVx, double windVy, double rx, double ry,
double rz, double omega, double radius,
double temperature) {
// Call the SpinProjectile class constructor.
super(x0, y0, z0, vx0, vy0, vz0, time, mass, area,
density, Cd, windVx, windVy, rx, ry, rz, omega, radius);
this.temperature = temperature;
}
The getRightHandSide method declared in the SoccerBall class is similar to the
SpinProjectile class version with two exceptions: the drag coefficient for the soccer ball is
computed according to Equation (7.54), and the lift coefficient for the Magnus force term is
determined from Equation (7.56). The first part of the method, which is identical to that of the
SpinProjectile class, is not shown.
// The getRightHandSide() method returns the right-hand
// sides of the six first-order projectile ODEs.
// q[0] = vx = dxdt
// q[1] = x
// q[2] = vy = dydt
// q[3] = y
// q[4] = vz = dzdt
// q[5] = z
public double[] getRightHandSide(double s, double q[],
double deltaQ[], double ds,
double qScale) {
double dQ[] = new double[6];
double newQ[] = new double[6];
Search WWH ::




Custom Search