Advertisement

2D vector collision response

Started by March 20, 2002 12:18 AM
-1 comments, last by eotvos 22 years, 11 months ago
These are the equations I've come up with, please respond with comments, corrections, etc.. Basically these are the equations given by Chris Hecker in his 3rd article on Rigid Body Dynamics, minus the rotation segment. the CVector class I'm using here is from http://www.cfxweb.net/~baskuene/vector.htm
      
void bounce(object &a, object &b)
{
		
		float e = coef;
		float m1 = a.mass;
		float m2 = b.mass;
		CVector C;
		C.x = centerx(a) - centerx(b);
		C.y = centery(a) - centery(b);
		CVector Vab = a.velocity - b.velocity;
		CVector n = GetNormal(C);

		float impNumerator = -(1+e)*(Vab % n);
		float impDenominator = ((n*(1/m1 + 1/m2)) % n);
		float impulse = impNumerator / impDenominator;			
		a.velocity += n*(impulse/m1);
		b.velocity -= n*(impulse/m2);
						
}

      
*Just in case you're confused, the CVector class has an inlined modulus operator returning the dot product. Edited by - eotvos on March 20, 2002 1:23:39 AM

This topic is closed to new replies.

Advertisement