Example #1
0
        /// <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;
        }
Example #2
0
 public static Body CreateBody(World world, Vector2 position, PressPlay.FFWD.Components.Collider userData)
 {
     Body body = CreateBody(world, userData);
     body.Position = position;
     return body;
 }
Example #3
0
 public static Body CreateRectangle(World world, float width, float height, float density, PressPlay.FFWD.Components.Collider userData)
 {
     return CreateRectangle(world, width, height, density, Vector2.Zero, userData);
 }
Example #4
0
 public static Body CreatePolygon(World world, Vertices vertices, float density, Vector2 position,
     PressPlay.FFWD.Component userData)
 {
     Body body = CreateBody(world, position);
     FixtureFactory.AttachPolygon(vertices, density, body, userData);
     return body;
 }
Example #5
0
 public static Body CreateLoopShape(World world, Vertices vertices, Vector2 position,
     PressPlay.FFWD.Components.Collider userData)
 {
     Body body = CreateBody(world, position);
     FixtureFactory.AttachLoopShape(vertices, body, userData);
     return body;
 }
Example #6
0
 public static Body CreateCircle(World world, float radius, float density, PressPlay.FFWD.Components.Collider userData)
 {
     return CreateCircle(world, radius, density, Vector2.Zero, userData);
 }
Example #7
0
 public static Body CreateEllipse(World world, float xRadius, float yRadius, int edges, float density,
     PressPlay.FFWD.Component userData)
 {
     return CreateEllipse(world, xRadius, yRadius, edges, density, Vector2.Zero, userData);
 }
Example #8
0
 public static Body CreateRoundedRectangle(World world, float width, float height, float xRadius,
     float yRadius,
     int segments, float density, PressPlay.FFWD.Components.Collider userData)
 {
     return CreateRoundedRectangle(world, width, height, xRadius, yRadius, segments, density, Vector2.Zero,
                                   userData);
 }
Example #9
0
 public static Body CreateEdge(World world, Vector2 start, Vector2 end, PressPlay.FFWD.Components.Collider userData)
 {
     Body body = CreateBody(world);
     FixtureFactory.AttachEdge(start, end, body, userData);
     return body;
 }
Example #10
0
 public static Body CreateBody(World world, PressPlay.FFWD.Components.Collider userData)
 {
     Body body = new Body(world, userData);
     return body;
 }
Example #11
0
 public static Body CreateCompoundPolygon(World world, List<Vertices> list, float density,
     Vector2 position, PressPlay.FFWD.Components.Collider userData)
 {
     //We create a single body
     Body polygonBody = CreateBody(world, position);
     FixtureFactory.AttachCompoundPolygon(list, density, polygonBody, userData);
     return polygonBody;
 }
Example #12
0
 public static Body CreateCompoundPolygon(World world, List<Vertices> list, float density,
     PressPlay.FFWD.Components.Collider userData)
 {
     return CreateCompoundPolygon(world, list, density, Vector2.Zero, userData);
 }
Example #13
0
 public static Body CreateCircle(World world, float radius, float density, Vector2 position, PressPlay.FFWD.Components.Collider userData)
 {
     Body body = CreateBody(world, position);
     FixtureFactory.AttachCircle(radius, density, body, userData);
     return body;
 }
Example #14
0
        public static Body CreateRectangle(World world, float width, float height, float density, Vector2 position,
            PressPlay.FFWD.Component userData)
        {
            if (width <= 0)
                throw new ArgumentOutOfRangeException("width", "Width must be more than 0 meters");

            if (height <= 0)
                throw new ArgumentOutOfRangeException("height", "Height must be more than 0 meters");

            Body newBody = CreateBody(world, position);
            Vertices rectangleVertices = PolygonTools.CreateRectangle(width / 2, height / 2);
            PolygonShape rectangleShape = new PolygonShape(rectangleVertices, density);
            newBody.CreateFixture(rectangleShape, userData);

            return newBody;
        }
Example #15
0
 public static Body CreateEllipse(World world, float xRadius, float yRadius, int edges, float density,
     Vector2 position, PressPlay.FFWD.Component userData)
 {
     Body body = CreateBody(world, position);
     FixtureFactory.AttachEllipse(xRadius, yRadius, edges, density, body, userData);
     return body;
 }
