当前位置: 首页>>代码示例>>C#>>正文


C# Body.SetTransform方法代码示例

本文整理汇总了C#中FarseerPhysics.Dynamics.Body.SetTransform方法的典型用法代码示例。如果您正苦于以下问题:C# Body.SetTransform方法的具体用法?C# Body.SetTransform怎么用?C# Body.SetTransform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FarseerPhysics.Dynamics.Body的用法示例。


在下文中一共展示了Body.SetTransform方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TheoJansenWalker

        public TheoJansenWalker(World world, PhysicsGameScreen screen, Vector2 position)
        {
            _position = position;
            _motorSpeed = 2.0f;
            _motorOn = true;
            _screen = screen;

            _walkerJoints = new List<DistanceJoint>();

            _leftShoulders = new Body[3];
            _rightShoulders = new Body[3];
            _leftLegs = new Body[3];
            _rightLegs = new Body[3];

            Vector2 pivot = new Vector2(0f, -0.8f);

            // Chassis
            {
                PolygonShape shape = new PolygonShape(1f);
                shape.SetAsBox(2.5f, 1.0f);

                _body =
                    new Sprite(_screen.ScreenManager.Assets.TextureFromShape(shape, MaterialType.Blank,
                                                                             Color.Beige, 1f));

                _chassis = BodyFactory.CreateBody(world);
                _chassis.BodyType = BodyType.Dynamic;
                _chassis.Position = pivot + _position;

                Fixture fixture = _chassis.CreateFixture(shape);
                fixture.CollisionGroup = -1;
            }

            {
                CircleShape shape = new CircleShape(1.6f, 1f);
                _engine =
                    new Sprite(_screen.ScreenManager.Assets.TextureFromShape(shape, MaterialType.Waves,
                                                                             Color.Beige * 0.8f, 1f));

                _wheel = BodyFactory.CreateBody(world);
                _wheel.BodyType = BodyType.Dynamic;
                _wheel.Position = pivot + _position;

                Fixture fixture = _wheel.CreateFixture(shape);
                fixture.CollisionGroup = -1;
            }

            {
                _motorJoint = new RevoluteJoint(_wheel, _chassis, _wheel.GetLocalPoint(_chassis.Position), Vector2.Zero);
                _motorJoint.CollideConnected = false;
                _motorJoint.MotorSpeed = _motorSpeed;
                _motorJoint.MaxMotorTorque = 400f;
                _motorJoint.MotorEnabled = _motorOn;
                world.AddJoint(_motorJoint);
            }

            Vector2 wheelAnchor = pivot + new Vector2(0f, 0.8f);

            CreateLegTextures();

            CreateLeg(world, -1f, wheelAnchor, 0);
            CreateLeg(world, 1f, wheelAnchor, 0);

            _leftLeg.Origin = AssetCreator.CalculateOrigin(_leftLegs[0]);
            _leftShoulder.Origin = AssetCreator.CalculateOrigin(_leftShoulders[0]);
            _rightLeg.Origin = AssetCreator.CalculateOrigin(_rightLegs[0]);
            _rightShoulder.Origin = AssetCreator.CalculateOrigin(_rightShoulders[0]);

            _wheel.SetTransform(_wheel.Position, 120f * Settings.Pi / 180f);
            CreateLeg(world, -1f, wheelAnchor, 1);
            CreateLeg(world, 1f, wheelAnchor, 1);

            _wheel.SetTransform(_wheel.Position, -120f * Settings.Pi / 180f);
            CreateLeg(world, -1f, wheelAnchor, 2);
            CreateLeg(world, 1f, wheelAnchor, 2);
        }
开发者ID:hilts-vaughan,项目名称:Farseer-Physics,代码行数:76,代码来源:TheoJansen.cs

