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

C# Dynamics.BreakableBody类代码示例

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

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



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

示例1: CreateBreakableBody

 public static BreakableBody CreateBreakableBody(World world, IEnumerable<Shape> shapes, Vector2 position = new Vector2(), float rotation = 0)
 {
     BreakableBody breakableBody = new BreakableBody(world, shapes, position, rotation);
     breakableBody.MainBody.Position = position;
     world.AddBreakableBody(breakableBody);
     return breakableBody;
 }
开发者ID:tinco,项目名称:Farseer-Physics,代码行数:7,代码来源:BodyFactory.cs


示例2: CreateColonyShip

        public void CreateColonyShip(float strength, Vector2 position)
        {
            uint[] data = new uint[_texture.Width * _texture.Height];
            _texture.GetData(data);
            List<Vertices> list = PolygonTools.CreatePolygon(data, _texture.Width, 1.55f, 1, false, false); //Play around with hullTolerance
            for (int i = 0; i < list.Count; i++)
            {
                Vertices polygon = list[i];
                Vector2 centroid = -polygon.GetCentroid();
                polygon.Translate(centroid);
                polygon = SimplifyTools.CollinearSimplify(polygon);
                polygon = SimplifyTools.ReduceByDistance(polygon, 4);
                List<Vertices> triangulation = Triangulate.ConvexPartition(polygon, TriangulationAlgorithm.Bayazit);

                // Scale to your screen view
                Vector2 vertScale = new Vector2(1 / _ratio);
                foreach (var vertices in triangulation)
                {
                    vertices.Scale(vertScale);
                }

                colonyShipBreakableBody = new BreakableBody(world, triangulation, 20, position: position, rotation: -MathHelper.PiOver2);
                colonyShipBreakableBody.Strength = strength;
                colonyShipBreakableBody.MainBody.CollisionCategories = Category.Cat1;
                colonyShipBreakableBody.MainBody.CollidesWith = Category.All;
                world.AddBreakableBody(colonyShipBreakableBody);

                _colonyShipSprite = new Sprite(_texture) { Position = colonyShipBreakableBody.MainBody.Position * _ratio, Rotation = colonyShipBreakableBody.MainBody.Rotation };

                colonyShipBreakableBody.MainBody.OnSeparation += Reload_OnSeparation;

            }
        }
开发者ID:RiltonF,项目名称:MonogameAsteroids,代码行数:33,代码来源:ColonyShip.cs


示例3: CreateBreakableBody

        public static BreakableBody CreateBreakableBody(this World world, IEnumerable<Shape> shapes, Vector2 position)
        {
            BreakableBody breakableBody = new BreakableBody(shapes, world);
            breakableBody.MainBody.Position = position;
            world.AddBreakableBody(breakableBody);

            return breakableBody;
        }
开发者ID:hgrandry,项目名称:Mgx,代码行数:8,代码来源:BodyFactory.cs


示例4: CreateBreakableBody

        /// <summary>
        /// Creates a breakable body. You would want to remove collinear points before using this.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="vertices">The vertices.</param>
        /// <param name="density">The density.</param>
        /// <param name="position">The position.</param>
        /// <returns></returns>
        public static BreakableBody CreateBreakableBody(World world, Vertices vertices, float density, Vector2 position)
        {
            List<Vertices> triangles = EarclipDecomposer.ConvexPartition(vertices);

            BreakableBody breakableBody = new BreakableBody(triangles, world, density);
            breakableBody.MainBody.Position = position;
            world.AddBreakableBody(breakableBody);

            return breakableBody;
        }
开发者ID:HaKDMoDz,项目名称:Lunar-Development-Kit,代码行数:18,代码来源:FixtureFactory.cs


示例5: CreateBreakableBody

        /// <summary>
        /// Creates a breakable body. You would want to remove collinear points before using this.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="vertices">The vertices.</param>
        /// <param name="density">The density.</param>
        /// <param name="position">The position.</param>
        /// <returns></returns>
        public static BreakableBody CreateBreakableBody(World world, Vertices vertices, float density, Vector2 position,
            PressPlay.FFWD.Components.Collider userData)
        {
            List<Vertices> triangles = EarclipDecomposer.ConvexPartition(vertices);

            BreakableBody breakableBody = new BreakableBody(triangles, world, density, userData);
            breakableBody.MainBody.Position = position;
            world.AddBreakableBody(breakableBody);

            return breakableBody;
        }
