Example #1
0
        public static Body CreateCircle(World world, float radius, float density, Vector2 position = new Vector2(), BodyType bodyType = BodyType.Static, object userData = null)
        {
            Body body = CreateBody(world, position, 0, bodyType, userData);

            FixtureFactory.AttachCircle(radius, density, body);
            return(body);
        }
        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 = PolygonUtils.CreateRectangle(endRadius, height / 2);

            var list = new List <Vertices>();

            list.Add(rectangle);

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

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

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

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