/// <summary> /// Draws the specified shape by the specified color. /// </summary> /// <param name="verticesShape">The shape to draw.</param> /// <param name="color">The color of the shape.</param> /// <param name="z">The z coordinate of the shape.</param> public void Draw(ShapeBasedOnVertices verticesShape, Color color, float z) { if (verticesShape.Vertices.Count < 2) { return; } while (verticesShape.Vertices.Count > lineVertices.Length) { ExtendBuffer(); } if (lineVerticesCount >= 2) { DrawLines(); } for (int i = 0; i < verticesShape.Vertices.Count; ++i) { lineVertices[i].Position = new Vector3(verticesShape.Vertices[i], z); lineVertices[i].Color = color; } if (verticesShape.Type == Shape.ShapeType.Polygon) { lineVertices[verticesShape.Vertices.Count] = lineVertices[0]; } lineVerticesCount = verticesShape.Type == Shape.ShapeType.Polygon ? verticesShape.Vertices.Count : verticesShape.Vertices.Count - 1; ApplyBasicEffect(); GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineStrip, lineVertices, 0, lineVerticesCount); lineVerticesCount = 0; }
/// <summary> /// Updates the shape that represents the path. /// </summary> public void Invalidate() { if (Path.Loop) { pathShape = new Polygon(new FarseerPhysics.Common.Vertices(Path.Vertices)); } else { pathShape = new Edge(new FarseerPhysics.Common.Vertices(Path.Vertices)); } if (Path.Vertices.Count != 0) { Position = Path.Vertices[0]; } UpdateRectangle(); }