struct CrushingContext {
cpFloat magnitudeSum;
cpVect vectorSum;
};
static void
EstimateCrushingHelper(cpBody *body, cpArbiter *arb, struct CrushingContext *context)
{
cpVect j = cpArbiterTotalImpulseWithFriction(arb);
context->magnitudeSum += cpvlength(j);
context->vectorSum = cpvadd(context->vectorSum, j);
}
cpFloat
EstimateCrushForce(cpBody *body, cpFloat dt)
{
struct CrushingContext crush = {0.0f, cpvzero};
cpBodyEachArbiter(body, (cpBodyArbiterIteratorFunc)EstimateCrushingHelper, &crush);
// Compare the vector sum magnitude and magnitude sum to see if
// how much the collision forces oppose one another.
cpFloat crushForce = (crush.magnitudeSum - cpvlength(crush.vectorSum))*dt;
}