public Texture2D TextureFromWorldElement(PhysicsWorldElementEntity elementEntity) { Vertices vertices; switch (elementEntity.ElementType) { case ElementType.Circle: throw new NotImplementedException(); case ElementType.Elipsis: throw new NotImplementedException(); case ElementType.Polygon: PolygonElementEntity polygon = elementEntity as PolygonElementEntity; vertices = new Vertices(polygon.Vertices.Count); foreach (var vertex in polygon.Vertices) { vertices.Add(ConvertUnits.ToDisplayUnits(vertex)); } polygon.Origin = polygon.Vertices.GetCentroid(); break; case ElementType.Rectangle: RectangleElementEntity rectangle = elementEntity as RectangleElementEntity; vertices = new Vertices(4); vertices.Add(Vector2.Zero); vertices.Add(new Vector2(ConvertUnits.ToDisplayUnits(rectangle.Width), 0)); vertices.Add(new Vector2(ConvertUnits.ToDisplayUnits(rectangle.Width), ConvertUnits.ToDisplayUnits(rectangle.Height))); vertices.Add(new Vector2(0, ConvertUnits.ToDisplayUnits(rectangle.Height))); rectangle.Origin = new Vector2(ConvertUnits.ToDisplayUnits(rectangle.Width / 2f), ConvertUnits.ToDisplayUnits(rectangle.Height / 2f)); break; default: throw new NotSupportedException(String.Format("ElementType '{0}' is not supported", elementEntity.ElementType)); } return(TextureFromVertices(vertices, elementEntity.Material, elementEntity.FillColor, elementEntity.OutlineColor.A != 0, elementEntity.OutlineColor, elementEntity.MaterialScale)); }
void drawingCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (isCreatePolygon) { polygon.Points.Add(e.GetPosition(drawingCanvas)); string output = ""; PolygonElementEntity poly = new PolygonElementEntity(); poly.Vertices = new Vertices(polygon.Points.Count); foreach (var p in polygon.Points) { poly.Vertices.Add(new Vector2((float)p.X, (float)p.Y)); } XElement xElement = new XElement(PolygonElementTransformer.STR_PolygonElement); PolygonElementTransformer.Instance.ToXElement(poly, xElement); consoleOutput.Text = xElement.ToString(); } }