Game Development Reference
In-Depth Information
public DragProjectile(double x0, double y0, double z0,
double vx0, double vy0, double vz0, double time,
double mass, double area, double density, double Cd,
double windVx, double windVy) {
// Call the DragProjectile class constructor.
super(x0, y0, z0, vx0, vy0, vz0, time, mass, area, density, Cd);
// Initialize variables declared in the DragProjectile class.
this.windVx = windVx;
this.windVy = windVy;
}
Two get methods are declared that return the values of the
windVx
and
windVy
fields.
// These methods return the value of the fields
// declared in this class.
public double getWindVx() {
return windVx;
}
public double getWindVy() {
return windVy;
}
Just as it did for the
DragProjectile
class, the
updateLocationAndVelocity
method of the
WindProjectile
class solves the equations of motion by invoking the Runge-Kutta ODE solver.
// This method updates the velocity and location
// of the projectile using a 4th order Runge-Kutta
// solver to integrate the equations of motion.
public void updateLocationAndVelocity(double dt) {
ODESolver.rungeKutta4(this, dt);
}
The
getRightHandSide
method in the
WindProjectile
class is exactly the same as the
getRightHandSide
method in the
DragProjectile
class with two exceptions. When the interme-
diate values of the x-, y-, and z-velocity components are obtained, they are converted into
apparent velocities by subtracting the wind velocity components. The apparent velocities are
then used to compute the drag force terms. The other difference is because the
mass
,
density
,
area
, and
Cd
fields were given private access in the
DragProjectile
class, we must use the
getMass
,
getDensity
,
getArea
, and
getCd
methods to access their values in the
WindProjectile
class.
// 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