开发者ID:Joelone,项目名称:FFWD,代码行数:19,代码来源:BodyFactory.cs


示例6: InvaderMother

        public InvaderMother(Game1 game, World world, float ratio, string texturePath, string textureMissilePath, string textureParticlePath, BreakableBody target)
            : base(game, world, texturePath)
        {
            _texture = Content.Load<Texture2D>(texturePath);

            _ratio = ratio;
            this.target = target;
            _missiles = new Missiles(game, world, ratio, textureMissilePath);
               // particles = new ParticleEngine(game, textureParticlePath);
            Practice = false;
            Alive = false;
        }
开发者ID:RiltonF,项目名称:MonogameAsteroids,代码行数:12,代码来源:InvaderMother.cs


示例7: SetPlayerKeys

        public void SetPlayerKeys(BreakableBody breakableBody, float speed, bool negativeForce = false)
        {
            var playerMovement = _inputManager.AddListener(new KeyboardListenerSettings());
            var cosAngle = (float)Math.Cos(breakableBody.MainBody.Rotation);
            var sinAngle = (float)Math.Sin(breakableBody.MainBody.Rotation);
            //var deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (!negativeForce) playerMovement.KeyPressed += (sender, arg) => { if (arg.Key == Keys.Down) breakableBody.MainBody.ApplyLinearImpulse(new Vector2(-speed * cosAngle, -speed * sinAngle)); };

            playerMovement.KeyPressed += (sender, arg) =>
            {
                if (arg.Key == Keys.Up) breakableBody.MainBody.ApplyLinearImpulse(new Vector2(speed * cosAngle, speed * sinAngle));
                if (arg.Key == Keys.Left) breakableBody.MainBody.ApplyTorque(10f);
                if (arg.Key == Keys.Right) breakableBody.MainBody.ApplyTorque(-10f);
            };
        }
开发者ID:RiltonF,项目名称:MonogameAsteroids,代码行数:16,代码来源:Listeners.cs


示例8: CreateMother

        public void CreateMother(float strength, Vector2 position, float angle = 0f)
        {
            Alive = true;
            uint[] data = new uint[_texture.Width * _texture.Height];
            _texture.GetData(data);
            List<Vertices> list = PolygonTools.CreatePolygon(data, _texture.Width, 1.55f, 1, true, true); //Play around with hullTolerance
            for (int i = 0; i < list.Count; i++)
            {
                //System.Diagnostics.Debug.WriteLine(list.Count + "  List Count");
                Vertices polygon = list[i];
                Vector2 centroid = -polygon.GetCentroid();
                polygon.Translate(centroid);
                polygon = SimplifyTools.CollinearSimplify(polygon);
                polygon = SimplifyTools.ReduceByDistance(polygon, 4);
                List<Vertices> triangulation = Triangulate.ConvexPartition(polygon, TriangulationAlgorithm.Bayazit);

                // Scale to your screen view
                Vector2 vertScale = new Vector2(1 / _ratio);
                foreach (var vertices in triangulation)
                {
                    vertices.Scale(vertScale);
                }

                MotherBreakableBody = new BreakableBody(world, triangulation, 10, position: position, rotation: angle);
                MotherBreakableBody.Strength = strength;
                //MotherBreakableBody.MainBody.Restitution = 0.00010f;
                MotherBreakableBody.MainBody.CollisionCategories = Category.Cat2 & ~Category.Cat5;
                MotherBreakableBody.MainBody.CollidesWith = Category.All & ~Category.Cat5;
                //MotherBreakableBody.MainBody.SleepingAllowed = false;
                //System.Diagnostics.Debug.WriteLine("mass of invader: " + MotherBreakableBody.MainBody.Mass);
                world.AddBreakableBody(MotherBreakableBody);

                motherTexture= new Sprite(_texture) { Position = MotherBreakableBody.MainBody.Position * _ratio, Rotation = MotherBreakableBody.MainBody.Rotation };

            }
        }
开发者ID:RiltonF,项目名称:MonogameAsteroids,代码行数:36,代码来源:InvaderMother.cs


示例9: LoadContent

        public override void LoadContent(AxiosGameScreen gameScreen)
        {
            base.LoadContent(gameScreen);

            Body = new BreakableBody();
        }
