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;
}
public void DestroyBody(Body b) { Box2DXDebug.Assert(_bodyCount > 0); Box2DXDebug.Assert(IsLocked() == false); if (IsLocked()) { return; } // Delete the attached joints. JointEdge je = b._jointList; while (je != null) { JointEdge je0 = je; je = je.Next; if (_destructionListener != null) { _destructionListener.SayGoodbye(je0.Joint); } DestroyJoint(je0.Joint); } b._jointList = null; // Delete the attached contacts. ContactEdge ce = b._contactList; while (ce != null) { ContactEdge ce0 = ce; ce = ce.Next; _contactManager.Destroy(ce0.Contact); } b._contactList = null; // Delete the attached fixtures. This destroys broad-phase proxies. Fixture f = b._fixtureList; while (f != null) { Fixture f0 = f; f = f._next; if (_destructionListener != null) { _destructionListener.SayGoodbye(f0); } f0.Destroy(_contactManager._broadPhase); f0 = null; } b._fixtureList = null; b._fixtureCount = 0; // Remove world body list. if (b._prev != null) { b._prev._next = b._next; } if (b._next != null) { b._next._prev = b._prev; } if (b == _bodyList) { _bodyList = b._next; } --_bodyCount; b = null; }