示例2: TheoJansenTest

        private TheoJansenTest()
        {
            _offset = new Vector2(0.0f, 8.0f);
            _motorSpeed = 2.0f;
            _motorOn = true;
            Vector2 pivot = new Vector2(0.0f, 0.8f);

            // Ground
            {
                Body ground = BodyFactory.CreateEdge(World, new Vector2(-50.0f, 0.0f), new Vector2(50.0f, 0.0f));
                FixtureFactory.AttachEdge(new Vector2(-50.0f, 0.0f), new Vector2(-50.0f, 10.0f), ground);
                FixtureFactory.AttachEdge(new Vector2(50.0f, 0.0f), new Vector2(50.0f, 10.0f), ground);
            }

            // Balls
            for (int i = 0; i < 40; ++i)
            {
                CircleShape shape = new CircleShape(0.25f, 1);

                Body body = BodyFactory.CreateBody(World);
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(-40.0f + 2.0f * i, 0.5f);

                body.CreateFixture(shape);
            }

            // Chassis
            {
                PolygonShape shape = new PolygonShape(1);
                shape.Vertices = PolygonTools.CreateRectangle(2.5f, 1.0f);

                _chassis = BodyFactory.CreateBody(World);
                _chassis.BodyType = BodyType.Dynamic;
                _chassis.Position = pivot + _offset;

                Fixture fixture = _chassis.CreateFixture(shape);
                fixture.CollisionGroup = -1;
            }

            {
                CircleShape shape = new CircleShape(1.6f, 1);

                _wheel = BodyFactory.CreateBody(World);
                _wheel.BodyType = BodyType.Dynamic;
                _wheel.Position = pivot + _offset;

                Fixture fixture = _wheel.CreateFixture(shape);
                fixture.CollisionGroup = -1;
            }

            {
                _motorJoint = new RevoluteJoint(_wheel, _chassis, _chassis.Position, true);
                _motorJoint.CollideConnected = false;
                _motorJoint.MotorSpeed = _motorSpeed;
                _motorJoint.MaxMotorTorque = 400.0f;
                _motorJoint.MotorEnabled = _motorOn;
                World.AddJoint(_motorJoint);
            }

            Vector2 wheelAnchor = pivot + new Vector2(0.0f, -0.8f);

            CreateLeg(-1.0f, wheelAnchor);
            CreateLeg(1.0f, wheelAnchor);

            _wheel.SetTransform(_wheel.Position, 120.0f * Settings.Pi / 180.0f);
            CreateLeg(-1.0f, wheelAnchor);
            CreateLeg(1.0f, wheelAnchor);

            _wheel.SetTransform(_wheel.Position, -120.0f * Settings.Pi / 180.0f);
            CreateLeg(-1.0f, wheelAnchor);
            CreateLeg(1.0f, wheelAnchor);
        }
开发者ID:tinco,项目名称:Farseer-Physics,代码行数:72,代码来源:TheoJansenTest.cs

