I've developed two different collision routines.
The first is far better at conservation of momentum, while the second yields more precise resultant vectors. But the magnitude of such results are not at all accurate as the first's.
This first code:
VB Code:
If Points(Y).Size < 1 Then Points(Y).Size = 1 pd = (Points(X).Size / Points(Y).Size) / 2 P1mx = (Points(X).Move.X) P1my = (Points(X).Move.Y) If Points(X).Size < 1 Then Points(X).Size = 1 If Points(X).Size > Points(Y).Size Then pd = (Points(X).Size / Points(Y).Size) Points(X).Move.X = (Points(Y).Move.X / pd) * Fric Points(X).Move.Y = (Points(Y).Move.Y / pd) * Fric Points(Y).Move.X = (P1mx * pd) * Fric Points(Y).Move.Y = (P1my * pd) * Fric ' Else pd = (Points(Y).Size / (Points(X).Size)) Points(X).Move.X = (Points(Y).Move.X * pd) * Fric Points(X).Move.Y = (Points(Y).Move.Y * pd) * Fric Points(Y).Move.X = (P1mx / pd) * Fric Points(Y).Move.Y = (P1my / pd) * Fric End If
The second.
VB Code:
pxmx = Points(X).Move.X pxmy = Points(X).Move.Y pymx = Points(Y).Move.X pymy = Points(Y).Move.Y If Points(X).Size > Points(Y).Size Then Points(X).Move.X = (((xRadii + yRadii) * xd) / dist * Fric) Points(X).Move.Y = (((xRadii + yRadii) * yd) / dist * Fric) Points(Y).Move.X = -(((xRadii + yRadii) * xd) / dist * Fric) Points(Y).Move.Y = -(((xRadii + yRadii) * yd) / dist * Fric) Else Points(X).Move.X = (((xRadii + yRadii) * xd) / dist * Fric) Points(X).Move.Y = (((xRadii + yRadii) * yd) / dist * Fric) Points(Y).Move.X = -(((xRadii + yRadii) * xd) / dist * Fric) Points(Y).Move.X = -(((xRadii + yRadii) * yd) / dist * Fric) End If
Points is defined as:
VB Code:
Private Points() As pPoint 'pPoint is: Private Type pPoint Loc As sPoint Move As sPoint Size As Long Color As rgbCol LastColl As Long End Type 'which uses: Private Type sPoint X As Single Y As Single End Type Private Type rgbCol r As Long g As Long b As Long End Type
When colliding:
VB Code:
If dist > 1 Then Points(X).Loc.X = Points(Y).Loc.X + ((xRadii + yRadii) * xd) / dist Points(X).Loc.Y = Points(Y).Loc.Y + ((xRadii + yRadii) * yd) / dist Points(Y).Loc.X = Points(X).Loc.X - ((xRadii + yRadii) * xd) / dist Points(Y).Loc.Y = Points(X).Loc.Y - ((xRadii + yRadii) * yd) / dist End If
Sets each particle's location out of the other particle.




Reply With Quote