Game Development Reference
In-Depth Information
The SimpleProjectile class declares a series of methods to return the current location,
velocity, and time values for the projectile. Since these quantities are stored in the s field and
q[] array of the ODE class, the get methods in the SimpleProjectile class simply call the getS or
getQ methods from the ODE class.
// These methods return the location, velocity,
// and time values.
public double getVx() {
return getQ(0);
}
public double getVy() {
return getQ(2);
}
public double getVz() {
return getQ(4);
}
public double getX() {
return getQ(1);
}
public double getY() {
return getQ(3);
}
public double getZ() {
return getQ(5);
}
public double getTime() {
return getS();
}
The updateLocationAndVelocity method is called to update the location and velocity of
the projectile according to the equations of motion in the gravity-only model. The first thing
the method does is to acquire the current location and velocity of the projectile. It then updates
the location and velocity at the new time increment according to the expressions in Equations
(5.6) and (5.8). The time value is updated, and then the new time, location, and velocity values
are loaded into the s and q[] arrays using the setS and setQ methods of the ODE class.
// This method updates the velocity and position
// of the projectile according to the gravity-only model.
public void updateLocationAndVelocity(double dt) {
// Get current location, velocity, and time values
// from the values stored in the ODE class.
Search WWH ::




Custom Search