From 5b858d45ab5c3ff77dfd6d9697cc4518894e7d16 Mon Sep 17 00:00:00 2001 From: LACOMBE Dominique Date: Sun, 1 Oct 2023 16:46:43 -0400 Subject: [PATCH] Update PrimitiveDrawing.cs Add a new DrawSolidCircle to add a fill color --- .../VectorDraw/PrimitiveDrawing.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/cs/MonoGame.Extended/VectorDraw/PrimitiveDrawing.cs b/src/cs/MonoGame.Extended/VectorDraw/PrimitiveDrawing.cs index ab9e27a6e..fcf5791d2 100644 --- a/src/cs/MonoGame.Extended/VectorDraw/PrimitiveDrawing.cs +++ b/src/cs/MonoGame.Extended/VectorDraw/PrimitiveDrawing.cs @@ -122,6 +122,31 @@ public void DrawSolidCircle(Vector2 center, float radius, Color color) DrawCircle(center, radius, color); } + public void DrawSolidCircle(Vector2 center, float radius, Color color, Color fillcolor) + { + if (!_primitiveBatch.IsReady()) + throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); + + const double increment = Math.PI * 2.0 / CircleSegments; + double theta = 0.0; + + Vector2 v0 = center + radius * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta)); + theta += increment; + + for (int i = 1; i < CircleSegments - 1; i++) + { + Vector2 v1 = center + radius * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta)); + Vector2 v2 = center + radius * new Vector2((float)Math.Cos(theta + increment), (float)Math.Sin(theta + increment)); + + _primitiveBatch.AddVertex(v0, fillcolor, PrimitiveType.TriangleList); + _primitiveBatch.AddVertex(v1, fillcolor, PrimitiveType.TriangleList); + _primitiveBatch.AddVertex(v2, fillcolor, PrimitiveType.TriangleList); + + theta += increment; + } + + DrawCircle(center, radius, color); + } public void DrawSegment(Vector2 start, Vector2 end, Color color) {