By now I've read most of it and I think i get a good hang on implementing rigid bodies..
However, this complex algorithm which is used for collision response (bullet seems to use a smimilar formula) I can't get it to work nor figure it out:
Code: Select all
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) + ((mu * j) * Collisions[i].vCollisionTangent) ) / Bodies[b1].fMass;
Bodies[b1].vAngularVelocityGlobal += (pt1 ^ ((j * Collisions[i].vCollisionNormal) + ((mu * j) * Collisions[i].vCollisionTangent)))*Bodies[b1].mIeInverse;
//separate b2 in the opposite impulse
} else {
same thing but "mu" (friction coefficient) seems considered zero
}
pt1 and pt2 are the points in both rigid bodies' local coordinates (but not rotation).
vRelativeVelocity is both velocities at the collision point (with linear and angular processed), and then the difference, as in vel_obj1 - vel_obj2
but my doubt is.. what is exactly the collision normal vCollisionNormal ? is it a vector from the collision point, pointing orthogonally from the surfaces towards object 1 ?
Also, is there a place where this algorithm is properly explained? or should i just use it "as is" ?