Search code examples
c++opengltransformationopengl-compat

OpenGL Draw Around a Circle At Angles


I am trying to draw an image at 45 degree increments in the shape of a circle. I am getting the image from a txt file. I am trying to translate the matrix by 45 degrees but its not working.

This is what I tried but it's not working:

glBegin(GL_LINE_STRIP);
glColor3f(0, 0,0);
for(int ii=0; ii<8; ii++){
    float theta = 2*PI * float(ii)/8;
    glVertex2f(cx+r*cos(theta), cy+r*sin(theta));
}
glEnd();

Solution

  • You want to draw the shape 8 times in different places, right?

    So the program would look like this: (I will not show the exact code but enough to make you understand it)

    for(int ii=0; ii<8; ii++) {
        push the matrix;
        calculate the position/rotation based on ii and change the matrix;
        draw the shape;
        pop the matrix;
    }
    

    And how do you draw the shape? Well, I guess you already know how to draw the shape and you draw the shape like this: (I think you already wrote this code, so I can show it)

    glBegin(GL_LINE_STRIP);
    for (auto i : floatPairs) {
        glVertex2f(i.first, i.second);
    }
    glEnd();