开发者ID:nadams810,项目名称:axiosengine,代码行数:6,代码来源:BreakableAxiosGameObject.cs


示例10: KeyboardHandlerPlayer

        private void KeyboardHandlerPlayer(KeyboardState keyboardState, GameTime gameTime, BreakableBody playerBreakableBody,float speed = 1f)
        {
            var cosAngle = (float)Math.Cos(playerBreakableBody.MainBody.Rotation);
            var sinAngle = (float)Math.Sin(playerBreakableBody.MainBody.Rotation);
            /*this doesn't work if camera controlls called before */
            if (keyboardState.IsKeyDown(Keys.Escape) & !_previousState.IsKeyDown(Keys.Escape))Exit();
            if (keyboardState.IsKeyDown(Keys.L) & !_previousState.IsKeyDown(Keys.L))
            {
                foreach (var item in _invaders.invaderBreakableBody)
                {
                    item.Break();
                }
            }
            if (keyboardState.IsKeyDown(Keys.N) & !_previousState.IsKeyDown(Keys.N)) negativeForce = !negativeForce;
            if (keyboardState.IsKeyDown(Keys.P) & !_previousState.IsKeyDown(Keys.P)) Pause = !Pause;
            if (!Pause)
            {
                if (keyboardState.IsKeyDown(Keys.Space) && !_previousState.IsKeyDown(Keys.Space))
                {
                    _player.FireMissile(speed);
                    System.Diagnostics.Debug.WriteLine("bullet");
                }

                if (keyboardState.IsKeyDown(Keys.Up))
                {
                    _player.Boosting = true;
                    playerBreakableBody.MainBody.ApplyLinearImpulse(new Vector2(speed * cosAngle, speed * sinAngle));
                }
                else
                {
                    if (!GamePad.GetState(PlayerIndex.One).IsConnected) _player.Boosting = false;
                }

                if (keyboardState.IsKeyDown(Keys.Right))
                    playerBreakableBody.MainBody.ApplyTorque(10f);

                if (keyboardState.IsKeyDown(Keys.Left))
                    playerBreakableBody.MainBody.ApplyTorque(-10f);

                if (keyboardState.IsKeyDown(Keys.Down))
                {
                    if (!negativeForce)//!false
                        playerBreakableBody.MainBody.ApplyLinearImpulse(new Vector2(-speed * cosAngle * 0.3f, -speed * sinAngle * 0.3f));
                    else
                    {
                        playerBreakableBody.MainBody.LinearVelocity = Vector2.Zero;
                        playerBreakableBody.MainBody.AngularVelocity *= .1f; //playwith this
                    }
                }
            }

            _previousState = keyboardState;
        }
开发者ID:RiltonF,项目名称:MonogameAsteroids,代码行数:53,代码来源:Level-2.cs


