MonoGame.Extended icon indicating copy to clipboard operation
MonoGame.Extended copied to clipboard

Incorrect value from Triangulator.DetermineWindingOrder

Open Videogamers0 opened this issue 1 year ago • 4 comments

I use the following method to generate vertices for a 5-point star shape:

        private static List<Vector2> Get5PointStarVertices(Rectangle Region)
        {
            float InnerRadius = Region.Width / 5.0f;
            float OuterRadius = Region.Width / 2.0f;

            float Ang36 = (float)(Math.PI / 5.0);   // 36° x PI/180
            float Ang72 = 2.0f * Ang36;     // 72° x PI/180
            float Sin36 = (float)Math.Sin(Ang36);
            float Sin72 = (float)Math.Sin(Ang72);
            float Cos36 = (float)Math.Cos(Ang36);
            float Cos72 = (float)Math.Cos(Ang72);

            Vector2 Center = new Vector2((Region.Left + Region.Right) / 2.0f, (Region.Top + Region.Bottom) / 2.0f);

            List<Vector2> Vertices = new(10);

            float YOffset = InnerRadius / 8;

            //  Top of the star: 12:00 hours
            Vertices.Add(new Vector2(Center.X, Center.Y - OuterRadius + YOffset));

            //  Right-side vertices
            Vertices.Add(new Vector2(Center.X + InnerRadius * Sin36, Center.Y - InnerRadius * Cos36 + YOffset));
            Vertices.Add(new Vector2(Region.Right, Center.Y - InnerRadius * Cos36 + YOffset));
            Vertices.Add(new Vector2(Center.X + InnerRadius * Sin72, Center.Y + InnerRadius * Cos72 + YOffset));
            Vertices.Add(new Vector2(Center.X + OuterRadius * Sin36 + InnerRadius / 2, Center.Y + OuterRadius * Cos36 + YOffset));

            //  Bottom-center of the star: 6:00 hours
            Vertices.Add(new Vector2(Center.X, Center.Y + InnerRadius + YOffset));

            //  Left-side vertices
            Vertices.Add(new Vector2(Center.X - OuterRadius * Sin36 - InnerRadius / 2, Center.Y + OuterRadius * Cos36 + YOffset));
            Vertices.Add(new Vector2(Center.X - InnerRadius * Sin72, Center.Y + InnerRadius * Cos72 + YOffset));
            Vertices.Add(new Vector2(Region.Left, Center.Y - InnerRadius * Cos36 + YOffset));
            Vertices.Add(new Vector2(Center.X - InnerRadius * Sin36, Center.Y - InnerRadius * Cos36 + YOffset));

            return Vertices;
        }

Then, using the following code:

List<Vector2> StarVertices = Get5PointStarVertices(new(0, 0, 256, 256)); WindingOrder Order1 = Triangulator.DetermineWindingOrder(StarVertices.ToArray()); WindingOrder Order2 = Triangulator.DetermineWindingOrder(StarVertices.Reverse<Vector2>().ToArray());

Both Order1 and Order2 result in WindingOrder.Clockwise. Shouldn't they be different values? This is causing me unexpected results when I use PrimitiveDrawing.DrawSolidPolygon

Videogamers0 avatar Oct 13 '22 01:10 Videogamers0