示例3: TheoJansenWalker

        public TheoJansenWalker(World world, Vector2 position)
        {
            _position = position;
            _motorSpeed = 2.0f;
            _motorOn = true;

            _leftShoulders = new Body[3];
            _leftLegs = new Body[3];

            _rightShoulders = new Body[3];
            _rightLegs = new Body[3];

            Vector2 pivot = new Vector2(0f, -0.8f);

            // Chassis
            PolygonShape box = new PolygonShape(1f);
            box.Vertices = PolygonTools.CreateRectangle(2.5f, 1.0f);
            _body = new Sprite(ContentWrapper.TextureFromShape(box, _walkerColors[0], ContentWrapper.Black));

            _chassis = BodyFactory.CreateBody(world);
            _chassis.BodyType = BodyType.Dynamic;
            _chassis.Position = pivot + _position;

            Fixture bodyFixture = _chassis.CreateFixture(box);
            bodyFixture.CollisionGroup = -1;

            // Wheel
            CircleShape circle = new CircleShape(1.6f, 1f);
            _engine = new Sprite(ContentWrapper.TextureFromShape(circle, "Stripe", _walkerColors[1] * 0.6f, _walkerColors[2] * 0.8f, ContentWrapper.Black, 3f));

            _wheel = BodyFactory.CreateBody(world);
            _wheel.BodyType = BodyType.Dynamic;
            _wheel.Position = pivot + _position;

            Fixture wheelFixture = _wheel.CreateFixture(circle);
            wheelFixture.CollisionGroup = -1;

            // Physics
            _motorJoint = new RevoluteJoint(_wheel, _chassis, _chassis.Position, true);
            _motorJoint.CollideConnected = false;
            _motorJoint.MotorSpeed = _motorSpeed;
            _motorJoint.MaxMotorTorque = 400f;
            _motorJoint.MotorEnabled = _motorOn;
            world.AddJoint(_motorJoint);

            Vector2 wheelAnchor = pivot + new Vector2(0f, 0.8f);

            CreateLeg(world, -1f, wheelAnchor, 0);
            CreateLeg(world, 1f, wheelAnchor, 0);

            _wheel.SetTransform(_wheel.Position, 120f * Settings.Pi / 180f);
            CreateLeg(world, -1f, wheelAnchor, 1);
            CreateLeg(world, 1f, wheelAnchor, 1);

            _wheel.SetTransform(_wheel.Position, -120f * Settings.Pi / 180f);
            CreateLeg(world, -1f, wheelAnchor, 2);
            CreateLeg(world, 1f, wheelAnchor, 2);

            // GFX
            Vector2[] points = { 
                                new Vector2(-5.4f, 6.1f),
                                new Vector2(-7.2f, 1.2f),
                                new Vector2(-4.3f, 1.9f),
                                new Vector2(-2.9f, -0.7f),
                                new Vector2(0.6f, -2.9f)
                               };

            _leftShoulder = new Sprite(ContentWrapper.PolygonTexture(new[] { Vector2.Zero, points[3], points[4] }, Color.White * 0.6f, ContentWrapper.Black));
            _leftShoulder.Origin = ContentWrapper.CalculateOrigin(_leftShoulders[0]);

            _leftLeg = new Sprite(ContentWrapper.PolygonTexture(new[] { points[0], points[1], points[2] }, Color.White * 0.6f, ContentWrapper.Black));
            _leftLeg.Origin = ContentWrapper.CalculateOrigin(_leftLegs[0]);

            for (int i = 0; i < points.Length; i++)
            {
                points[i].X *= -1f;
            }

            _rightShoulder = new Sprite(ContentWrapper.PolygonTexture(new[] { Vector2.Zero, points[4], points[3] }, Color.White * 0.6f, ContentWrapper.Black));
            _rightShoulder.Origin = ContentWrapper.CalculateOrigin(_rightShoulders[0]);

            _rightLeg = new Sprite(ContentWrapper.PolygonTexture(new[] { points[0], points[2], points[1] }, Color.White * 0.6f, ContentWrapper.Black));
            _rightLeg.Origin = ContentWrapper.CalculateOrigin(_rightLegs[0]);
        }
开发者ID:RCGame,项目名称:FarseerPhysics,代码行数:84,代码来源:TheoJansenWalker.cs

