I am trying to rotate a polygon about it’s own center (0.375, 0.375) but it is rotating around (0,0). The following is a portion of some test code that I have been using in trying to figure this out:
// Draw main polygon
glRectf (-0.75, -0.75, 0.75, 0.75);
// Draw sub-polygon with 45.0 rotation (instead of rotating the polygon 45.0
// degrees on the polygon’s center (0.375, 0.375) the polygon is rotated on the
// x,y axis center (0,0) and winds up drawn on the y axis rotated 45.0 degrees)
glPushMatrix();
glRotatef (45.0, 0.0, 0.0, 1.0);
glBegin (GL_LINE_LOOP);
glVertex2f (min_x, max_y);
glVertex2f (max_x, max_y);
glVertex2f (max_x, min_y);
glVertex2f (min_x, min_y);
glEnd();
How is one to rotate the polygon about it’s own center?
Originally posted by Magpie:
[b]I am trying to rotate a polygon about it’s own center (0.375, 0.375) but it is rotating around (0,0). The following is a portion of some test code that I have been using in trying to figure this out:
// Draw main polygon
glRectf (-0.75, -0.75, 0.75, 0.75);
// Draw sub-polygon with 45.0 rotation (instead of rotating the polygon 45.0
// degrees on the polygon’s center (0.375, 0.375) the polygon is rotated on the
// x,y axis center (0,0) and winds up drawn on the y axis rotated 45.0 degrees)
glPushMatrix();
glRotatef (45.0, 0.0, 0.0, 1.0);
glBegin (GL_LINE_LOOP);
glVertex2f (min_x, max_y);
glVertex2f (max_x, max_y);
glVertex2f (max_x, min_y);
glVertex2f (min_x, min_y);
glEnd();
How is one to rotate the polygon about it’s own center?[/b]
what nexusone said, except that you probably also want to translate the object back to its center location after you rotate. so the code becomes
glPushMatrix();
glTranslatef(object_center); //translate object back to its center location
glRotatef(…);
glTranslatef(-object_center); //translate object center to origin
draw_polygon();
glPopMatrix();
[This message has been edited by SThomas (edited 02-25-2003).]