Draw 2D empty and filled circle

Started by
12 comments, last by BlackJoker 8 years, 4 months ago
Yeah, obviously wrong. Very wrong. I gonna put the geo-shader code here for easier comparison.

    int n = 20;
    float r1 = 0.1;
    float r2 = 0.05;
    for(int i = 0; i <= n; i++)
    {
        float a = (float)i / n * 2 * 3.1415926;
        float x, y;
        sincos(a, x, y);
        v.Position = mul(center + r2 * float4(x,y,0,0), WVP);
        triStream.Append(v);
        v.Position = mul(center + r1 * float4(x,y,0,0), WVP); 
        triStream.Append(v);
    }
And some probing questions:
  • Why do you iterate to 363 degrees ?
  • Why do you add three vertices per iteration?
  • Why adding a "thickness" once to x and once to y?
Please explain your thinking here, because your result looks very hackish. It might also help to use a bigger step (60 or even 90 degrees) and render in wire-frame (or use a graphics debugger) to get a better look at your result.
Advertisement

Maybe because I am a little bit stupid)

1. I iterate to 363 because I thought that less will made circle unfinished, but obviously I was wrong.

2. I added three vertices per iteration because I didnt fully understand triangle strip yet and work with it like with triangle list

3. This is also because of point 2.

Now, I apply your algorithm (which was obviously very simple) and not it works as expected.

Thanks a lot for that!

1. Well, yes, sort of. One needs to duplicate the first two vertices (identical to the last two of the strip). Avoidable with index buffers, but for just two I wouldn't bother. But 360 (inclusive) not 363.

2. & 3. Yeah, I assumed you know the workings of these.

In the end you were unlucky with that code. It duplicates the center over and over again (for a tri-list, where a fan would have sufficed, or again an index buffer) and calculates the tex-coords in a second loop (unecessary, can be done in one go).

Always check what code does. C# gives you plenty of possibilities to debug and visualize (hint: I "abuse" System.Drawing to inspect such algorithms) and don't forget graphics debuggers.

Edit: Oh, and congrats biggrin.png

Yeah, I already understood my mistakes and will try to avoid them in future.

Thanks again for help.

This topic is closed to new replies.

Advertisement