CreateJoint() публичный Метод

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
Результат Joint
 /** 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);
 }
Пример #2
0
        protected override void CreatePhysics(World world, float positionX, float positionY)
        {
            var frontWheelJointDef = new RevoluteJointDef();
            frontWheelJointDef.Initialize(CarBody.Body, FrontWheel.Body, FrontWheel.Body.GetWorldCenter());
            frontWheelJoint = (RevoluteJoint)world.CreateJoint(frontWheelJointDef);

            var backWheelJointDef = new RevoluteJointDef();
            backWheelJointDef.Initialize(CarBody.Body, BackWheel.Body, BackWheel.Body.GetWorldCenter());
            backWheelJoint = (RevoluteJoint)world.CreateJoint(backWheelJointDef);

            var poleJointDef = new RevoluteJointDef();

            var anchor = this.Pole.Body.GetWorldCenter();
            anchor.Y -= Pole.Height  ;
            poleJointDef.CollideConnected = false;
            poleJointDef.EnableLimit = true;
            poleJointDef.LowerAngle = Helper.DegreesToRad(-90);
            poleJointDef.UpperAngle = Helper.DegreesToRad(90);
            poleJointDef.Initialize(CarBody.Body, Pole.Body, anchor);
            poleJoint = (RevoluteJoint)world.CreateJoint(poleJointDef);
        }
Пример #3
0
        public PlayerCharacter(World _world, Vector2 _position)
            : base(_world, _position)
        {
            playerIndex = playerCount++;
            color = PlayerCharacter.Colors[playerIndex];
            accelerate = 0;
            rotate = 0;

            isDead = false;

            this.angVelocity = 0;
            //build the unicycle
            CircleDef circleDef = new CircleDef();
            circleDef.Radius = 1;
            circleDef.Density = 1f;
            circleDef.Friction = 1.0f;
            circleDef.Restitution = 0.0f;
            circleDef.LocalPosition.Set(0, 0);

            wheel = body.CreateShape(circleDef);
            body.SetMassFromShapes();
            body.SetUserData(this); // link body and this to register collisions in this

            //build the head and connect with the wheel
            BodyDef bodydef = new BodyDef();
            bodydef.Position = _position + new Vector2(0.0f, 3.5f);
            bodydef.Angle = 0f;

            chest = _world.CreateBody(bodydef);

            //add the head
            circleDef.Density = 0.0001f;
            circleDef.Radius = 0.75f;
            circleDef.LocalPosition.Set(0, 3);
            head = chest.CreateShape(circleDef);

            rotationHead = _position;

            PolygonDef Boxdef = new PolygonDef();
            Boxdef.SetAsBox(1, 1.5f);
            Boxdef.Density = 0.25f;
            Boxdef.Friction = 0.4f;
            Box2DX.Collision.Shape s2 = chest.CreateShape(Boxdef);
            chest.SetMassFromShapes();
            chest.SetUserData(this);

            //Jointshit
            RevoluteJointDef jointDefKW = new RevoluteJointDef();
            jointDefKW.Body2 = chest;
            jointDefKW.Body1 = body;
            jointDefKW.CollideConnected = false;
            jointDefKW.LocalAnchor2 = new Vector2(-0.0f, -3.8f);
            jointDefKW.LocalAnchor1 = new Vector2(0, 0);
            jointDefKW.EnableLimit = false;

            _world.CreateJoint(jointDefKW);

            // add visuals
            Texture wheelTexture = AssetManager.getTexture(AssetManager.TextureName.ShoopWheel);
            wheelSprite = new AnimatedSprite(wheelTexture, 1.0f, 1, (Vector2)wheelTexture.Size);
            wheelSprite.Scale = Constants.windowScaleFactor * new Vector2(0.2f, 0.2f); //(Vector2.One / (Vector2)wheelTexture.Size * 2F * circleDef.Radius).toScreenCoord() - Vector2.Zero.toScreenCoord();//new Vector2(0.08f, 0.08f);
            wheelSprite.Origin = ((Vector2)wheelSprite.spriteSize) / 2F;

            sheepSprite = new Sprite(AssetManager.getTexture(AssetManager.TextureName.ShoopInfronUnicycle));
            sheepSprite.Origin = ((Vector2)sheepSprite.Texture.Size) / 2F;
            sheepSprite.Scale = Constants.windowScaleFactor *  new Vector2(_position.X > Constants.worldSizeX / 2F ? -0.2f : 0.2f, 0.2f);
        }
        private void SetupJointsHelper(World world)
        {
            if (children.Count == 0)
            {
                //If there are no children left, set up the final plank and stop recursing
                CreateEndJoint(world, false);
                return;
            }

            //nextBoard is the next piece of the bridge
            RopeBridge nextBoard = children[0] as RopeBridge;

            // Attach this board's body to nextBoard's body with a joint
            /////////////////////////////////////////////////

            RevoluteJointDef joint = new RevoluteJointDef();
            Vector2 anchor = Position + new Vector2(width / 2, 0);
            joint.Initialize(Body, nextBoard.Body, Utils.Convert(anchor));
            world.CreateJoint(joint);

            /////////////////////////////////////////////////

            nextBoard.SetupJointsHelper(world);
        }
Пример #5
0
        public Biped(World w, Vec2 position)
        {
            m_world = w;

            BipedDef def = new BipedDef();
            BodyDef bd;

            // create body parts
            bd = def.LFootDef;
            bd.Position += position;
            LFoot = w.CreateBody(bd);
            LFoot.CreateShape(def.LFootPoly);
            LFoot.SetMassFromShapes();

            bd = def.RFootDef;
            bd.Position += position;
            RFoot = w.CreateBody(bd);
            RFoot.CreateShape(def.RFootPoly);
            RFoot.SetMassFromShapes();

            bd = def.LCalfDef;
            bd.Position += position;
            LCalf = w.CreateBody(bd);
            LCalf.CreateShape(def.LCalfPoly);
            LCalf.SetMassFromShapes();

            bd = def.RCalfDef;
            bd.Position += position;
            RCalf = w.CreateBody(bd);
            RCalf.CreateShape(def.RCalfPoly);
            RCalf.SetMassFromShapes();

            bd = def.LThighDef;
            bd.Position += position;
            LThigh = w.CreateBody(bd);
            LThigh.CreateShape(def.LThighPoly);
            LThigh.SetMassFromShapes();

            bd = def.RThighDef;
            bd.Position += position;
            RThigh = w.CreateBody(bd);
            RThigh.CreateShape(def.RThighPoly);
            RThigh.SetMassFromShapes();

            bd = def.PelvisDef;
            bd.Position += position;
            Pelvis = w.CreateBody(bd);
            Pelvis.CreateShape(def.PelvisPoly);
            Pelvis.SetMassFromShapes();

            bd = def.PelvisDef;
            bd.Position += position;
            Stomach = w.CreateBody(bd);
            Stomach.CreateShape(def.StomachPoly);
            Stomach.SetMassFromShapes();

            bd = def.ChestDef;
            bd.Position += position;
            Chest = w.CreateBody(bd);
            Chest.CreateShape(def.ChestPoly);
            Chest.SetMassFromShapes();

            bd = def.NeckDef;
            bd.Position += position;
            Neck = w.CreateBody(bd);
            Neck.CreateShape(def.NeckPoly);
            Neck.SetMassFromShapes();

            bd = def.HeadDef;
            bd.Position += position;
            Head = w.CreateBody(bd);
            Head.CreateShape(def.HeadCirc);
            Head.SetMassFromShapes();

            bd = def.LUpperArmDef;
            bd.Position += position;
            LUpperArm = w.CreateBody(bd);
            LUpperArm.CreateShape(def.LUpperArmPoly);
            LUpperArm.SetMassFromShapes();

            bd = def.RUpperArmDef;
            bd.Position += position;
            RUpperArm = w.CreateBody(bd);
            RUpperArm.CreateShape(def.RUpperArmPoly);
            RUpperArm.SetMassFromShapes();

            bd = def.LForearmDef;
            bd.Position += position;
            LForearm = w.CreateBody(bd);
            LForearm.CreateShape(def.LForearmPoly);
            LForearm.SetMassFromShapes();

            bd = def.RForearmDef;
            bd.Position += position;
            RForearm = w.CreateBody(bd);
            RForearm.CreateShape(def.RForearmPoly);
            RForearm.SetMassFromShapes();

            bd = def.LHandDef;
            bd.Position += position;
            LHand = w.CreateBody(bd);
            LHand.CreateShape(def.LHandPoly);
            LHand.SetMassFromShapes();

            bd = def.RHandDef;
            bd.Position += position;
            RHand = w.CreateBody(bd);
            RHand.CreateShape(def.RHandPoly);
            RHand.SetMassFromShapes();

            // link body parts
            def.LAnkleDef.Body1 = LFoot;
            def.LAnkleDef.Body2 = LCalf;
            def.RAnkleDef.Body1 = RFoot;
            def.RAnkleDef.Body2 = RCalf;
            def.LKneeDef.Body1 = LCalf;
            def.LKneeDef.Body2 = LThigh;
            def.RKneeDef.Body1 = RCalf;
            def.RKneeDef.Body2 = RThigh;
            def.LHipDef.Body1 = LThigh;
            def.LHipDef.Body2 = Pelvis;
            def.RHipDef.Body1 = RThigh;
            def.RHipDef.Body2 = Pelvis;
            def.LowerAbsDef.Body1 = Pelvis;
            def.LowerAbsDef.Body2 = Stomach;
            def.UpperAbsDef.Body1 = Stomach;
            def.UpperAbsDef.Body2 = Chest;
            def.LowerNeckDef.Body1 = Chest;
            def.LowerNeckDef.Body2 = Neck;
            def.UpperNeckDef.Body1 = Chest;
            def.UpperNeckDef.Body2 = Head;
            def.LShoulderDef.Body1 = Chest;
            def.LShoulderDef.Body2 = LUpperArm;
            def.RShoulderDef.Body1 = Chest;
            def.RShoulderDef.Body2 = RUpperArm;
            def.LElbowDef.Body1 = LForearm;
            def.LElbowDef.Body2 = LUpperArm;
            def.RElbowDef.Body1 = RForearm;
            def.RElbowDef.Body2 = RUpperArm;
            def.LWristDef.Body1 = LHand;
            def.LWristDef.Body2 = LForearm;
            def.RWristDef.Body1 = RHand;
            def.RWristDef.Body2 = RForearm;

            // create joints
            LAnkle = (RevoluteJoint)w.CreateJoint(def.LAnkleDef);
            RAnkle = (RevoluteJoint)w.CreateJoint(def.RAnkleDef);
            LKnee = (RevoluteJoint)w.CreateJoint(def.LKneeDef);
            RKnee = (RevoluteJoint)w.CreateJoint(def.RKneeDef);
            LHip = (RevoluteJoint)w.CreateJoint(def.LHipDef);
            RHip = (RevoluteJoint)w.CreateJoint(def.RHipDef);
            LowerAbs = (RevoluteJoint)w.CreateJoint(def.LowerAbsDef);
            UpperAbs = (RevoluteJoint)w.CreateJoint(def.UpperAbsDef);
            LowerNeck = (RevoluteJoint)w.CreateJoint(def.LowerNeckDef);
            UpperNeck = (RevoluteJoint)w.CreateJoint(def.UpperNeckDef);
            LShoulder = (RevoluteJoint)w.CreateJoint(def.LShoulderDef);
            RShoulder = (RevoluteJoint)w.CreateJoint(def.RShoulderDef);
            LElbow = (RevoluteJoint)w.CreateJoint(def.LElbowDef);
            RElbow = (RevoluteJoint)w.CreateJoint(def.RElbowDef);
            LWrist = (RevoluteJoint)w.CreateJoint(def.LWristDef);
            RWrist = (RevoluteJoint)w.CreateJoint(def.RWristDef);
        }