示例11: GamePadController

        public void GamePadController(GamePadState state, GameTime gameTime, BreakableBody playerBreakableBody, float speed = 1f)
        {
            var deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
            const float movementSpeed = 200;
            const float zoomSpeed = 0.5f;
            var cosAngle = (float)Math.Cos(playerBreakableBody.MainBody.Rotation);
            var sinAngle = (float)Math.Sin(playerBreakableBody.MainBody.Rotation);
            if (_camera.Position.Y - 800 < 1388 && state.DPad.Down == ButtonState.Pressed )
                _camera.Move(new Vector2(0, movementSpeed) * deltaTime);
            if (_camera.Position.Y > -668 && state.DPad.Up == ButtonState.Pressed )
                _camera.Move(new Vector2(0, -movementSpeed) * deltaTime);
            if (_camera.Position.X > -628 && state.DPad.Left == ButtonState.Pressed )
                _camera.Move(new Vector2(-movementSpeed, 0) * deltaTime);
            if (_camera.Position.X - 720 < 1428 && state.DPad.Right == ButtonState.Pressed )
                _camera.Move(new Vector2(movementSpeed, 0) * deltaTime);
            if (state.Buttons.Y == ButtonState.Pressed )
                _camera.ZoomIn(zoomSpeed * deltaTime);
            if (state.Buttons.X == ButtonState.Pressed)
                _camera.ZoomOut(zoomSpeed * deltaTime);
            if (state.Buttons.Back == ButtonState.Pressed && !(_previousStateGamepad.Buttons.Back == ButtonState.Pressed))
                Exit();
            if (state.Buttons.Start == ButtonState.Pressed && !(_previousStateGamepad.Buttons.Start == ButtonState.Pressed))
                Pause = !Pause;
            if (state.Buttons.LeftShoulder == ButtonState.Pressed && !(_previousStateGamepad.Buttons.LeftShoulder == ButtonState.Pressed))
                negativeForce = !negativeForce;

            if (!Pause)
            {
                if (state.Buttons.RightShoulder == ButtonState.Pressed && !(_previousStateGamepad.Buttons.RightShoulder == ButtonState.Pressed))
                    _player.FireMissile(speed);
                if (state.Buttons.A == ButtonState.Pressed)
                {
                    _player.Boosting = true;
                    playerBreakableBody.MainBody.ApplyLinearImpulse(new Vector2(speed * cosAngle, speed * sinAngle));
                }
                else _player.Boosting = false;

                if (state.Buttons.B == ButtonState.Pressed)
                {
                    if (!negativeForce)//!false
                        playerBreakableBody.MainBody.ApplyLinearImpulse(new Vector2(-speed * cosAngle * 0.3f, -speed * sinAngle * 0.3f));
                    else
                    {
                        playerBreakableBody.MainBody.LinearVelocity = Vector2.Zero;
                        playerBreakableBody.MainBody.AngularVelocity *= .1f; //playwith this
                    }
                }

                playerBreakableBody.MainBody.ApplyTorque(8f * state.ThumbSticks.Left.X);
            }

            _previousStateGamepad = state;
        }
开发者ID:RiltonF,项目名称:MonogameAsteroids,代码行数:53,代码来源:Level-2.cs


示例12: LoadContent

        public override void LoadContent()
        {
            base.LoadContent();

            DebugView.AppendFlags(DebugViewFlags.Shape);

            World.Gravity = Vector2.Zero;

            _border = new Border(World, ScreenManager, Camera);

            Texture2D alphabet = ScreenManager.Content.Load<Texture2D>("Samples/alphabet");

            uint[] data = new uint[alphabet.Width * alphabet.Height];
            alphabet.GetData(data);

            List<Vertices> list = PolygonTools.CreatePolygon(data, alphabet.Width, 3.5f, 20, true, true);

            float yOffset = -5f;
            float xOffset = -14f;
            for (int i = 0; i < list.Count; i++)
            {
                if (i == 9)
                {
                    yOffset = 0f;
                    xOffset = -14f;
                }
                if (i == 18)
                {
                    yOffset = 5f;
                    xOffset = -12.25f;
                }
                Vertices polygon = list[i];
                Vector2 centroid = -polygon.GetCentroid();
                polygon.Translate(ref centroid);
                polygon = SimplifyTools.CollinearSimplify(polygon);
                polygon = SimplifyTools.ReduceByDistance(polygon, 4);
                List<Vertices> triangulated = Triangulate.ConvexPartition(polygon, TriangulationAlgorithm.Bayazit);

#if WINDOWS_PHONE
                const float scale = 0.6f;
#else
                const float scale = 1f;
#endif
                Vector2 vertScale = new Vector2(ConvertUnits.ToSimUnits(1)) * scale;
                foreach (Vertices vertices in triangulated)
                {
                    vertices.Scale(ref vertScale);
                }

                BreakableBody breakableBody = new BreakableBody(World, triangulated, 1);
                breakableBody.MainBody.Position = new Vector2(xOffset, yOffset);
                breakableBody.Strength = 100;
                World.AddBreakableBody(breakableBody);

                xOffset += 3.5f;
            }
        }
开发者ID:RCGame,项目名称:FarseerPhysics,代码行数:57,代码来源:AdvancedDemo5.cs


