• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Dynamics.Body类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: TriggerEntity_cl

        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"></param>
        /// <param name="disable"></param>
        /// <param name="cooldown"></param>
        public TriggerEntity_cl(string type, bool disable = false, float cooldown = 0.0f)
            : base()
        {
            mDisableAfterTrigger = disable;
            mCooldownTime = cooldown;
            mCooldownTimer = 0.0f;

            AddComponent(new PositionComponent_cl(this));

            AddComponent(new RenderableComponent_cl(this, "whitePixel"));
            ((RenderableComponent_cl)GetComponentOfType(typeof(RenderableComponent_cl))).Sprite.Size = new Vector2(TRIGGER_DEFAULT_SIZE, TRIGGER_DEFAULT_SIZE);

            mPhysicsBody = BodyFactory.CreateBody(PhysicsManager_cl.Instance.PhysicsWorld);
            SetShape(PhysicsComponent_cl.PhysicsObjectType.RECTANGLE);

            /************************************************************************
             * TODO:
             * Allow multiple trigger types.
             * Ex: Sound and DamageHealth components on a single TriggerEntity
             *
             * Jay Sternfield	-	2011/12/05
             ************************************************************************/
            AddTriggerOfType(type);

            TriggerManager_cl.Instance.AddTrigger(this);

            mEnabled = true;
        }
开发者ID:dogmahtagram,项目名称:Finale,代码行数:34,代码来源:TriggerEntity.cs


示例17: Border

        public Border(World _world)
        {
            _anchorBottom = BodyFactory.CreateLineArc(_world, 2* MathHelper.Pi, 100, 100, position: new Vector2 (40f, 36f));
            _anchorTop = BodyFactory.CreateLineArc(_world, MathHelper.Pi, 100, 100, position: new Vector2(40f, 36f), rotation: MathHelper.Pi);

            _exitBottom = BodyFactory.CreateLineArc(_world, 2 * MathHelper.Pi, 100, 110, position: new Vector2(40f, 36f));
            _exitTop = BodyFactory.CreateLineArc(_world, MathHelper.Pi, 100, 110, position: new Vector2(40f, 36f), rotation: MathHelper.Pi);

            _exitTop.OnCollision += OnCollision;
            _exitBottom.OnCollision += OnCollision;

            _exitTop.CollisionCategories = Category.All;
            _exitTop.CollidesWith = Category.All;

            _exitBottom.CollisionCategories = Category.All;
            _exitBottom.CollidesWith = Category.All;

            _anchorTop.CollisionCategories = Category.Cat5;  //.All & ~Category.Cat3 & ~Category.Cat2;
            _anchorTop.CollidesWith = Category.Cat1;//Category.All & ~Category.Cat3 & ~Category.Cat2; //collides with enemy and player

            _anchorBottom.CollisionCategories = Category.All & ~Category.Cat3;
            _anchorBottom.CollidesWith = Category.Cat1;//Category.All & ~Category.Cat3 & ~Category.Cat2;  //collides with enemy and player

            //_anchorTop.IsSensor = true;
            //_anchorTop.ContactList
            //_anchorBottom.OnSeparation += OnSeparation;
            //System.Diagnostics.Debug.WriteLine( _anchorTop.ContactList+"contact list");
        }
开发者ID:RiltonF,项目名称:MonogameAsteroids,代码行数:28,代码来源:Border.cs


示例18: CreateRevoluteJoint

 /// <summary>
 /// Creates a revolute joint and adds it to the world
 /// </summary>
 /// <param name="world"></param>
 /// <param name="bodyA"></param>
 /// <param name="bodyB"></param>
 /// <param name="anchorB"></param>
 /// <returns></returns>
 public static RevoluteJoint CreateRevoluteJoint(World world, Body bodyA, Body bodyB, Vector2 anchorB)
 {
     Vector2 localanchorA = bodyA.GetLocalPoint(bodyB.GetWorldPoint(anchorB));
     RevoluteJoint joint = new RevoluteJoint(bodyA, bodyB, localanchorA, anchorB);
     world.AddJoint(joint);
     return joint;
 }
开发者ID:Alexz18z35z,项目名称:Gibbo2D,代码行数:15,代码来源:JointFactory.cs


示例19: AttachOnCollisionHandlers

 public static void AttachOnCollisionHandlers(Body body, EasyTopDownGame game)
 {
     foreach (Fixture fixture in body.FixtureList)
     {
         fixture.OnCollision += game.OnFixtureCollision;
     }
 }
开发者ID:pinh3ad,项目名称:EasyXNA,代码行数:7,代码来源:PhysicsHelper.cs


示例20: CreateFixedRevoluteJoint

 /// <summary>
 /// Creates the fixed revolute joint.
 /// </summary>
 /// <param name="world">The world.</param>
 /// <param name="body">The body.</param>
 /// <param name="bodyAnchor">The body anchor.</param>
 /// <param name="worldAnchor">The world anchor.</param>
 /// <returns></returns>
 public static FixedRevoluteJoint CreateFixedRevoluteJoint(World world, Body body, Vector2 bodyAnchor,
                                                           Vector2 worldAnchor)
 {
     FixedRevoluteJoint fixedRevoluteJoint = new FixedRevoluteJoint(body, bodyAnchor, worldAnchor);
     world.AddJoint(fixedRevoluteJoint);
     return fixedRevoluteJoint;
 }
开发者ID:HaKDMoDz,项目名称:Zazumo,代码行数:15,代码来源:JointFactory.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Dynamics.BreakableBody类代码示例发布时间:2022-05-26
下一篇:
C# Sweep.DTSweepContext类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap