Game Development Reference
In-Depth Information
The formula we'll use to model still air drag is:
F d = ½ ρV 2 AC d
Here F d is the magnitude of the drag force. Its direction is directly opposite the velocity
of the moving particle. ρ is the density of air through which the particle moves, V is the
magnitude of the particle's velocity (its speed), A is the projected area of the particle as
though it's a sphere, and C d is a drag coefficient.
We can use this same formula to estimate the wind force pushing the particle sideways.
The only difference this time is that V is the wind speed, and the direction of the resulting
wind force is from our assumed left-to-right direction.
To add these two forces to our simulation, we need to make a few additions to the
Particle class's CalcLoads method. The following code shows how CalcLoads looks
now. Remember, all we had in here originally were the first three lines of executable
code shown next—the code that initializes the aggregate force vector and then the line
of code that adds the force due to gravity to the aggregate force. All the rest of the code
in this method is new.
void Particle::CalcLoads(void)
// Reset forces:
vForces.x = 0.0f;
vForces.y = 0.0f;
// Aggregate forces:
// Gravity
vForces += vGravity;
// Still air drag
Vector vDrag;
Float fDrag;
fDrag = 0.5 * _AIRDENSITY * fSpeed * fSpeed *
(3.14159 * fRadius * fRadius) * _DRAGCOEFFICIENT;
vForces += vDrag;
// Wind
Vector vWind;
vWind.x = 0.5 * _AIRDENSITY * _WINDSPEED *
_WINDSPEED * (3.14159 * fRadius * fRadius) *
Search Nedrilad ::

Custom Search