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


C# Dynamics.Body类代码示例

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


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

示例1: CreateAngleJoint

        /// <summary>
        /// Creates an angle joint.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="bodyA">The first body.</param>
        /// <param name="bodyB">The second body.</param>
        /// <returns></returns>
        public static AngleJoint CreateAngleJoint(World world, Body bodyA, Body bodyB)
        {
            AngleJoint angleJoint = new AngleJoint(bodyA, bodyB);
            world.AddJoint(angleJoint);

            return angleJoint;
        }
开发者ID:kyallbarrows,项目名称:Cinch_4-3,代码行数:14,代码来源:JointFactory.cs

示例2: FarseerObject

 public FarseerObject(FarseerWorld world, Shape shape, BodyType BodyType = BodyType.Dynamic)
 {            
     body = new Body(world.World);
     body.BodyType = BodyType;
     body.CreateFixture(shape);
     body.Enabled = false;            
 }
开发者ID:brunoduartec,项目名称:port-ploobsengine,代码行数:7,代码来源:FarseerObject.cs

示例3: CalculateOrigin

        public static Vector2 CalculateOrigin(Body body)
        {
            Vector2 origin = Vector2.Zero;

            if (body != null)
            {
                Vector2 leftBound = new Vector2(float.MaxValue);
                Transform trans;
                body.GetTransform(out trans);

                for (int i = 0; i < body.FixtureList.Count; ++i)
                {
                    for (int j = 0; j < body.FixtureList[i].Shape.ChildCount; ++j)
                    {
                        AABB bounds;
                        body.FixtureList[i].Shape.ComputeAABB(out bounds, ref trans, j);
                        Vector2.Min(ref leftBound, ref bounds.LowerBound, out leftBound);
                    }
                }

                // calculate body offset from its center and add a 1 pixel border
                // because we generate the textures a little bigger than the actual body's fixtures
                origin = ConvertUnits.ToDisplayUnits(body.Position - leftBound) + new Vector2(1f);
            }

            return origin;
        }
开发者ID:00erik2,项目名称:Physicist,代码行数:27,代码来源:AssetCreator.cs

示例4: Player

        public Player(World world, float x, float y, Texture2D texture)
        {
            torso = BodyFactory.CreateRectangle(world, 60 * MainGame.PIXEL_TO_METER, 80 * MainGame.PIXEL_TO_METER, 1);
            torso.Position = new Vector2(x * MainGame.PIXEL_TO_METER, y * MainGame.PIXEL_TO_METER);
            torso.BodyType = BodyType.Dynamic;
            torso.UserData = this;
            legs = BodyFactory.CreateCircle(world, 31 * MainGame.PIXEL_TO_METER, 1);
            legs.Position = torso.Position + new Vector2(0, 40 * MainGame.PIXEL_TO_METER);
            legs.BodyType = BodyType.Dynamic;
            legs.Friction = 5.0f;
            legs.UserData = this;
            JointFactory.CreateFixedAngleJoint(world, torso);
            axis = JointFactory.CreateRevoluteJoint(world, torso, legs, Vector2.Zero);
            axis.CollideConnected = false;
            axis.MotorEnabled = true;
            axis.MotorSpeed = 0.0f;
            axis.MotorTorque = 3.0f;
            axis.MaxMotorTorque = 10.0f;
            onGround = false;
            facingLeft = false;
            jumpForce = new Vector2(0, -1f);
            rightAirForce = new Vector2(5f, 0);
            leftAirForce = -1 * rightAirForce;
            prevVelocity = Vector2.Zero;
            normal = Vector2.Zero;
            pressW = false;
            holdW = false;

            texIdle = new AnimatedTexture(texture, 24, 0, 0, 120, 140);
            texRun = new AnimatedTexture(texture, 19, 0, 140, 120, 140);
            texJump = new AnimatedTexture(texture, 9, 19 * 120, 140, 120, 140, 1, false, false);
            currentTexture = texIdle;
        }
开发者ID:TadCordle,项目名称:MrGuyXNA,代码行数:33,代码来源:Player.cs

示例5: PinballMiniGame

        public PinballMiniGame(GraphicsDevice graphicsDevice)
        {
            this.graphicsDevice = graphicsDevice;

            sb = new SpriteBatch(graphicsDevice);

            ein = new Kinect(0, 0);
            ein.Init();

            circleTexture = CreateCircle(ball_radius, graphicsDevice);

            gameState = MiniGameState.Initialized;

            physicsWorld = new World(new Vector2(0, .982f));
            paddleSize = new Vector2(300, 16);
            paddleLeft = BodyFactory.CreateRectangle(physicsWorld, paddleSize.X * 2 * pixelToUnit, paddleSize.Y * pixelToUnit, 1000f);
            paddleLeft.BodyType = BodyType.Dynamic;
            paddleLeft.Position = new Vector2(8 * pixelToUnit, (GameConstants.MiniGameCanvasHeight - 100) * pixelToUnit);
            paddleLeft.LocalCenter = new Vector2(0, 0);
            paddleLeft.SleepingAllowed = false;
            paddleLeft.Restitution = 1.0f;
            paddleLeft.IgnoreGravity = true;

            ball = BodyFactory.CreateCircle(physicsWorld, (ball_radius) * pixelToUnit, 1000f);
            ball.BodyType = BodyType.Dynamic;
            ball.Position = new Vector2(100 * pixelToUnit, 100 * pixelToUnit);
            ball.Restitution = 1.0f;
            ball.SleepingAllowed = false;
        }
开发者ID:GriffinLedingham,项目名称:hacklandia,代码行数:29,代码来源:PinballMiniGame.cs

示例6: getDirection

        public override Vector2 getDirection(SpriteObjects.Ship mShip, Body otherShipsBody, float directionWeight)
        {
            float rearRayLength = mShip.getRayCastLengths.ElementAt(4); //length of raycast at the back of the ship
            float frontRayLength = mShip.getRayCastLengths.ElementAt(0); //length of raycast at the front of the ship
            Vector2 thrust = new Vector2(0, 99);

            //if (otherShipsBody == null || mShip.mSpriteBody == null)
            //{
            //    thrust = thrust;
            //}
            //else if (otherShipsBody.Position.Equals(mShip.mSpriteBody.Position))
            //{
            //    thrust = Vector2.Zero;
            //}

            if (rearRayLength < (-SpriteObjects.Ship.BASE_SHIP_RAYCAST_LENGTH))
            {
                thrust = new Vector2(0, -directionWeight);
            }
            //else
            //{
            //    thrust = Vector2.Zero;
            //}
            if ((frontRayLength < (-SpriteObjects.Ship.BASE_SHIP_RAYCAST_LENGTH)))
            {
                thrust = Vector2.Zero;
            }

            return thrust;
        }
开发者ID:thedamoes,项目名称:Gravitation,代码行数:30,代码来源:AvoidObsticles.cs

示例7: AddSolid

        public void AddSolid()
        {
            if (!Dead)
            {
                _floor = BodyFactory.CreateRectangle(_world, ConvertUnits.ToSimUnits(Globals.SmallGridSize.X),
                                                     ConvertUnits.ToSimUnits(Globals.SmallGridSize.Y), 30f);
                _floor.Position = ConvertUnits.ToSimUnits(_position.X + _centerVect.X, _position.Y + _centerVect.Y);
                _floor.IsStatic = true;
                _floor.Restitution = _stats.Restitution;
                _floor.Friction = _stats.Friction;
                //_bullet.LinearDamping = 0.2f;
                //_bullet.AngularDamping = 0.2f;
                _floor.Enabled = false;
                _floor.UserData = "caveblock";

                hull = ShadowHull.CreateRectangle(new Vector2(Globals.SmallGridSize.X, Globals.SmallGridSize.Y));
                hull.Position.X = _position.X + _centerVect.X;
                hull.Position.Y = _position.Y + _centerVect.Y;
                krypton.Hulls.Add(hull);
                hull.Visible = false;

                SSolid = true;
                GoingtobeSolid = false;
            }
        }
开发者ID:Wonko-the-sane,项目名称:Artefact001,代码行数:25,代码来源:CaveBlock.cs

示例8: CreateJoint

		protected override Joint CreateJoint(Body bodyA, Body bodyB)
		{
			if (bodyA == null) return null;
			FixedMouseJoint mj = new FixedMouseJoint(bodyA, Vector2.Zero);
			Scene.PhysicsWorld.AddJoint(mj);
			return mj;
		}
开发者ID:undue,项目名称:duality,代码行数:7,代码来源:FixedMouseJointInfo.cs

示例9: Agent

        public Agent(World world, Vector2 position)
        {
            _collidesWith = Category.All;
            _collisionCategories = Category.All;

            _agentBody = BodyFactory.CreateBody(world, position);
            _agentBody.BodyType = BodyType.Dynamic;

            //Center
            FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody);

            //Left arm
            FixtureFactory.AttachRectangle(1.5f, 0.4f, 1f, new Vector2(-1f, 0f), _agentBody);
            FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(-2f, 0f));

            //Right arm
            FixtureFactory.AttachRectangle(1.5f, 0.4f, 1f, new Vector2(1f, 0f), _agentBody);
            FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(2f, 0f));

            //Top arm
            FixtureFactory.AttachRectangle(0.4f, 1.5f, 1f, new Vector2(0f, 1f), _agentBody);
            FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(0f, 2f));

            //Bottom arm
            FixtureFactory.AttachRectangle(0.4f, 1.5f, 1f, new Vector2(0f, -1f), _agentBody);
            FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(0f, -2f));

            //GFX
            _box = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateRectangle(1.75f, 0.2f), Color.White, ContentWrapper.Black));
            _knob = new Sprite(ContentWrapper.CircleTexture(0.5f, "Square", ContentWrapper.Black, ContentWrapper.Gold, ContentWrapper.Black, 1f));

            _offset = ConvertUnits.ToDisplayUnits(2f);
        }
开发者ID:tinco,项目名称:Farseer-Physics,代码行数:33,代码来源:Agent.cs

示例10: CreateFixedPrismaticJoint

 public static FixedPrismaticJoint CreateFixedPrismaticJoint(World world, Body body, Vector2 worldAnchor,
                                                             Vector2 axis)
 {
     FixedPrismaticJoint joint = new FixedPrismaticJoint(body, worldAnchor, axis);
     world.AddJoint(joint);
     return joint;
 }
开发者ID:kyallbarrows,项目名称:Cinch_4-3,代码行数:7,代码来源:JointFactory.cs

示例11: DrawBody

        public void DrawBody(Body body, Color color)
        {
            // shift the current context into place to stamp down the little critter
            basicEffect.World = Matrix.Multiply(Matrix.CreateRotationZ(body.Rotation), Matrix.CreateTranslation(new Vector3(body.Position, 0.0f)));
            basicEffect.CurrentTechnique.Passes[0].Apply();

            // go through every fixture in this body (only one atm: the square!)
            foreach (Fixture fixture in body.FixtureList)
            {
                /*
                 * cast the shape into a special case of the Shape object -> PolygonShape. PolygonShape knows all about Vertices, which we need to draw. There
                 * are a whole host of other shape types that we could draw in different ways
                 */
                PolygonShape shape = (PolygonShape)fixture.Shape;

                // create a new vertex array to hold our drawing information (one bigger than the number of Vertices to loop back round and close the rectangle
                VertexPositionColor[] vertices = new VertexPositionColor[shape.Vertices.Count + 1];

                // loop through the vertices, saving each one into an array slot
                int i = 0;
                foreach (Vector2 vector in shape.Vertices)
                {
                    vertices[i].Position = new Vector3(vector, 0.0f);
                    vertices[i].Color = color;
                    ++i;
                }
                // put in the final vertex, closing off the rectangle
                vertices[i].Position = new Vector3(shape.Vertices[0], 0.0f);
                vertices[i].Color = color;

                // draw the rectangle to the screen
                graphics.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, vertices, 0, 4);
            }
        }
开发者ID:jengledew,项目名称:square-battle,代码行数:34,代码来源:Ship.cs

示例12: CreateFixedDistanceJoint

 public static FixedDistanceJoint CreateFixedDistanceJoint(World world, Body body, Vector2 localAnchor,
                                                           Vector2 worldAnchor)
 {
     FixedDistanceJoint distanceJoint = new FixedDistanceJoint(body, localAnchor, worldAnchor);
     world.AddJoint(distanceJoint);
     return distanceJoint;
 }
开发者ID:kyallbarrows,项目名称:Cinch_4-3,代码行数:7,代码来源:JointFactory.cs

示例13: CreateFixedAngleJoint

        /// <summary>
        /// Creates a fixed angle joint.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="body">The body.</param>
        /// <returns></returns>
        public static FixedAngleJoint CreateFixedAngleJoint(World world, Body body)
        {
            FixedAngleJoint angleJoint = new FixedAngleJoint(body);
            world.AddJoint(angleJoint);

            return angleJoint;
        }
开发者ID:kyallbarrows,项目名称:Cinch_4-3,代码行数:13,代码来源:JointFactory.cs

示例14: CreateDistanceJoint

 public static DistanceJoint CreateDistanceJoint(World world, Body bodyA, Body bodyB, Vector2 anchorA,
                                                 Vector2 anchorB)
 {
     DistanceJoint distanceJoint = new DistanceJoint(bodyA, bodyB, anchorA, anchorB);
     world.AddJoint(distanceJoint);
     return distanceJoint;
 }
开发者ID:kyallbarrows,项目名称:Cinch_4-3,代码行数:7,代码来源:JointFactory.cs

示例15: IsActiveOn

        /// <summary>
        /// 
        /// </summary>
        /// <param name="body"></param>
        /// <returns></returns>
        public virtual bool IsActiveOn(Body body)
        {
            if (body == null || !body.Enabled || body.IsStatic)
                return false;

            if (body.FixtureList == null)
                return false;

            foreach (Fixture fixture in body.FixtureList)
            {
                //Disable
                if ((fixture.CollisionGroup == DisabledOnGroup) && fixture.CollisionGroup != 0 && DisabledOnGroup != 0)
                    return false;

                if ((fixture.CollisionCategories & DisabledOnCategories) != Category.None)
                    return false;

                if (EnabledOnGroup != 0 || EnabledOnCategories != Category.All)
                {
                    //Enable
                    if ((fixture.CollisionGroup == EnabledOnGroup) && fixture.CollisionGroup != 0 && EnabledOnGroup != 0)
                        return true;

                    if ((fixture.CollisionCategories & EnabledOnCategories) != Category.None &&
                        EnabledOnCategories != Category.All)
                        return true;
                }
                else
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:Alexz18z35z,项目名称:Gibbo2D,代码行数:40,代码来源:FilterData.cs


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