Game Development Reference
In-Depth Information
for(i=0; i<NumCollisions; i++)
{
b1 = Collisions[i].body1;
b2 = Collisions[i].body2;
if( (b1 != −1) && (b1 != b2) )
{
if(b2 != −1) // not ground plane
{
pt1 = Collisions[i].vCollisionPoint - Bodies[b1].vPosition;
pt2 = Collisions[i].vCollisionPoint - Bodies[b2].vPosition;
// Calculate impulse:
j = (-(1+fCr) * (Collisions[i].vRelativeVelocity *
Collisions[i].vCollisionNormal)) /
((1/Bodies[b1].fMass + 1/Bodies[b2].fMass) +
(Collisions[i].vCollisionNormal * ( ( (pt1 ^
Collisions[i].vCollisionNormal) *
Bodies[b1].mIeInverse )^pt1) ) +
(Collisions[i].vCollisionNormal * ( ( (pt2 ^
Collisions[i].vCollisionNormal) *
Bodies[b2].mIeInverse )^pt2) ) );
Vrt = Collisions[i].vRelativeVelocity *
Collisions[i].vCollisionTangent;
if(fabs(Vrt) > 0.0 && dofriction) {
Bodies[b1].vVelocity +=
((j * Collisions[i].vCollisionNormal) +
((muB * j) * Collisions[i].vCollisionTangent)) /
Bodies[b1].fMass;
Bodies[b1].vAngularVelocityGlobal +=
(pt1 ^ ((j * Collisions[i].vCollisionNormal) +
((muB * j) * Collisions[i].vCollisionTangent))) *
Bodies[b1].mIeInverse;
Bodies[b1].vAngularVelocity =
QVRotate(~Bodies[b1].qOrientation,
Bodies[b1].vAngularVelocityGlobal);
Bodies[b2].vVelocity +=
((-j * Collisions[i].vCollisionNormal) + ((muB *
j) * Collisions[i].vCollisionTangent)) /
Bodies[b2].fMass;
Bodies[b2].vAngularVelocityGlobal +=
(pt2 ^ ((-j * Collisions[i].vCollisionNormal) +
((muB * j) * Collisions[i].vCollisionTangent)))
* Bodies[b2].mIeInverse;
Bodies[b2].vAngularVelocity =
QVRotate(~Bodies[b2].qOrientation,
Bodies[b2].vAngularVelocityGlobal);
Search Nedrilad ::




Custom Search