rotating circle?

Hello there…

This is my first post, I’m studying OpenGL and working in my first project. I draw a circle using the formula: glVertex2f(cos(angle)*radius , sin(angle)*radius). I’m controlling the segment of the circle by using starting and ending number of the (2 * pi). The problem is that when I try to rotate the circle using glRotatef(), It is rotated not around its center but around something else I couldn’t figure it out!

I hope the problem is cleared. Any idea?

Best wishes

Post your code if it isn’t too long.

It’s something like:

void newCircle(float x, float y, float radius)
for ( float i = 0.0; i < 2*3.14159; i += 0.05){
glVertex2f(x + cos(i)*radius, y + sin(i)*radius);
glRotatef(10, 0, 0,1);

now, this function is called in myDisplay(void) many times changeing x and y. Another thing, I change the starting and the ending of of i in the for loop to ensure that the rotating has occured.

what I got is the whole circle rotating not around itself. I want it to around it center.

I found a way to do it but not using glRotatef()!


The center of your circle must be at the origin when the rotation is applied. Looking at your snippet of code, I see two ways to do this -

   glTranslatef ( x,  y, 0);  // Moves rotated circle to desired location.
   glRotatef    (10, 0,0,1);
   glTranslatef (-x, -y, 0);  // Centers circle at origin.
   newCircle    (x, y, r);

OR (a cleaner solution) -

   glTranslatef (x, y, 0);    // Move circle to desired location.
   glRotatef    (10, 0,0,1);
   newCircle    (0, 0, r);    // Generate circle at origin.