I'm glad to have found this forum. The thing is that I'm currently working on a small simulation mainly instructed by Chris Hecker's articles. I've figured out the collision detection through line intersections which are reconstructed to edges and vertices and this part seems to work fine, at least to my standards. Now the problem is that my collision response part behaves in quite a strange way, that is the angular component seems to be resolved nicely while there is practically no change in linear momentum, i.e. bodies which don't collide spinning and near their vertices just interpenetrate with minimal deflection. So as a last resort and after much tinkering around I decided to eliminate the angular portion of the impulse equation. I'm not sure about how it's supposed to look, but now it seemed as if the linear part was working acceptably as long as the body was NOT spinning or just rotating lightly, else the impulse went through the roof. It's coded in Blitzmax. Here's the Collision Resolve function: + I had to upload the program to megaupload as it was too big to attach: http://www.2shared.com/file/2747637/78e ... ation.html
Left Mouse -> Pull; Right -> Hold and Move
Code: Select all
Function ResolveBodyCollision(A:Body, B:Body, PerpA:Vector, PerpB:Vector, VAB:Vector, Unit:Vector)
Local e# = 0.6
Local n1#, n2#
Local dot1#, dot2#
Local dn1#, dn2#, dn3#, dn4#
Local n#
Local dn#
Local imp#
Local I:Vector = New Vector
n1 = -1*(1+e)
n2 = Vector.Dot(VAB, Unit)
dot1 = Vector.Dot(PerpA, Unit)
dot2 = Vector.Dot(PerpB, Unit)
dn1 = Vector.Dot(Unit, Unit)
dn2 = (A.mass + B.mass)/(A.mass*B.mass)
dn3 = (dot1^2))/A.moi
dn4 = (dot2^2))/B.moi
n = n1*n2
dn = dn1*dn2 + dn3 + dn4
imp = n/dn
I = Vector.Scale(Unit, imp)
A.Vel = Vector.Add(A.Vel, Vector.Scale(I, (1/A.mass)))
B.Vel = Vector.Sub(B.Vel, Vector.Scale(I, (1/B.mass)))
A.angvel = A.angvel + (Vector.Dot(PerpA, I))/A.moi
B.angvel = B.angvel - (Vector.Dot(PerpB, I))/B.moi
End Function
Lowv