Game Development Reference
In-Depth Information
The GolfBall class declares its own version of the getRightHandSide method. The only
significant difference between this method and the one declared in the SpinProjectile class
is that the lift coefficient is computed according to Equation (7.23).
// 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];
// Compute the intermediate values of the
// dependent variables.
for(int i=0; i<6; ++i) {
newQ[i] = q[i] + qScale*deltaQ[i];
}
// Declare some convenience variables representing
// the intermediate values of velocity.
double vx = newQ[0];
double vy = newQ[2];
double vz = newQ[4];
// Compute the apparent velocities by subtracting
// the wind velocity components from the projectile
// velocity components.
double vax = vx - getWindVx();
double vay = vy - getWindVy();
double vaz = vz;
// Compute the apparent velocity magnitude. The 1.0e-8 term
// ensures there won't be a divide by zero later on
// if all of the velocity components are zero.
double va = Math.sqrt(vax*vax + vay*vay + vaz*vaz) + 1.0e-8;
Search WWH ::




Custom Search