示例4: Ragdoll

        public Ragdoll(World world, Vector2 position)
        {
            // Physics
            // Head
            _head = BodyFactory.CreateCircle(world, 0.75f, 10f);
            _head.BodyType = BodyType.Dynamic;
            _head.AngularDamping = LimbAngularDamping;
            _head.Mass = 2f;
            _head.Position = position;

            // Torso
            _upperBody = BodyFactory.CreateCapsule(world, 0.5f, 0.75f, LegDensity);
            _upperBody.BodyType = BodyType.Dynamic;
            _upperBody.Mass = 1f;
            _upperBody.SetTransform(position + new Vector2(0f, 1.75f), MathHelper.Pi / 2f);
            _middleBody = BodyFactory.CreateCapsule(world, 0.5f, 0.75f, LegDensity);
            _middleBody.BodyType = BodyType.Dynamic;
            _middleBody.Mass = 1f;
            _middleBody.SetTransform(position + new Vector2(0f, 3f), MathHelper.Pi / 2f);
            _lowerBody = BodyFactory.CreateCapsule(world, 0.5f, 0.75f, LegDensity);
            _lowerBody.BodyType = BodyType.Dynamic;
            _lowerBody.Mass = 1f;
            _lowerBody.SetTransform(position + new Vector2(0f, 4.25f), MathHelper.Pi / 2f);

            // Left Arm
            _lowerLeftArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity);
            _lowerLeftArm.BodyType = BodyType.Dynamic;
            _lowerLeftArm.AngularDamping = LimbAngularDamping;
            _lowerLeftArm.Mass = 2f;
            _lowerLeftArm.Rotation = 1.4f;
            _lowerLeftArm.Position = position + new Vector2(-4f, 2.2f);

            _upperLeftArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity);
            _upperLeftArm.BodyType = BodyType.Dynamic;
            _upperLeftArm.AngularDamping = LimbAngularDamping;
            _upperLeftArm.Mass = 2f;
            _upperLeftArm.Rotation = 1.4f;
            _upperLeftArm.Position = position + new Vector2(-2f, 1.8f);

            // Right Arm
            _lowerRightArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity);
            _lowerRightArm.BodyType = BodyType.Dynamic;
            _lowerRightArm.AngularDamping = LimbAngularDamping;
            _lowerRightArm.Mass = 2f;
            _lowerRightArm.Rotation = -1.4f;
            _lowerRightArm.Position = position + new Vector2(4f, 2.2f);

            _upperRightArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity);
            _upperRightArm.BodyType = BodyType.Dynamic;
            _upperRightArm.AngularDamping = LimbAngularDamping;
            _upperRightArm.Mass = 2f;
            _upperRightArm.Rotation = -1.4f;
            _upperRightArm.Position = position + new Vector2(2f, 1.8f);

            // Left Leg
            _lowerLeftLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity);
            _lowerLeftLeg.BodyType = BodyType.Dynamic;
            _lowerLeftLeg.AngularDamping = LimbAngularDamping;
            _lowerLeftLeg.Mass = 2f;
            _lowerLeftLeg.Position = position + new Vector2(-0.6f, 8f);

            _upperLeftLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity);
            _upperLeftLeg.BodyType = BodyType.Dynamic;
            _upperLeftLeg.AngularDamping = LimbAngularDamping;
            _upperLeftLeg.Mass = 2f;
            _upperLeftLeg.Position = position + new Vector2(-0.6f, 6f);

            // Right Leg
            _lowerRightLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity);
            _lowerRightLeg.BodyType = BodyType.Dynamic;
            _lowerRightLeg.AngularDamping = LimbAngularDamping;
            _lowerRightLeg.Mass = 2f;
            _lowerRightLeg.Position = position + new Vector2(0.6f, 8f);

            _upperRightLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity);
            _upperRightLeg.BodyType = BodyType.Dynamic;
            _upperRightLeg.AngularDamping = LimbAngularDamping;
            _upperRightLeg.Mass = 2f;
            _upperRightLeg.Position = position + new Vector2(0.6f, 6f);

            // head -> upper body
            DistanceJoint jointHeadBody = new DistanceJoint(_head, _upperBody, new Vector2(0f, 1f), new Vector2(-0.75f, 0f));
            jointHeadBody.CollideConnected = true;
            jointHeadBody.DampingRatio = DampingRatio;
            jointHeadBody.Frequency = Frequency;
            jointHeadBody.Length = 0.025f;
            world.AddJoint(jointHeadBody);

            // lowerLeftArm -> upperLeftArm
            DistanceJoint jointLeftArm = new DistanceJoint(_lowerLeftArm, _upperLeftArm, new Vector2(0f, -1f), new Vector2(0f, 1f));
            jointLeftArm.CollideConnected = true;
            jointLeftArm.DampingRatio = DampingRatio;
            jointLeftArm.Frequency = Frequency;
            jointLeftArm.Length = 0.02f;
            world.AddJoint(jointLeftArm);

            // upperLeftArm -> upper body
            DistanceJoint jointLeftArmBody = new DistanceJoint(_upperLeftArm, _upperBody, new Vector2(0f, -1f), new Vector2(-0.15f, 1f));
            jointLeftArmBody.DampingRatio = DampingRatio;
            jointLeftArmBody.Frequency = Frequency;
