Box2D.Dynamics.World.DestroyJoint C# (CSharp) Method

DestroyJoint() public method

destroy a joint. This may cause the connected bodies to begin colliding.
public DestroyJoint ( Joint j ) : void
j Box2D.Dynamics.Joints.Joint
return void
        public void DestroyJoint(Joint j)
        {
            Debug.Assert(Locked == false);
            if (Locked)
            {
                return;
            }

            bool collideConnected = j.CollideConnected;

            // Remove from the doubly linked list.
            if (j.Prev != null)
            {
                j.Prev.Next = j.Next;
            }

            if (j.Next != null)
            {
                j.Next.Prev = j.Prev;
            }

            if (j == JointList)
            {
                JointList = j.Next;
            }

            // Disconnect from island graph.
            Body bodyA = j.BodyA;
            Body bodyB = j.BodyB;

            // Wake up connected bodies.
            bodyA.Awake = true;
            bodyB.Awake = true;

            // Remove from body 1.
            if (j.EdgeA.Prev != null)
            {
                j.EdgeA.Prev.Next = j.EdgeA.Next;
            }

            if (j.EdgeA.Next != null)
            {
                j.EdgeA.Next.Prev = j.EdgeA.Prev;
            }

            if (j.EdgeA == bodyA.JointList)
            {
                bodyA.JointList = j.EdgeA.Next;
            }

            j.EdgeA.Prev = null;
            j.EdgeA.Next = null;

            // Remove from body 2
            if (j.EdgeB.Prev != null)
            {
                j.EdgeB.Prev.Next = j.EdgeB.Next;
            }

            if (j.EdgeB.Next != null)
            {
                j.EdgeB.Next.Prev = j.EdgeB.Prev;
            }

            if (j.EdgeB == bodyB.JointList)
            {
                bodyB.JointList = j.EdgeB.Next;
            }

            j.EdgeB.Prev = null;
            j.EdgeB.Next = null;

            Joint.Destroy(j);

            Debug.Assert(JointCount > 0);
            --JointCount;

            // If the joint prevents collisions, then flag any contacts for filtering.
            if (collideConnected == false)
            {
                ContactEdge edge = bodyB.ContactList;
                while (edge != null)
                {
                    if (edge.Other == bodyA)
                    {
                        // Flag the contact for filtering at the next time step (where either
                        // body is awake).
                        edge.Contact.SetFlagForFiltering();
                    }

                    edge = edge.Next;
                }
            }
        }