Game Development Reference
In-Depth Information
// This method updates the velocity and location
// of the boat using a 4th order Runge-Kutta
// solver to integrate the equations of motion.
public void updateLocationAndVelocity(double dt) {
ODESolver.rungeKutta4(this, dt);
}
Because the Powerboat class is a subclass of the SimpleProjectile class, which itself
is a subclass of the ODE class, the Powerboat class must provide an implementation of the
getRightHandSide method. The Powerboat class version of this method sets all of the location
and velocity updates to zero. The intention is that Powerboat subclasses will override this
method with the acceleration and velocity functions, like Equation (9.26) for instance, that
correspond to the specific boat being modeled.
// The getRightHandSide() method returns the right-hand
// sides of the two first-order ODEs. The Powerboat
// implementation of this method does nothing. It is
// meant to be overridden by subclasses of Powerboat.
// 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];
dQ[0] = 0.0;
dQ[1] = 0.0;
dQ[2] = 0.0;
dQ[3] = 0.0;
dQ[4] = 0.0;
dQ[5] = 0.0;
return dQ;
}
}
Similar to the approach taken with the Car Simulator in Chapter 8, classes that represent
specific powerboats are written as subclasses of the Powerboat class. We want to include the
Fountain Lightning in the Boat Simulator, so a FountainLightning class is written. The main
thing the FountainLightning class does is to provide a real implementation of the getRightHandSide
method according to the acceleration expression shown in Equation (9.26). The FountainLightning
class doesn't declare any new fields, and its constructor simply calls the Powerboat constructor.
Search WWH ::




Custom Search