//.........这里部分代码省略.........
开发者ID:RCGame,项目名称:FarseerPhysics,代码行数:101,代码来源:Ragdoll.cs

示例5: SetPhysicalState

        protected void SetPhysicalState(object nState)
        {
            List<Body> mOldBodies = mBodies;
            if (mSpriteEffects == SpriteEffects.FlipHorizontally)
            {
                mBodies = mBodiesLeft;
            }
            else
            {
                mBodies = mBodiesRight;
            }

            //If mBody == null, the player is being loaded for the first time
            if (mBody == null)
            {
                mBody = mBodies[mStates.IndexOf(nState)];
                mBody.Enabled = true;
                //mBody.Awake = true;
                //mBody.IgnoreGravity = false;
                //mBody.CollidesWith = Category.All;
                //mBody.Positi = mStartPos;
                mBody.IgnoreGravity = false;
                mBody.CollisionCategories = Category.Cat1;
                mBody.CollidesWith = Category.All & ~Category.Cat2;
                mBody.CollisionGroup = -1;
            }
            else
            {
                //Set new body
                mBody = mBodies[mStates.IndexOf(nState)];

                //Disable old body
                mOldBodies[mStates.IndexOf(mState)].CollisionCategories = Category.Cat2;
                mOldBodies[mStates.IndexOf(mState)].CollidesWith = Category.None;
                mOldBodies[mStates.IndexOf(mState)].CollisionGroup = -2;

                //Enable new body
                mBody.IgnoreGravity = false;
                mBody.CollisionCategories = Category.Cat1;
                mBody.CollidesWith = Category.All & ~Category.Cat2;
                mBody.CollisionGroup = -1;

                //Copy properties to new body
                mBody.SetTransform(mOldBodies[mStates.IndexOf(mState)].Position, mOldBodies[mStates.IndexOf(mState)].Rotation);
                mBody.LinearVelocity = mOldBodies[mStates.IndexOf(mState)].LinearVelocity;
                mBody.AngularVelocity = mOldBodies[mStates.IndexOf(mState)].AngularVelocity;
            }
        }
开发者ID:WilHall,项目名称:hakyn-client,代码行数:48,代码来源:AdvancedPhysicalSprite.cs

