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


C# Body.ApplyForce方法代码示例

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


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

示例1: CreateBullets

        private static void CreateBullets(Body ship)
        {
            Func<Vector2, Body> createBullet = pos =>
            {
                var body = new Body(world);
                body.BodyType = BodyType.Dynamic;
                body.IsBullet = true;

                var shape = new FarseerCircleShape(0.15f / 4, 1);
                body.CreateFixture(shape);

                body.Position = ship.Position + ship.GetWorldVector(pos);
                body.Rotation = ship.Rotation;
                body.ApplyForce(body.GetWorldVector(new Vector2(0.0f, -15f)));

                body.OnCollision += (a, b, contact) =>
                {
                    world.RemoveBody(body);
                    return false;
                };

                return body;
            };

            createBullet(new Vector2(-0.575f, -0.20f));
            createBullet(new Vector2(0.575f, -0.20f));
        }
开发者ID:Rohansi,项目名称:Programe,代码行数:27,代码来源:Program.cs

示例2: CenterGravity

        public static void CenterGravity(Body Body)
        {
            Vector2f Pos = Body.Position.ToVec();

            Quantity Radius = SI.px.Quant(Pos.Length()).Convert(SI.m) + SI.m.Quant(1000);
            Quantity F = Constants.G * (SI.kg.Quant(Body.Mass) * SI.kg.Quant(5.972e16)) / (Radius ^ 2);

            Vector2f Force = -Pos.Normalize() * (float)F.Amount;
            Body.ApplyForce(Force.ToVec());
        }
开发者ID:cartman300,项目名称:Tetraquark,代码行数:10,代码来源:Phys.cs

示例3: Load

        public void Load()
        {
            var palette = Palette.FromXmlFile(DataPack.Colors.PaleBlue);
            Add(new BgColorValue(palette.ColorSets[0].Colors[1]));
            _actorColor = palette.ColorSets[0].Colors[3];

            // scene
            var scene = Add(RubeScene.FromFile(DataPack.Physic.Potato));
            Add(new PropertyValue<Vector2>(new Vector2(0, 20),
                () => Physic.World.Gravity,
                v => Physic.World.Gravity = v));

            // ui
            _body = scene.GetBody("actor");
            Add(new BodyStateRecorder(_body, "actor"));
            //_body.Position = new Vector2(0, 10);
            var actor = Add(new GameUI { Name = "actor"} );

            var tracker = actor.Add(new BodyMouseTracker(_body, .4f));
            Add(new BodyStateRecorder(tracker, "tracker"));

            actor.AddRange(
                new KeyBinding(Keys.Space, () => _body.ApplyForce(new Vector2(0, 20))),
                new FlyController(_body, 10, 50),
                new MouseZoomController(),
                new TrackingBodyCameraController(tracker, UpdateTime.Sim),
                new CameraStateRecorder()
            );
            _body.UserData = this;

            // rendering
            Add(new DrawComponent(DrawBody));
            var staticBodies = scene.Bodies.Where(b => b.BodyType == BodyType.Static);
            var contours = staticBodies.GetContours();
            foreach (var contour in contours)
            {
                var strip = ShapeFactory.PolygonStrip(contour, .3f, .01f);
                _staticBodiesContours.AddRange(strip);
            }

            // debug
            Add(new UpdateComponent(Update, UpdateTime.Sim));
        }
开发者ID:hgrandry,项目名称:Mgx,代码行数:43,代码来源:PotatoTest.cs

示例4: MoveBodyOnPath

        //TODO: Comment better
        /// <summary>
        /// Moves the body on the path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="body">The body.</param>
        /// <param name="time">The time.</param>
        /// <param name="strength">The strength.</param>
        /// <param name="timeStep">The time step.</param>
        public static void MoveBodyOnPath(Path path, Body body, float time, float strength, float timeStep, bool if_type2 = true)
        {
            Vector2 destination = path.GetPosition(time);
            Vector2 positionDelta = body.Position - destination;
            if ( positionDelta.Length() != 0 )
                positionDelta.Normalize();  // Added for game
            Vector2 velocity = (positionDelta / timeStep) * strength;
            Vector2 vel = Math.Min(8,body.LinearVelocity.Length()+3) * -velocity * body.Mass;

            if (if_type2 && vel.Length() > 1)
            {
                float velocity_magnitude_X = Math.Abs(body.LinearVelocity.X);
                float velocity_magnitude_Y = Math.Abs(body.LinearVelocity.Y);

                float force_magnitude_X = Math.Abs(vel.X);
                float force_magnitude_Y = Math.Abs(vel.Y);

                bool horiz = force_magnitude_X > 2;
                bool vert = force_magnitude_Y > 2;

                bool high_vert_low_horiz = (velocity_magnitude_X < velocity_magnitude_Y - 10);
                bool high_horiz_low_vert = velocity_magnitude_X > velocity_magnitude_Y + 10;

                if ((horiz) && high_vert_low_horiz)
                {
                    vel.X *= 2f;
                    vel.Y /= 2f;
                    //body.LinearVelocity = new Vector2(body.LinearVelocity.X,body.LinearVelocity.Y/1.5f);
                }
                if (vert && high_horiz_low_vert)
                {
                    vel.Y *= 2f;
                    vel.X /= 2f;
                   // body.LinearVelocity = new Vector2(body.LinearVelocity.X/1.5f, body.LinearVelocity.Y);
                }
                if (Math.Sign(vel.Y) != Math.Sign(body.LinearVelocity.Y))
                {
                    vel.Y *= 3;
                }
                if (Math.Sign(vel.X) != Math.Sign(body.LinearVelocity.X))
                {
                    vel.X *= 3;
                }
                body.ApplyForce(vel);
            }
            else if(path.GetLength()>0.5f)
            {
                body.LinearVelocity = -velocity;
            }
        }
开发者ID:mumumumu,项目名称:SpeedUp,代码行数:59,代码来源:PathManager.cs

示例5: CreateBullets

        private void CreateBullets()
        {
            Func<Vector2, Body> createBullet = pos =>
            {
                var body = new Body(Game.World);
                body.BodyType = BodyType.Dynamic;
                body.IsBullet = true;
                body.UserData = new RadarData(RadarType.Bullet, new NetBullet(body));

                var shape = new CircleShape(0.15f / 4, 1);
                body.CreateFixture(shape);

                body.Position = Body.Position + Body.GetWorldVector(pos);
                body.Rotation = Body.Rotation;
                body.ApplyForce(body.GetWorldVector(new Vector2(0.0f, -10f)));

                body.OnCollision += (a, b, contact) =>
                {
                    Game.World.RemoveBody(body);
                    return false;
                };

                return body;
            };

            createBullet(new Vector2(-0.575f, -0.20f));
            createBullet(new Vector2(0.575f, -0.20f));
        }
开发者ID:Rohansi,项目名称:Programe,代码行数:28,代码来源:Ship.cs


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