/// <summary> /// Draws a rectangle using top left and bottom right point with specified colors for each corner. /// </summary> public static void Draw(float x1, float y1, float x2, float y2, bool isOutline, Color c1, Color c2, Color c3, Color c4) { GraphicsMode mode; short[] indices; if (isOutline) { mode = GraphicsMode.LinePrimitives; indices = _rectangleIndices[1]; } else { mode = GraphicsMode.TrianglePrimitives; indices = _rectangleIndices[0]; } var vertices = new List <VertexPositionColorTexture> { new VertexPositionColorTexture(new Vector3(x1, y1, 0), c1, Vector2.Zero), new VertexPositionColorTexture(new Vector3(x2, y1, 0), c2, Vector2.Zero), new VertexPositionColorTexture(new Vector3(x2, y2, 0), c3, Vector2.Zero), new VertexPositionColorTexture(new Vector3(x1, y2, 0), c4, Vector2.Zero) }; GraphicsMgr.AddVertices(mode, null, vertices, indices); }
public void Draw() { GraphicsMgr.AddVertices( _graphicsMode, _texture, GetConvertedVertices(), GetIndices() ); }
/// <summary> /// Draws a line with specified colors. /// </summary> public static void Draw(float x1, float y1, float x2, float y2, Color c1, Color c2) { var vertices = new List <VertexPositionColorTexture> { new VertexPositionColorTexture(new Vector3(x1, y1, 0), c1, Vector2.Zero), new VertexPositionColorTexture(new Vector3(x2, y2, 0), c2, Vector2.Zero) }; GraphicsMgr.AddVertices(GraphicsMode.LinePrimitives, null, vertices, new short[] { 0, 1 }); }
/// <summary> /// Draws a line with specified width and colors. /// </summary> public static void Draw(float x1, float y1, float x2, float y2, float thickness, Color c1, Color c2) { var normal2 = new Vector2(y2 - y1, x1 - x2); normal2 = normal2.GetSafeNormalize(); // The result is a unit vector rotated by 90 degrees. normal2 *= thickness / 2; var normal = normal2.ToVector3(); var vertices = new List <VertexPositionColorTexture> { new VertexPositionColorTexture(new Vector3(x1, y1, 0) - normal, c1, Vector2.Zero), new VertexPositionColorTexture(new Vector3(x1, y1, 0) + normal, c1, Vector2.Zero), new VertexPositionColorTexture(new Vector3(x2, y2, 0) + normal, c2, Vector2.Zero), new VertexPositionColorTexture(new Vector3(x2, y2, 0) - normal, c2, Vector2.Zero) }; // Thick line is in fact just a rotated rectangle. GraphicsMgr.AddVertices(GraphicsMode.TrianglePrimitives, null, vertices, _thickLineIndices); }