I'm trying to implement impulse response with friction and I can't get it to work. I have compared other implementations that I found but I can't find any errors in my code. So what happens is as soon as object stops bouncing (bouncing works) it starts to slide and accelerate indefinitely. I'm testing this using sphere and plane.
e0->pos += e0->getVel() * info->getContactTime(); e1->pos += e1->getVel() * info->getContactTime(); vec3 n = info->getNormal(); vec3 r0 = info->getContactPoint() - e0->pos; vec3 r1 = info->getContactPoint() - e1->pos; vec3 v0 = e0->getVel() + cross( r0, e0->angVel ); vec3 v1 = e1->getVel() + cross( r1, e1->angVel ); vec3 dv = v1 - v0; float e = 0.5; float f = 0.1; float num = (1+e) * dot(dv,n); float denom = e0->massInv + e1->massInv + dot( e0->getWorldInertiaInv() * cross(cross(r0,n),r0) + e1->getWorldInertiaInv() * cross(cross(r1,n),r1) ,n ); float jr = num / denom; e0->applyImpulse( r0, n * jr ); e1->applyImpulse( r1, -n * jr ); vec3 t = normalize( cross( n, cross( dv, n ) ) ); num = -dot(dv,t); denom = e0->massInv + e1->massInv + dot( e0->getWorldInertiaInv() * cross(cross(r0,t),r0) + e1->getWorldInertiaInv() * cross(cross(r1,t),r1) ,t ); float jf = num / denom; jf = clamp( jf, -jr * f, jr * f ); e0->applyImpulse( r0, jf * t ); e1->applyImpulse( r1, -jf * t );
Other implementations I've tried:
http://www.gamedev.net/topic/465248-calculating-impulse-due-to-rigid-body-collision-with-friction/
http://en.wikipedia.org/wiki/Collision_response#Impulse-Based_Reaction_Model






