Game Development Reference
In-Depth Information
{
double vt = fabs(Collisions[j].vRelativeVelocity *
Collisions[j].vCollisionTangent);
if(vt > VELOCITYTOLERANCE)
{
// Kinetic:
FrictionForce = (ContactForce.Magnitude() *
FRICTIONCOEFFICIENTGROUND) *
Collisions[j].vCollisionTangent;
} else {
// Static:
FrictionForce = (ContactForce.Magnitude() *
FRICTIONCOEFFICIENTGROUND * 2 *
vt/VELOCITYTOLERANCE) *
Collisions[j].vCollisionTangent;
}
} else
FrictionForce.x = FrictionForce.y = FrictionForce.z = 0;
// Do rolling resistance:
if(Bodies[i].vAngularVelocity.Magnitude() > VELOCITYTOLERANCE)
{
FRn = ContactForce.Magnitude() *
Collisions[j].vCollisionNormal;
Collisions[j].vCollisionTangent.Normalize();
Vector m = (Collisions[j].vCollisionTangent
*(ROLLINGRESISTANCECOEFFICIENT *
Bodies[i].fRadius))^FRn;
double mag = m.Magnitude();
Vector a = Bodies[i].vAngularVelocity;
a.Normalize();
Bodies[i].vMoments += -a * mag;
}
// accumlate contact and friction forces and moments
Bodies[i].vForces += ContactForce;
Bodies[i].vForces += FrictionForce;
ContactForce = QVRotate(~Bodies[i].qOrientation, ContactForce);
FrictionForce = QVRotate(~Bodies[i].qOrientation,
FrictionForce);
pt = Collisions[j].vCollisionPoint - Bodies[i].vPosition;
pt = QVRotate(~Bodies[i].qOrientation, pt);
Bodies[i].vMoments += pt^ContactForce;
Bodies[i].vMoments += pt^FrictionForce;
}
}
}
}
Search Nedrilad ::




Custom Search