Game Development Reference
In-Depth Information
on a particle. You'll see later that it is possible for a particle to collide with more than
one object at the same time. bCollision is simply a flag that is used to indicate whether
or not a collision has been detected with the particle at the current time step. This is
important because when a collision occurs, at that instant in time, we assume that the
only forces acting on the particle are the impact forces; all of the other forces—gravity,
drag, and wind—are ignored for that time instant. We use bCollision in the updated
CalcLoads method:
void Particle::CalcLoads(void)
{
// Reset forces:
vForces.x = 0.0f;
vForces.y = 0.0f;
// Aggregate forces:
if(bCollision) {
// Add Impact forces (if any)
vForces += vImpactForces;
} else {
// Gravity
vForces += vGravity;
// Still air drag
Vector vDrag;
float fDrag;
vDrag -= vVelocity;
vDrag.Normalize();
fDrag = 0.5 * _AIRDENSITY * fSpeed * fSpeed *
(3.14159 * fRadius * fRadius) * _DRAGCOEFFICIENT;
vDrag *= fDrag;
vForces += vDrag;
// Wind
Vector vWind;
vWind.x = 0.5 * _AIRDENSITY * _WINDSPEED * _WINDSPEED *
(3.14159 * fRadius * fRadius) * _DRAGCOEFFICIENT;
vForces += vWind;
}
}
The only difference between this version of CalcLoads and the previous one is that we
added the conditional if(bCollision) { ... } else { ... } . If bCollision is true,
then we have a collision to deal with and the only forces that get aggregated are the
impact forces. If there is no collision, if bCollision is false, then the non-impact forces
are aggregated in the usual manner.
You may have caught that we are aggregating impact forces in this example. This is an
alternate approach to the one shown in Chapter 5 . There we showed you how to calculate
an impulse and change an object's velocity in response to a collision, using conservation
Search Nedrilad ::




Custom Search