Exemplo n.º 1
0
 public static Body CreateEllipse(World world, FP xRadius, FP yRadius, int edges, FP density, object userData = null)
 {
     return(BodyFactory.CreateEllipse(world, xRadius, yRadius, edges, density, TSVector2.zero, userData));
 }
Exemplo n.º 2
0
 public static Body CreateRectangle(World world, FP width, FP height, FP density, object userData = null)
 {
     return(BodyFactory.CreateRectangle(world, width, height, density, TSVector2.zero, userData));
 }
Exemplo n.º 3
0
 public static Body CreateCircle(World world, FP radius, FP density, object userData = null)
 {
     return(BodyFactory.CreateCircle(world, radius, density, TSVector2.zero, userData));
 }
Exemplo n.º 4
0
 public static BreakableBody CreateBreakableBody(World world, IEnumerable <Shape> shapes)
 {
     return(BodyFactory.CreateBreakableBody(world, shapes, TSVector2.zero));
 }
Exemplo n.º 5
0
 public static Body CreateLoopShape(World world, Vertices vertices, object userData = null)
 {
     return(BodyFactory.CreateLoopShape(world, vertices, TSVector2.zero, userData));
 }
Exemplo n.º 6
0
 public static BreakableBody CreateBreakableBody(World world, Vertices vertices, FP density)
 {
     return(BodyFactory.CreateBreakableBody(world, vertices, density, TSVector2.zero));
 }
Exemplo n.º 7
0
 public static Body CreateRoundedRectangle(World world, FP width, FP height, FP xRadius, FP yRadius, int segments, FP density, object userData = null)
 {
     return(BodyFactory.CreateRoundedRectangle(world, width, height, xRadius, yRadius, segments, density, TSVector2.zero, userData));
 }
Exemplo n.º 8
0
 public static Body CreateCompoundPolygon(World world, List <Vertices> list, FP density, object userData = null)
 {
     return(BodyFactory.CreateCompoundPolygon(world, list, density, TSVector2.zero, userData));
 }
Exemplo n.º 9
0
 public static Body CreatePolygon(World world, Vertices vertices, FP density, object userData)
 {
     return(BodyFactory.CreatePolygon(world, vertices, density, TSVector2.zero, userData));
 }
Exemplo n.º 10
0
        /// <summary>
        /// This is a high-level function to cuts fixtures inside the given world, using the start and end points.
        /// Note: We don't support cutting when the start or end is inside a shape.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="start">The startpoint.</param>
        /// <param name="end">The endpoint.</param>
        /// <returns>True if the cut was performed.</returns>
        public static bool Cut(World world, TSVector2 start, TSVector2 end)
        {
            List <Fixture>   fixtures    = new List <Fixture>();
            List <TSVector2> entryPoints = new List <TSVector2>();
            List <TSVector2> exitPoints  = new List <TSVector2>();

            //We don't support cutting when the start or end is inside a shape.
            if (world.TestPoint(start) != null || world.TestPoint(end) != null)
            {
                return(false);
            }

            //Get the entry points
            world.RayCast((f, p, n, fr) =>
            {
                fixtures.Add(f);
                entryPoints.Add(p);
                return(1);
            }, start, end);

            //Reverse the ray to get the exitpoints
            world.RayCast((f, p, n, fr) =>
            {
                exitPoints.Add(p);
                return(1);
            }, end, start);

            //We only have a single point. We need at least 2
            if (entryPoints.Count + exitPoints.Count < 2)
            {
                return(false);
            }

            for (int i = 0; i < fixtures.Count; i++)
            {
                // can't cut circles or edges yet !
                if (fixtures[i].Shape.ShapeType != ShapeType.Polygon)
                {
                    continue;
                }

                if (fixtures[i].Body.BodyType != BodyType.Static)
                {
                    //Split the shape up into two shapes
                    Vertices first;
                    Vertices second;
                    SplitShape(fixtures[i], entryPoints[i], exitPoints[i], out first, out second);

                    //Delete the original shape and create two new. Retain the properties of the body.
                    if (first.CheckPolygon() == PolygonError.NoError)
                    {
                        Body firstFixture = BodyFactory.CreatePolygon(world, first, fixtures[i].Shape.Density, fixtures[i].Body.Position);
                        firstFixture.Rotation        = fixtures[i].Body.Rotation;
                        firstFixture.LinearVelocity  = fixtures[i].Body.LinearVelocity;
                        firstFixture.AngularVelocity = fixtures[i].Body.AngularVelocity;
                        firstFixture.BodyType        = BodyType.Dynamic;
                    }

                    if (second.CheckPolygon() == PolygonError.NoError)
                    {
                        Body secondFixture = BodyFactory.CreatePolygon(world, second, fixtures[i].Shape.Density, fixtures[i].Body.Position);
                        secondFixture.Rotation        = fixtures[i].Body.Rotation;
                        secondFixture.LinearVelocity  = fixtures[i].Body.LinearVelocity;
                        secondFixture.AngularVelocity = fixtures[i].Body.AngularVelocity;
                        secondFixture.BodyType        = BodyType.Dynamic;
                    }

                    world.RemoveBody(fixtures[i].Body);
                }
            }

            return(true);
        }