Game Development Reference
In-Depth Information
public class FountainLightning extends Powerboat
{
// The FountainLightning constructor calls the
// SimpleProjectile constructor and initializes
// the value of the mode variable.
public FountainLightning(double x, double y, double z,
double vx, double vy, double vz,
double time, double planingSpeed) {
super(x, y, z, vx, vy, vz, time, planingSpeed);
}
The FountainLightning class implements the getRightHandSide method to compute the
right-hand sides of the equations of motion. The first part of the method is the same as always
in that it computes intermediate values of the location and velocity of the boat.
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 powerboat in this simulation moves in the x-direction only. If the mode is set to
“accelerate” and if the velocity is equal to the maximum velocity of 46.1 m/s , the acceleration is
set to zero. If the velocity is less than 11.2 m/s , the acceleration is set to a constant value of 2.1 m/s 2 .
Otherwise, the acceleration is determined from the curve fit relation shown in Equation (9.26).
double v = newQ[0];
double ax; // x-direction acceleration
if ( getMode().equals("accelerating") ) {
// If the velocity is at or above the maximum
// value, set the acceleration to zero.
if ( v >= 46.1 ) {
ax = 0.0;
}
// If the velocity is less than 11.2 m/s, set the
// acceleration equal to the value at 11.2 m/s.
else if ( v < 11.2 ) {
ax = 2.1;
}
Search WWH ::




Custom Search