Skip to content

Instantly share code, notes, and snippets.

@linusthe3rd
Created January 30, 2011 18:54
Show Gist options
  • Save linusthe3rd/803118 to your computer and use it in GitHub Desktop.
Save linusthe3rd/803118 to your computer and use it in GitHub Desktop.

Revisions

  1. linusthe3rd revised this gist Jan 30, 2011. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions circles.cpp
    Original file line number Diff line number Diff line change
    @@ -18,8 +18,8 @@ void drawFilledCircle(GLfloat x, GLfloat y, GLfloat radius){
    glVertex2f(x, y); // center of circle
    for(i = 0; i <= triangleAmount;i++) {
    glVertex2f(
    x + (radius * cos(i * twicePi / triangleAmount)),
    y + (radius * sin(i * twicePi / triangleAmount))
    x + (radius * cos(i * twicePi / triangleAmount)),
    y + (radius * sin(i * twicePi / triangleAmount))
    );
    }
    glEnd();
    @@ -44,8 +44,8 @@ void drawHollowCircle(GLfloat x, GLfloat y, GLfloat radius){
    glBegin(GL_LINE_LOOP);
    for(i = 0; i <= lineAmount;i++) {
    glVertex2f(
    x + (radius * cos(i * twicePi / lineAmount)),
    y + (radius* sin(i * twicePi / lineAmount))
    x + (radius * cos(i * twicePi / lineAmount)),
    y + (radius* sin(i * twicePi / lineAmount))
    );
    }
    glEnd();
  2. linusthe3rd created this gist Jan 30, 2011.
    52 changes: 52 additions & 0 deletions circles.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    /*
    * Function that handles the drawing of a circle using the triangle fan
    * method. This will create a filled circle.
    *
    * Params:
    * x (GLFloat) - the x position of the center point of the circle
    * y (GLFloat) - the y position of the center point of the circle
    * radius (GLFloat) - the radius that the painted circle will have
    */
    void drawFilledCircle(GLfloat x, GLfloat y, GLfloat radius){
    int i;
    int triangleAmount = 20; //# of triangles used to draw circle

    //GLfloat radius = 0.8f; //radius
    GLfloat twicePi = 2.0f * PI;

    glBegin(GL_TRIANGLE_FAN);
    glVertex2f(x, y); // center of circle
    for(i = 0; i <= triangleAmount;i++) {
    glVertex2f(
    x + (radius * cos(i * twicePi / triangleAmount)),
    y + (radius * sin(i * twicePi / triangleAmount))
    );
    }
    glEnd();
    }

    /*
    * Function that handles the drawing of a circle using the line loop
    * method. This will create a hollow circle.
    *
    * Params:
    * x (GLFloat) - the x position of the center point of the circle
    * y (GLFloat) - the y position of the center point of the circle
    * radius (GLFloat) - the radius that the painted circle will have
    */
    void drawHollowCircle(GLfloat x, GLfloat y, GLfloat radius){
    int i;
    int lineAmount = 100; //# of triangles used to draw circle

    //GLfloat radius = 0.8f; //radius
    GLfloat twicePi = 2.0f * PI;

    glBegin(GL_LINE_LOOP);
    for(i = 0; i <= lineAmount;i++) {
    glVertex2f(
    x + (radius * cos(i * twicePi / lineAmount)),
    y + (radius* sin(i * twicePi / lineAmount))
    );
    }
    glEnd();
    }