Quantcast
Viewing all articles
Browse latest Browse all 6821

My circle is not entirely round

@johmarjac wrote:

Hi,

i want to draw a circle using vertices. I am almost done but I cant figure out why it is not finishing the circle properly.

`
public static void DrawCircle(this SpriteBatch batch, float radius, Color color, ref Matrix transformMatrix)
{
var vertices = new List();
for(int i = 0; i < 360; i++)
{
var heading = MathHelper.ToRadians(i);

            vertices.Add(new VertexPositionColor(new Vector3((float)Math.Cos(heading) * radius, (float)Math.Sin(heading) * radius, 0f), color));
        }

        var effect = new BasicEffect(batch.GraphicsDevice);

        effect.View = transformMatrix;
        effect.Projection = Matrix.CreateOrthographicOffCenter(0, batch.GraphicsDevice.Viewport.Width, batch.GraphicsDevice.Viewport.Height, 0, 0, -1);

        foreach(var pass in effect.CurrentTechnique.Passes)
        {
            pass.Apply();

            batch.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineStrip, vertices.ToArray(), 0, vertices.Count -1);
        }
    }

`

This is the result, as you can see on the right side there is a little bit missing.
image

Posts: 8

Participants: 4

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles