Пример #1
0
        public static void DrawCircle(this SpriteBatch spriteBatch, Vector2 position, float radius, Color color, float thickness = 1f, int resolution = 12)
        {
            var last  = Vector2.UnitX * radius;
            var lastP = Vector2Ext.Perpendicular(last);

            for (int i = 1; i <= resolution; i++)
            {
                var at  = Mathf.AngleToVector(i * MathHelper.PiOver2 / resolution, radius);
                var atP = Vector2Ext.Perpendicular(at);

                DrawLine(spriteBatch, position + last, position + at, color, thickness);
                DrawLine(spriteBatch, position - last, position - at, color, thickness);
                DrawLine(spriteBatch, position + lastP, position + atP, color, thickness);
                DrawLine(spriteBatch, position - lastP, position - atP, color, thickness);

                last  = at;
                lastP = atP;
            }
        }
Пример #2
0
        public static void DrawCircle(this Batcher batcher, Vector2 position, float radius, Color color, float thickness = 1f, int resolution = 12)
        {
            var last  = Vector2.UnitX * radius;
            var lastP = Vector2Ext.Perpendicular(last);

            batcher.SetIgnoreRoundingDestinations(true);
            for (int i = 1; i <= resolution; i++)
            {
                var at  = Mathf.AngleToVector(i * MathHelper.PiOver2 / resolution, radius);
                var atP = Vector2Ext.Perpendicular(at);

                DrawLine(batcher, position + last, position + at, color, thickness);
                DrawLine(batcher, position - last, position - at, color, thickness);
                DrawLine(batcher, position + lastP, position + atP, color, thickness);
                DrawLine(batcher, position - lastP, position - atP, color, thickness);

                last  = at;
                lastP = atP;
            }
            batcher.SetIgnoreRoundingDestinations(false);
        }