Game Development Reference
In-Depth Information
divided by the projectile mass, and the velocity and position components would be found by
integrating the acceleration and velocity equations.
An interesting thing to note about Equation (5.25c) is that while there is no wind velocity
component in the z-direction, the drag force in the z-direction is affected by wind, because the
z-component of drag force is now a function of the apparent velocity magnitude. The presence
of wind changes the apparent velocity of the projectile, which alters the overall drag on the
projectile. A projectile will reach a different height in the presence of a crosswind than it would
if there was no wind.
There are some problems with this approach to modeling wind effects. The basic drag
force expression shown in Equation (5.24) is based on the frontal area of the projectile. When
wind is taken into account, the apparent velocity vector no longer lines up with the inertial
velocity vector. The wind doesn't act solely on the frontal area of the projectile but on some
combination of the frontal and lateral areas. The same situation exists for the drag coefficient.
It is based on the object having a certain orientation with respect to the velocity vector. When
wind is included in the model, the apparent velocity may have a different orientation, and the
drag coefficient may no longer have the same value.
This is another case when you, as a game developer, need to evaluate how much accuracy
you want to build into your models. For a spherical projectile, it doesn't make any difference.
The frontal area and drag coefficient will be the same no matter what the orientation of the
apparent velocity vector. If the projectile shape is asymmetrical, there will be a difference to the
frontal area and drag coefficient, but then the question becomes whether you can accurately
model the differences. It may be difficult to determine what the proper area term should be,
and drag coefficient data may not be available for different velocity-geometry orientations. For
the rest of this section, we will take the easy way out and assume that the same frontal area and
drag coefficient can be used when wind effects are added to the model.
Programming Wind Effects into the Projectile Trajectory Model
Adding wind effects to our projectile trajectory modeling code is really quite simple, because
we did most of the work when we wrote the DragProjectile class. We will call the class that
represents a projectile under the influence of wind and drag the WindProjectile class. To reuse
as much of the previous code as possible, we will make the WindProjectile class a subclass of
DragProjectile . The WindProjectile class declares two fields that represent the x- and y-velocity
components of the wind.
public class WindProjectil e extends DragProjectile
{
private double windVx;
private double windVy;
The WindProjectile constructor calls the DragProjectile constructor to initialize the
fields declared in the DragProjectile , SimpleProjectile , and ODE classes. The windVx and
windVy fields are then given initial values.
Search WWH ::




Custom Search