示例13: BreakableTextureFragments

        public static List<Texture2D> BreakableTextureFragments(BreakableBody body, string textureName)
        {
            List<Texture2D> result = new List<Texture2D>();
            if (_contentWrapper != null)
            {
                Vector2 scale = ConvertUnits.ToDisplayUnits(Vector2.One);
                foreach (Fixture f in body.Parts)
                {
                    Vertices v = null;
                    if (f.Shape is PolygonShape)
                    {
                        v = new Vertices(((PolygonShape)f.Shape).Vertices);
                        v.Scale(ref scale);
                    }
                    if (v != null)
                    {
                        AABB polygonBounds = v.GetAABB();
                        List<Vertices> decomposedVertices;
                        if (!v.IsConvex())
                        {
                            decomposedVertices = Triangulate.ConvexPartition(v, TriangulationAlgorithm.Bayazit);
                        }
                        else
                        {
                            decomposedVertices = new List<Vertices>();
                            decomposedVertices.Add(v);
                        }
                        List<VertexPositionColorTexture[]> verticesFill = new List<VertexPositionColorTexture[]>(decomposedVertices.Count);
                        for (int i = 0; i < decomposedVertices.Count; i++)
                        {
                            verticesFill.Add(new VertexPositionColorTexture[3 * (decomposedVertices[i].Count - 2)]);
                            for (int j = 0; j < decomposedVertices[i].Count - 2; j++)
                            {
                                // fill vertices
                                verticesFill[i][3 * j].Position = new Vector3(decomposedVertices[i][0] - polygonBounds.Center, 0f);
                                verticesFill[i][3 * j + 1].Position = new Vector3(decomposedVertices[i].NextVertex(j) - polygonBounds.Center, 0f);
                                verticesFill[i][3 * j + 2].Position = new Vector3(decomposedVertices[i].NextVertex(j + 1) - polygonBounds.Center, 0f);

                                verticesFill[i][3 * j].TextureCoordinate = new Vector2(decomposedVertices[i][0].X / _textureList[textureName].Width, decomposedVertices[i][0].Y / _textureList[textureName].Height - 1f);
                                verticesFill[i][3 * j + 1].TextureCoordinate = new Vector2(decomposedVertices[i].NextVertex(j).X / _textureList[textureName].Width, decomposedVertices[i].NextVertex(j).Y / _textureList[textureName].Height - 1f);
                                verticesFill[i][3 * j + 2].TextureCoordinate = new Vector2(decomposedVertices[i].NextVertex(j + 1).X / _textureList[textureName].Width, decomposedVertices[i].NextVertex(j + 1).Y / _textureList[textureName].Height - 1f);
                                verticesFill[i][3 * j].Color = verticesFill[i][3 * j + 1].Color = verticesFill[i][3 * j + 2].Color = Color.Transparent;
                            }
                        }

                        Vector2 vertsSize = new Vector2(polygonBounds.UpperBound.X - polygonBounds.LowerBound.X, polygonBounds.UpperBound.Y - polygonBounds.LowerBound.Y);
                        result.Add(_contentWrapper.RenderTexture((int)vertsSize.X, (int)vertsSize.Y, _textureList.ContainsKey(textureName) ? _textureList[textureName] : null, Color.White, verticesFill, new VertexPositionColor[0]));
                    }
                    else
                    {
                        result.Add(_textureList["Blank"]);
                    }
                }
            }
            return result;
        }
开发者ID:RCGame,项目名称:FarseerPhysics,代码行数:56,代码来源:ContentWrapper.cs


示例14: LoadContent

        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = Vector2.Zero;

            _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport);
            _breakableObject = new List<List<Vertices>>();

            Texture2D alphabet = ScreenManager.Content.Load<Texture2D>("Samples/alphabet");

            uint[] data = new uint[alphabet.Width * alphabet.Height];
            alphabet.GetData(data);

            List<Vertices> list = PolygonTools.CreatePolygon(data, alphabet.Width, 3.5f, 20, true, true);

            float yOffset = -5f;
            float xOffset = -14f;
            for (int i = 0; i < list.Count; i++)
            {
                if (i == 9)
                {
                    yOffset = 0f;
                    xOffset = -14f;
                }
                if (i == 18)
                {
                    yOffset = 5f;
                    xOffset = -12.25f;
                }
                Vertices polygon = list[i];
                Vector2 centroid = -polygon.GetCentroid();
                polygon.Translate(ref centroid);
                //polygon = SimplifyTools.CollinearSimplify(polygon); // this breaks the split hole function
                polygon = SimplifyTools.ReduceByDistance(polygon, 4);
                List<Vertices> triangulated = BayazitDecomposer.ConvexPartition(polygon);

            #if WINDOWS_PHONE
                const float scale = 0.6f;
            #else
                const float scale = 1f;
            #endif
                Vector2 vertScale = new Vector2(ConvertUnits.ToSimUnits(1)) * scale;
                foreach (Vertices vertices in triangulated)
                {
                    vertices.Scale(ref vertScale);
                }

                BreakableBody breakableBody = new BreakableBody(triangulated, World, 1);
                breakableBody.MainBody.Position = new Vector2(xOffset, yOffset);
                breakableBody.Strength = 100;
                breakableBody.MainBody.UserData = i;
                World.AddBreakableBody(breakableBody);

                polygon.Scale(ref vertScale);
                _breakableObject.Add(polygon.SplitAtHoles());

                xOffset += 3.5f;
            }
        }
开发者ID:danzel,项目名称:FarseerPhysics,代码行数:60,代码来源:AdvancedDemo5.cs


示例15: AddBreakableBody

 public void AddBreakableBody(BreakableBody breakableBody)
 {
     BreakableBodyList.Add(breakableBody);
 }
开发者ID:dvgamer,项目名称:GhostLegend-XNA,代码行数:4,代码来源:World.cs


示例16: FireMissile

 public void FireMissile(BreakableBody body, float speed)
 {
     var cosAngle = (float)Math.Cos(body.MainBody.Rotation);
     var sinAngle = (float)Math.Sin(body.MainBody.Rotation);
     var distanceFromRotationX = (float)(body.MainBody.Position.X + 7.3 * Math.Cos(body.MainBody.Rotation));
     var distanceFromRotationY = (float)(body.MainBody.Position.Y + 7.3 * Math.Sin(body.MainBody.Rotation));
     _missiles.CreateBullet(new Vector2(distanceFromRotationX, distanceFromRotationY), body.MainBody.Rotation, new Vector2(speed * cosAngle * 30, speed * sinAngle * 30) + body.MainBody.LinearVelocity);
 }
开发者ID:RiltonF,项目名称:MonogameAsteroids,代码行数:8,代码来源:InvaderMother.cs


示例17: RemoveBreakableBody

        public void RemoveBreakableBody(BreakableBody breakableBody)
        {
            //The breakable body list does not contain the body you tried to remove.
            Debug.Assert(BreakableBodyList.Contains(breakableBody));

            BreakableBodyList.Remove(breakableBody);
        }
开发者ID:dvgamer,项目名称:GhostLegend-XNA,代码行数:7,代码来源:World.cs


示例18: CreatePlayerBreakableBody

        private void CreatePlayerBreakableBody(float strength, Vector2 position)
        {
            uint[] data = new uint[_textureReference.Width * _textureReference.Height];
            _textureReference.GetData(data);
            List<Vertices> list = PolygonTools.CreatePolygon(data, _textureReference.Width, 40f, 1, true, false); //Play around with hullTolerance 1.55
            for (int i = 0; i < list.Count; i++)
            {
                Vertices polygon = list[i];
                Vector2 centroid = -polygon.GetCentroid();
                polygon.Translate(centroid);
                polygon = SimplifyTools.CollinearSimplify(polygon);
                polygon = SimplifyTools.ReduceByDistance(polygon, 4);
                List<Vertices> triangulation = Triangulate.ConvexPartition(polygon, TriangulationAlgorithm.Earclip);

                // Scale to your screen view. A little smaller so texture overlaps the body, usually this would be 1f.
                Vector2 vertScale = new Vector2(.9f / _ratio);
                foreach (var vertices in triangulation)
                {
                    vertices.Scale(vertScale);
                }

                playerBreakableBody = new BreakableBody(world, triangulation, 1, position: position, rotation:-MathHelper.PiOver2);
                playerBreakableBody.Strength = strength;
                //playerBreakableBody.MainBody.Restitution = 0.00010f;
                playerBreakableBody.MainBody.CollisionCategories = Category.Cat1;
                playerBreakableBody.MainBody.CollidesWith = Category.All;

                world.AddBreakableBody(playerBreakableBody);
            }
        }
开发者ID:RiltonF,项目名称:MonogameAsteroids,代码行数:30,代码来源:Player.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Dynamics.Fixture类代码示例发布时间:2022-05-26
下一篇:
C# Dynamics.Body类代码示例发布时间: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