public Joint CreateJoint(JointDef def)
{
Debug.Assert(Locked == false);
if (Locked)
{
return null;
}
Joint j = Joint.Create(this, def);
// Connect to the world list.
j.Prev = null;
j.Next = JointList;
if (JointList != null)
{
JointList.Prev = j;
}
JointList = j;
++JointCount;
// Connect to the bodies' doubly linked lists.
j.EdgeA.Joint = j;
j.EdgeA.Other = j.BodyB;
j.EdgeA.Prev = null;
j.EdgeA.Next = j.BodyA.JointList;
if (j.BodyA.JointList != null)
{
j.BodyA.JointList.Prev = j.EdgeA;
}
j.BodyA.JointList = j.EdgeA;
j.EdgeB.Joint = j;
j.EdgeB.Other = j.BodyA;
j.EdgeB.Prev = null;
j.EdgeB.Next = j.BodyB.JointList;
if (j.BodyB.JointList != null)
{
j.BodyB.JointList.Prev = j.EdgeB;
}
j.BodyB.JointList = j.EdgeB;
Body bodyA = def.BodyA;
Body bodyB = def.BodyB;
// If the joint prevents collisions, then flag any contacts for filtering.
if (def.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;
}
}
// Note: creating a joint doesn't wake the bodies.
return j;
}