Game Development Reference
In-Depth Information
To determine the velocity components as a function of time, the differential equations
shown in Equation (5.19) must be integrated. For the gravity-only model, the velocity differential
equations were simple enough to be solved directly into simple algebraic equations. Unfortu-
nately, this simplicity is not the case when aerodynamic drag is added to the model. In looking
at Equation (5.19a), the derivative of x-velocity with respect to time is a function of the x-velocity
and velocity magnitude, which is a function of all three velocity components. The equations
cannot be solved independently of each other and there are no simple, closed-form solutions
to the differential equations.
Luckily for us, the ODE solver that was developed in Chapter 4 will save the day. The ODE
solver will solve the velocity differential equations for us and will automatically update the
velocity of the projectile as a function of time. Having access to the ODE solver was the reason
why the SimpleProjectile class was written as a subclass of the ODE class. When we write the
DragProjectile class to model drag effects a bit later in the chapter, it will be written as a subclass
of SimpleProjectile (which itself is a subclass of the ODE class), so the DragProjectile class will
have access to all of the data structure and methods defined in the ODE class that are needed to
run the ODE solver.
Keep in mind that the accelerations due to aerodynamic drag will change over the course
of the trajectory. Drag force is a function of velocity. When the velocity increases, the accelera-
tion due to drag increases with the square of velocity. Because of the “velocity squared” nature
of drag, it will often be a limiting factor in the maximum velocity a projectile can attain. When
a parachutist jumps out of an airplane, she doesn't accelerate forever (luckily for her). Instead,
she accelerates until the drag force on the parachute is equal to the force of gravity.
Location Equations
The inclusion of drag effects similarly complicates the equations that determine the location of
the projectile as a function of time. As shown in Equation (5.20), the derivatives of the x-, y-, or
z-location with respect to time are equal to the x-, y-, or z-velocities.
dx
dt =
v
(5.20a)
x
dy
dt =
v
(5.20b)
y
dz
dt =
v
(5.20c)
z
The problem in trying to solve for x , y , or z as a function of time is that the velocities cannot
be expressed in terms of simple algebraic equations. Luckily, the ODE solver comes to the rescue
once again, because it can solve the velocity and location differential equations simultaneously.
Once we have written the code that defines the differential equations, the ODE solver takes
over and does all the rest of the work. The output from the ODE solver is the location and velocity
values for the projectile at any time.
 
Search WWH ::




Custom Search