Home > Software engineering >  OpenGL Draw Around a Circle At Angles
OpenGL Draw Around a Circle At Angles

Time:01-28

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. The image should be something like this:

enter image description here

This is what I tried but its 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));
    for (auto i : floatPairs) {
        glPushMatrix();
        glRotatef(45.0*ii, 0.0, 0.0, 0.0);
        glVertex2f(i.first, i.second);
        glPopMatrix( );
    }
}
glEnd();

CodePudding user response:

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();
  • Related