Game Development Reference
In-Depth Information
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 - windVx;
double vay = vy - windVy;
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;
// Compute the total drag force.
double Fd = 0.5*getDensity()*getArea()*getCd()*va*va;
// Compute the right-hand sides of the six ODEs.
dQ[0] = -ds*Fd*vax/(getMass()*va);
dQ[1] = ds*vx;
dQ[2] = -ds*Fd*vay/(getMass()*va);
dQ[3] = ds*vy;
dQ[4] = ds*(G - Fd*vaz/(getMass()*va));
dQ[5] = ds*vz;
return dQ;
}
}
All-in-all, the changes required to write the WindProjectile class from the DragProjectile
class were pretty minor. As you may have guessed, we're now going to use the WindProjectile class
to create a new version of the Golf Game—version 3 with wind effects.
Search WWH ::




Custom Search