Game Development Reference
In-Depth Information
vForces += vWind;
}
So after the force due to gravity is added to the aggregate, two new local variables are
declared. vDrag is a vector that will represent the still air drag force. fDrag is the mag‐
nitude of that drag force. Since we know the drag force vector is exactly opposite to the
particle's velocity vector, we can equate vDrag to negative vVelocity and then normalize
vDrag to obtain a unit vector pointing in a direction opposite of the particle's velocity.
Next we compute the magnitude of the drag force using the formula shown earlier. This
line handles that:
fDrag = 0.5 * _AIRDENSITY * fSpeed * fSpeed *
(3.14159 * fRadius * fRadius) * _DRAGCOEFFICIENT;
Here, _AIRDENSITY is a global define representing the density of air, which we have set
to 1.23 kg/m 3 (standard air at 15°C). fSpeed is the particle's speed: the magnitude of its
velocity. The 3.14159 * fRadius * fRadius line represents the projected area of the
particle assuming the particle is a sphere. And finally, _DRAGCOEFFICIENT is a drag co‐
efficient that we have set to 0.6. We picked this value from the chart of drag coefficient
for a smooth sphere versus the Reynolds number shown in Chapter 6 . We simply eye‐
balled a value in the Reynolds number range from 1e4 to 1e5. You have a choice here
of tuning the drag coefficient value to achieve some desired effect, or you can create a
curve fit or lookup table to select a drag coefficient corresponding to the Reynolds
number of the moving particle.
Now that we have the magnitude of the drag force, we simply multiply that force by the
unit drag vector to obtain the final drag force vector. This vector then gets aggregated
in vForces .
We handle the wind force in a similar manner with a few differences in the details. First,
since we know the unit wind force vector is in the positive x-direction (i.e., it acts from
left to right), we can simply set the x component of the wind force vector, vWind , to the
magnitude of the wind force. We compute that wind force using the same formula we
used for still air drag with the exception of using the wind speed instead of the particle's
speed. We used _WINDSPEED , a global define , to represent the wind speed, which we
have set to 10 m/s (about 20 knots).
Finally, the wind force is aggregated in vForces .
At this stage the particles will fall under the influence of gravity, but not as fast as they
would have without the drag force. And now they'll also drift to the right due to the
wind force.
Search Nedrilad ::




Custom Search