示例6: ConstructGenericMan

        protected void ConstructGenericMan()
        {
            #region Torso

            //Torso
            Vector2 size = new Vector2(20f / PPM, 36f / PPM);
            torso = BodyFactory.CreateRectangle(world, size.X, size.Y, 10f);
            torso.UserData = new PhysicalData(size, this, medColor);
            torso.Position = position / PPM;
            torso.FixedRotation = true;
            torso.BodyType = BodyType.Dynamic;
            torso.Restitution = 0.2f;
            torso.Friction = 0.2f;
            torso.SleepingAllowed = false;
            torso.CollisionCategories = Category.Cat2;
            torso.CollidesWith = Category.Cat1 | Category.Cat3 | Category.Cat5;
            //FixtureFactory.AttachRectangle(20f / PPM, 20f / PPM, 5f, new Vector2(0f, -20f), torso);

            #endregion

            #region Head

            //Head
            size = new Vector2(26f / PPM, 26f / PPM);
            head = BodyFactory.CreateRectangle(world, size.X, size.Y, 10f);
            head.UserData = new PhysicalData(size, this, medColor);
            head.Position = (position + new Vector2(0f, -38f)) / PPM;
            head.BodyType = BodyType.Dynamic;
            head.Restitution = 0.2f;
            head.Friction = 0.2f;
            head.AngularDamping = 1.2f;
            head.SetTransform(head.Position, 0.1f);
            head.SleepingAllowed = false;
            head.CollisionCategories = Category.Cat2;
            head.CollidesWith = Category.Cat1 | Category.Cat3 | Category.Cat5;

            //Join head to body
            neck = JointFactory.CreateRevoluteJoint(world, torso, head, new Vector2(0f, 0f));

            #endregion

            #region Arms

            #region Right Arm
            //Right Arm
            size = new Vector2(15f / PPM, 25f / PPM);
            rArm = BodyFactory.CreateRectangle(world, size.X, size.Y, 10f);
            rArm.UserData = new PhysicalData(size, this, color);
            rArm.Position = (position + new Vector2(0f, -6f)) / PPM;
            rArm.BodyType = BodyType.Dynamic;
            rArm.Restitution = 0.2f;
            rArm.Friction = 0.2f;
            rArm.SleepingAllowed = false;
            rArm.CollisionCategories = Category.Cat2;
            rArm.CollidesWith = Category.Cat1 | Category.Cat3 | Category.Cat5;

            //Join right arm to body
            //JointFactory.CreateRevoluteJoint(world, torso, rArm, new Vector2(0f, -4f / PPM));
            rShoulder = new RevoluteJoint(torso, rArm, new Vector2(0f / PPM, -15f / PPM), new Vector2(0f / PPM, -10f / PPM));
            //rShoulder.LowerLimit = -(float)Math.PI / 1.5f;
            //rShoulder.UpperLimit = (float)Math.PI / 3f;
            //rShoulder.LimitEnabled = true;
            rShoulder.MotorEnabled = true;
            rShoulder.MaxMotorTorque = JOINT_MAX_TORQUE;
            rShoulder.MotorSpeed = 0;

            world.AddJoint(rShoulder);

            //Right Forearm
            size = new Vector2(18f / PPM, 30f / PPM);
            rForearm = BodyFactory.CreateRectangle(world, size.X, size.Y, 10f);
            rForearm.UserData = new PhysicalData(size, this, color);
            rForearm.Position = (position + new Vector2(0f, 4f)) / PPM;
            rForearm.BodyType = BodyType.Dynamic;
            rForearm.Restitution = 0.2f;
            rForearm.Friction = 0.2f;
            rForearm.AngularDamping = 0.8f;
            rForearm.SleepingAllowed = false;
            rForearm.CollisionCategories = Category.Cat2;
            rForearm.CollidesWith = Category.Cat1 | Category.Cat3 | Category.Cat5;

            //Join right forearm to right arm
            //JointFactory.CreateRevoluteJoint(world, rArm, rForearm, new Vector2(0f, 4f / PPM));
            rElbow = new RevoluteJoint(rArm, rForearm, new Vector2(0f / PPM, 15f / PPM), new Vector2(0f / PPM, -10f / PPM));
            //rElbow.LowerLimit = -(float)Math.PI / 1.5f;
            //rElbow.UpperLimit = (float)Math.PI / 3f;
            //rElbow.LimitEnabled = true;
            rElbow.MotorEnabled = true;
            rElbow.MaxMotorTorque = JOINT_MAX_TORQUE;
            rElbow.MotorSpeed = 0;

            world.AddJoint(rElbow);

            #endregion

            #region Left Arm
            //Left Arm
            size = new Vector2(15f / PPM, 25f / PPM);
            lArm = BodyFactory.CreateRectangle(world, size.X, size.Y, 10f);
            lArm.UserData = new PhysicalData(size, this, darkColor);
//.........这里部分代码省略.........
开发者ID:JadenAlekis,项目名称:RogueMechs,代码行数:101,代码来源:Player.cs

示例7: SetTransform

 public static void SetTransform(Body body, Transform2 transform)
 {
     body.SetTransform((Xna.Vector2)transform.Position, transform.Rotation);
 }
开发者ID:AyyTee,项目名称:Aventyr,代码行数:4,代码来源:BodyExt.cs


注:本文中的FarseerPhysics.Dynamics.Body.SetTransform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。