An easy to use factory for creating bodies
Esempio n. 1
0
        public static Body CreateSolidArc(World world, float density, float radians, int sides, float radius,
                                          Vector2 position  = new Vector2(), float rotation = 0,
                                          BodyType bodyType = BodyType.Static)
        {
            var body = CreateBody(world, position, rotation, bodyType);

            FixtureFactory.AttachSolidArc(density, radians, sides, radius, body);

            return(body);
        }
Esempio n. 2
0
        public static Body CreateCompoundPolygon(World world, List <Vertices> list, float density,
                                                 Vector2 position, object userData)
        {
            //We create a single body
            Body polygonBody = CreateBody(world, position);

            polygonBody.Geometry = BodyGeometryType.CompoundPolygon;
            FixtureFactory.AttachCompoundPolygon(list, density, polygonBody, userData);
            return(polygonBody);
        }
Esempio n. 3
0
        public static Body CreateCompoundPolygon(World world, List <Vertices> list, float density,
                                                 Vector2 position  = new Vector2(), float rotation    = 0,
                                                 BodyType bodyType = BodyType.Static, object userData = null)
        {
            //We create a single body
            var polygonBody = CreateBody(world, position, rotation, bodyType);

            FixtureFactory.AttachCompoundPolygon(list, density, polygonBody, userData);
            return(polygonBody);
        }
Esempio n. 4
0
        public static Body CreateCapsule(World world, float height, float endRadius, float density, Vector2 position = new Vector2(), float rotation = 0, BodyType bodyType = BodyType.Static, object userData = null)
        {
            //Create the middle rectangle
            var rectangle = PolygonTools.CreateRectangle(endRadius, height / 2);

            var list = new List <Vertices>();

            list.Add(rectangle);
            var body = CreateCompoundPolygon(world, list, density, position, rotation, bodyType, userData);

            //Create the two circles
            FixtureFactory.AttachCircle(endRadius, density, body, new Vector2(0, height / 2));
            FixtureFactory.AttachCircle(endRadius, density, body, new Vector2(0, -(height / 2)));

            return(body);
        }
Esempio n. 5
0
        public static Body CreateRectangle(World world, float width, float height, float density, Vector2 position = new Vector2(), float rotation = 0, BodyType bodyType = BodyType.Static, object userData = null)
        {
            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 body = CreateBody(world, position, rotation, bodyType, userData);

            Vertices rectangleVertices = PolygonTools.CreateRectangle(width / 2, height / 2);

            FixtureFactory.AttachPolygon(rectangleVertices, density, body);

            return(body);
        }