Game Development Reference
In-Depth Information
Fb.x = 0.0f; Mb.x = 0.0f;
Fb.y = 0.0f; Mb.y = 0.0f;
Fb.z = 0.0f; Mb.z = 0.0f;
// Do drag force:
vDragVector = -Bodies[i].vVelocityBody;
vDragVector.Normalize();
speed = Bodies[i].vVelocityBody.Magnitude();
Fb += vDragVector * ((1.0f/2.0f)*speed * speed * rho *
LINEARDRAGCOEFFICIENT * pow(Bodies[i].fRadius,2) *
Bodies[i].fRadius*pi);
vAngularDragVector = -Bodies[i].vAngularVelocity;
vAngularDragVector.Normalize();
Mb += vAngularDragVector * (Bodies[i].vAngularVelocity.Magnitude() *
Bodies[i].vAngularVelocity.Magnitude() * rho * ANGULARDRAGCOEFFICIENT
* 4 * pow(Bodies[i].fRadius,2)*pi);
// Convert forces from model space to earth space:
Bodies[i].vForces = QVRotate(Bodies[i].qOrientation, Fb);
// Apply gravity:
Bodies[i].vForces.z += GRAVITY * Bodies[i].fMass;
// Save the moments:
Bodies[i].vMoments += Mb;
// Handle contacts with ground plane:
Bodies[i].vAcceleration = Bodies[i].vForces / Bodies[i].fMass;
Bodies[i].vAngularAcceleration = Bodies[i].mInertiaInverse *
(Bodies[i].vMoments -
(Bodies[i].vAngularVelocity^
(Bodies[i].mInertia *
Bodies[i].vAngularVelocity)));
// Resolve ground plane contacts:
FlushCollisionData();
pCollisionData = Collisions;
NumCollisions = 0;
if(DOCONTACT)
check = CheckGroundPlaneContacts(pCollisionData, i);
if((check == CONTACT) && DOCONTACT)
{ j = 0;
{
assert(NumCollisions <= 1);
ContactForce = (Bodies[i].fMass * (-Bodies[i].vAcceleration *
Collisions[j].vCollisionNormal)) *
Collisions[j].vCollisionNormal;
if(DOFRICTION)
Search Nedrilad ::




Custom Search