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) {
// Call the SimpleProjectile class constructor.
super(x0, y0, z0, vx0, vy0, vz0, time);
// Initialize variables declared in the DragProjectile class.
this.mass = mass;
this.area = area;
this.density = density;
this.Cd = Cd;
}
A series of get methods are declared to return the values of the fields declared in the class.
// These methods return the value of the fields
// declared in this class.
public double getMass() {
return mass;
}
public double getArea() {
return area;
}
public double getDensity() {
return density;
}
public double getCd() {
return Cd;
}
The updateLocationAndVelocity method is used to update the location and velocity of the
projectile at the next time increment. In the SimpleProjectile class, this method solved the
gravity-only equations of motion. In the DragProjectile class, the equations of motion are
solved by calling the fourth-order 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 real “meat” of the DragProjectile class is its implementation of the getRightHandSide
method that calculates the right-hand sides of the six differential equations that determine the
motion of the projectile. If you recall from Chapter 4, the ODE solver updates the location and
velocity components by making four intermediate guesses for the values. The final answer is a
Search WWH ::




Custom Search