public void Destroy(Contact c)
{
Shape shape1 = c.GetShape1();
Shape shape2 = c.GetShape2();
Body body1 = shape1.GetBody();
Body body2 = shape2.GetBody();
ContactPoint cp = new ContactPoint();
cp.Shape1 = shape1;
cp.Shape2 = shape2;
cp.Friction = Settings.MixFriction(shape1.Friction, shape2.Friction);
cp.Restitution = Settings.MixRestitution(shape1.Restitution, shape2.Restitution);
// Inform the user that this contact is ending.
int manifoldCount = c.GetManifoldCount();
if (manifoldCount > 0 && _world._contactListener!=null)
{
Manifold[] manifolds = c.GetManifolds();
for (int i = 0; i < manifoldCount; ++i)
{
Manifold manifold = manifolds[i];
cp.Normal = manifold.Normal;
for (int j = 0; j < manifold.PointCount; ++j)
{
ManifoldPoint mp = manifold.Points[j];
cp.Position = body1.GetWorldPoint(mp.LocalPoint1);
Vec2 v1 = body1.GetLinearVelocityFromLocalPoint(mp.LocalPoint1);
Vec2 v2 = body2.GetLinearVelocityFromLocalPoint(mp.LocalPoint2);
cp.Velocity = v2 - v1;
cp.Separation = mp.Separation;
cp.ID = mp.ID;
_world._contactListener.Remove(cp);
}
}
}
// Remove from the world.
if (c._prev != null)
{
c._prev._next = c._next;
}
if (c._next != null)
{
c._next._prev = c._prev;
}
if (c == _world._contactList)
{
_world._contactList = c._next;
}
// Remove from body 1
if (c._node1.Prev != null)
{
c._node1.Prev.Next = c._node1.Next;
}
if (c._node1.Next != null)
{
c._node1.Next.Prev = c._node1.Prev;
}
if (c._node1 == body1._contactList)
{
body1._contactList = c._node1.Next;
}
// Remove from body 2
if (c._node2.Prev != null)
{
c._node2.Prev.Next = c._node2.Next;
}
if (c._node2.Next != null)
{
c._node2.Next.Prev = c._node2.Prev;
}
if (c._node2 == body2._contactList)
{
body2._contactList = c._node2.Next;
}
// Call the factory.
Contact.Destroy(c);
--_world._contactCount;
}