Magpie

02-25-2003, 06:37 AM

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);

GLint min_x(0.25);

GLint min_y(0.25);

GLint max_x(0.50);

GLint max_y(0.50);

// Draw sub-polygon with no-rotation (upper-right quadrant)

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

// 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?

// Draw main polygon

glRectf (-0.75, -0.75, 0.75, 0.75);

GLint min_x(0.25);

GLint min_y(0.25);

GLint max_x(0.50);

GLint max_y(0.50);

// Draw sub-polygon with no-rotation (upper-right quadrant)

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

// 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?