Example #16
0
        /// <summary>
        /// Creates a rounded rectangle.
        /// Note: Automatically decomposes the capsule if it contains too many vertices (controlled by Settings.MaxPolygonVertices)
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="xRadius">The x radius.</param>
        /// <param name="yRadius">The y radius.</param>
        /// <param name="segments">The segments.</param>
        /// <param name="density">The density.</param>
        /// <param name="position">The position.</param>
        /// <returns></returns>
        public static Body CreateRoundedRectangle(World world, float width, float height, float xRadius,
            float yRadius,
            int segments, float density, Vector2 position,
            PressPlay.FFWD.Components.Collider userData)
        {
            Vertices verts = PolygonTools.CreateRoundedRectangle(width, height, xRadius, yRadius, segments);

            //There are too many vertices in the capsule. We decompose it.
            if (verts.Count >= Settings.MaxPolygonVertices)
            {
                List<Vertices> vertList = EarclipDecomposer.ConvexPartition(verts);
                Body body = CreateCompoundPolygon(world, vertList, density, userData);
                body.Position = position;
                return body;
            }

            return CreatePolygon(world, verts, density);
        }
Example #17
0
        public static Body CreateGear(World world, float radius, int numberOfTeeth, float tipPercentage,
            float toothHeight, float density, PressPlay.FFWD.Components.Collider userData)
        {
            Vertices gearPolygon = PolygonTools.CreateGear(radius, numberOfTeeth, tipPercentage, toothHeight);

            //Gears can in some cases be convex
            if (!gearPolygon.IsConvex())
            {
                //Decompose the gear:
                List<Vertices> list = EarclipDecomposer.ConvexPartition(gearPolygon);

                return CreateCompoundPolygon(world, list, density, userData);
            }

            return CreatePolygon(world, gearPolygon, density, userData);
        }
Example #18
0
 public static BreakableBody CreateBreakableBody(World world, Vertices vertices, float density, PressPlay.FFWD.Components.Collider userData)
 {
     return CreateBreakableBody(world, vertices, density, Vector2.Zero, userData);
 }
Example #19
0
 public static Body CreateLoopShape(World world, Vertices vertices, PressPlay.FFWD.Components.Collider userData)
 {
     return CreateLoopShape(world, vertices, Vector2.Zero, userData);
 }
Example #20
0
        /// <summary>
        /// Creates a capsule.
        /// Note: Automatically decomposes the capsule if it contains too many vertices (controlled by Settings.MaxPolygonVertices)
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="height">The height.</param>
        /// <param name="topRadius">The top radius.</param>
        /// <param name="topEdges">The top edges.</param>
        /// <param name="bottomRadius">The bottom radius.</param>
        /// <param name="bottomEdges">The bottom edges.</param>
        /// <param name="density">The density.</param>
        /// <param name="position">The position.</param>
        /// <returns></returns>
        public static Body CreateCapsule(World world, float height, float topRadius, int topEdges,
            float bottomRadius,
            int bottomEdges, float density, Vector2 position, PressPlay.FFWD.Components.Collider userData)
        {
            Vertices verts = PolygonTools.CreateCapsule(height, topRadius, topEdges, bottomRadius, bottomEdges);

            Body body;

            //There are too many vertices in the capsule. We decompose it.
            if (verts.Count >= Settings.MaxPolygonVertices)
            {
                List<Vertices> vertList = EarclipDecomposer.ConvexPartition(verts);
                body = CreateCompoundPolygon(world, vertList, density, userData);
                body.Position = position;

                return body;
            }

            body = CreatePolygon(world, verts, density, userData);
            body.Position = position;

            return body;
        }
Example #21
0
        public static Body CreateCapsule(World world, float height, float endRadius, float density,
            PressPlay.FFWD.Components.Collider userData)
        {
            //Create the middle rectangle
            Vertices rectangle = PolygonTools.CreateRectangle(endRadius, height / 2);

            List<Vertices> list = new List<Vertices>();
            list.Add(rectangle);

            Body body = CreateCompoundPolygon(world, list, density, userData);

            //Create the two circles
            CircleShape topCircle = new CircleShape(endRadius, density);
            topCircle.Position = new Vector2(0, height / 2);
            body.CreateFixture(topCircle, userData);

            CircleShape bottomCircle = new CircleShape(endRadius, density);
            bottomCircle.Position = new Vector2(0, -(height / 2));
            body.CreateFixture(bottomCircle, userData);
            return body;
        }