public Objects(World world, Vector2 startPosition, Vector2 endPosition, int count, float radius, ObjectType type) { _bodies = new List <Body>(count); CollidesWith = Category.All; CollisionCategories = Category.All; // Physics for (int i = 0; i < count; i++) { switch (type) { case ObjectType.Circle: _bodies.Add(BodyFactory.CreateCircle(world, radius, 1f)); break; case ObjectType.Rectangle: _bodies.Add(BodyFactory.CreateRectangle(world, radius, radius, 1f)); break; case ObjectType.Star: _bodies.Add(BodyFactory.CreateGear(world, radius, 10, 0f, 1f, 1f)); break; case ObjectType.Gear: _bodies.Add(BodyFactory.CreateGear(world, radius, 10, 100f, 1f, 1f)); break; } } for (int i = 0; i < _bodies.Count; i++) { Body body = _bodies[i]; body.BodyType = BodyType.Dynamic; body.Position = Vector2.Lerp(startPosition, endPosition, i / (float)(count - 1)); body.Restitution = 0.7f; body.Friction = 0.2f; } //GFX switch (type) { case ObjectType.Circle: _object = new Sprite(ContentWrapper.CircleTexture(radius, ContentWrapper.Gold, ContentWrapper.Grey)); break; case ObjectType.Rectangle: _object = new Sprite(ContentWrapper.PolygonTexture(PolygonUtils.CreateRectangle(radius / 2f, radius / 2f), ContentWrapper.Red, ContentWrapper.Grey)); break; case ObjectType.Star: _object = new Sprite(ContentWrapper.PolygonTexture(PolygonUtils.CreateGear(radius, 10, 0f, 1f), ContentWrapper.Brown, ContentWrapper.Black)); break; case ObjectType.Gear: _object = new Sprite(ContentWrapper.PolygonTexture(PolygonUtils.CreateGear(radius, 10, 100f, 1f), ContentWrapper.Orange, ContentWrapper.Grey)); break; } }
public override void Initialize() { Vector2 trans = new Vector2(); _polygons = new List <Vertices>(); _polygons.Add(PolygonUtils.CreateGear(5f, 10, 0f, 6f)); _polygons.Add(PolygonUtils.CreateGear(4f, 15, 100f, 3f)); trans.X = 0f; trans.Y = 8f; _polygons[0].Translate(ref trans); _polygons[1].Translate(ref trans); _polygons.Add(PolygonUtils.CreateGear(5f, 10, 50f, 5f)); trans.X = 22f; trans.Y = 17f; _polygons[2].Translate(ref trans); AddRectangle(5, 10); AddCircle(5, 32); trans.X = -20f; trans.Y = 8f; _polygons[3].Translate(ref trans); trans.Y = 20f; _polygons[4].Translate(ref trans); _polygons.Add(PolygonUtils.CreateRectangle(5f, 5f)); _polygons.Add(PolygonUtils.CreateRectangle(5f, 5f)); trans.X = 0f; trans.Y = 27f; _polygons[5].Translate(ref trans); _polygons[6].Translate(ref trans); _polygons.Add(PolygonUtils.CreateRectangle(5f, 5f)); _polygons.Add(PolygonUtils.CreateRectangle(5f, 5f)); trans.Y = 40f; _polygons[7].Translate(ref trans); trans.X = 5f; _polygons[8].Translate(ref trans); _polygons.Add(PolygonUtils.CreateRectangle(5f, 5f)); _polygons.Add(PolygonUtils.CreateRectangle(5f, 5f)); trans.Y = 35f; trans.X = 20f; _polygons[9].Translate(ref trans); trans.Y = 45f; trans.X = 25f; _polygons[10].Translate(ref trans); _subject = _polygons[5]; _clip = _polygons[6]; base.Initialize(); }
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) { Vertices gearPolygon = PolygonUtils.CreateGear(radius, numberOfTeeth, tipPercentage, toothHeight); //Gears can in some cases be convex if (!gearPolygon.IsConvex()) { //Decompose the gear: List <Vertices> list = Triangulate.ConvexPartition(gearPolygon, TriangulationAlgorithm.Earclip); return(CreateCompoundPolygon(world, list, density, position, rotation, bodyType, userData)); } return(CreatePolygon(world, gearPolygon, density, position, rotation, bodyType, userData)); }