Box2DX.Dynamics.World.CreateJoint C# (CSharp) Method

CreateJoint() public method

Create a joint to constrain bodies together. No reference to the definition is retained. This may cause the connected bodies to cease colliding. @warning This function is locked during callbacks.
public CreateJoint ( JointDef def ) : Joint
def JointDef
return Joint
        public Joint CreateJoint(JointDef def)
        {
            Box2DXDebug.Assert(_lock == false);

            Joint j = Joint.Create(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._node1.Joint = j;
            j._node1.Other = j._body2;
            j._node1.Prev = null;
            j._node1.Next = j._body1._jointList;
            if (j._body1._jointList != null)
                j._body1._jointList.Prev = j._node1;
            j._body1._jointList = j._node1;

            j._node2.Joint = j;
            j._node2.Other = j._body1;
            j._node2.Prev = null;
            j._node2.Next = j._body2._jointList;
            if (j._body2._jointList != null)
                j._body2._jointList.Prev = j._node2;
            j._body2._jointList = j._node2;

            // If the joint prevents collisions, then reset collision filtering.
            if (def.CollideConnected == false)
            {
                // Reset the proxies on the body with the minimum number of shapes.
                Body b = def.Body1._shapeCount < def.Body2._shapeCount ? def.Body1 : def.Body2;
                for (Shape s = b._shapeList; s != null; s = s._next)
                {
                    s.RefilterProxy(_broadPhase, b.GetXForm());
                }
            }

            return j;
        }

Usage Example

 /** Handles anchoring the first and last pieces of the bridge
  * to the world versus to other bridge pieces
  */
 private void CreateEndJoint(World world, bool leftEnd)
 {
     RevoluteJointDef joint = new RevoluteJointDef();
     Vector2 anchor = Position - new Vector2(width/2, 0);
     if (!leftEnd)
         anchor = Position + new Vector2(width / 2, 0);
     joint.Initialize(Body, world.GetGroundBody(), Utils.Convert(anchor));
     world.CreateJoint(joint);
 }
All Usage Examples Of Box2DX.Dynamics.World::CreateJoint