Game Development Reference
In-Depth Information
} else {
// Apply impulse:
Bodies[b1].vVelocity +=
(j * Collisions[i].vCollisionNormal) /
Bodies[b1].fMass;
Bodies[b1].vAngularVelocityGlobal +=
(pt1 ^ (j * Collisions[i].vCollisionNormal)) *
Bodies[b1].mIeInverse;
Bodies[b1].vAngularVelocity =
QVRotate(~Bodies[b1].qOrientation,
Bodies[b1].vAngularVelocityGlobal);
Bodies[b2].vVelocity -=
(j * Collisions[i].vCollisionNormal) /
Bodies[b2].fMass;
Bodies[b2].vAngularVelocityGlobal -=
(pt2 ^ (j * Collisions[i].vCollisionNormal)) *
Bodies[b2].mIeInverse;
Bodies[b2].vAngularVelocity =
QVRotate(~Bodies[b2].qOrientation,
Bodies[b2].vAngularVelocityGlobal);
}
} else { // Ground plane:
fCr = COEFFICIENTOFRESTITUTIONGROUND;
pt1 = Collisions[i].vCollisionPoint - Bodies[b1].vPosition;
// Calculate impulse:
j = (-(1+fCr) * (Collisions[i].vRelativeVelocity *
Collisions[i].vCollisionNormal)) /
( (1/Bodies[b1].fMass) +
(Collisions[i].vCollisionNormal *
( ( (pt1 ^ Collisions[i].vCollisionNormal) *
Bodies[b1].mIeInverse )^pt1)));
Vrt = Collisions[i].vRelativeVelocity *
Collisions[i].vCollisionTangent;
if(fabs(Vrt) > 0.0 && dofriction) {
Bodies[b1].vVelocity +=
( (j * Collisions[i].vCollisionNormal) + ((muG *
j) * Collisions[i].vCollisionTangent) ) /
Bodies[b1].fMass;
Bodies[b1].vAngularVelocityGlobal +=
(pt1 ^ ((j * Collisions[i].vCollisionNormal) +
((muG * j) * Collisions[i].vCollisionTangent))) *
Bodies[b1].mIeInverse;
Bodies[b1].vAngularVelocity =
QVRotate(~Bodies[b1].qOrientation,
Bodies[b1].vAngularVelocityGlobal);
} else {
Search Nedrilad ::




Custom Search