Пример #1
0
        public static Body createGear(World world, float radius, int numberOfTeeth, float tipPercentage, float toothHeight, float density, Vector2 position = new Vector2(), float rotation = 0, BodyType bodyType = BodyType.Static, object userData = null)
        {
            var gearPolygon = PolygonTools.createGear(radius, numberOfTeeth, tipPercentage, toothHeight);

            //Gears can in some cases be convex
            if (!gearPolygon.isConvex())
            {
                //Decompose the gear:
                var list = Triangulate.convexPartition(gearPolygon, TriangulationAlgorithm.Earclip);
                return(createCompoundPolygon(world, list, density, position, rotation, bodyType, userData));
            }

            return(createPolygon(world, gearPolygon, density, position, rotation, bodyType, userData));
        }
Пример #2
0
        public static List <Fixture> attachGear(this Body body, float radius, int numberOfTeeth, float tipPercentage, float toothHeight, float density)
        {
            var gearPolygon = PolygonTools.createGear(FSConvert.displayToSim * radius, numberOfTeeth, tipPercentage, FSConvert.displayToSim * toothHeight);

            // Gears can in some cases be convex
            if (!gearPolygon.isConvex())
            {
                //Decompose the gear:
                var list = Triangulate.convexPartition(gearPolygon, TriangulationAlgorithm.Earclip);
                return(body.attachCompoundPolygon(list, density));
            }

            var fixtures = new List <Fixture>();

            fixtures.Add(body.attachPolygon(gearPolygon, density));
            return(fixtures);
        }