Game Development Reference
In-Depth Information
combination of the four guesses. The first thing the getRightHandSide method does is to compute
the intermediate values of location, velocity, and time.
// 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];
}
The directional velocity components and overall velocity magnitude are determined. The
method then computes the overall drag force according to Equation (5.12). Once the overall
drag force is calculated, it is split into directional components according to Equation (5.16).
The drag force components are then added to the right-hand sides of the ODEs.
// Declare some convenience variables representing
// the intermediate values of velocity.
double vx = newQ[0];
double vy = newQ[2];
double vz = newQ[4];
// Compute the 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 v = Math.sqrt(vx*vx + vy*vy + vz*vz) + 1.0e-8;
// Compute the total drag force.
double Fd = 0.5*density*area*Cd*v*v;
// Compute the right-hand sides of the six ODEs.
dQ[0] = -ds*Fd*vx/(mass*v);
dQ[1] = ds*vx;
dQ[2] = -ds*Fd*vy/(mass*v);
Search WWH ::




Custom Search