# Thread: rotating a quad (Newbie)

1. ## rotating a quad (Newbie)

just a quick question on how to rotate my quad exactly the way i want.

some code.....

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity (); // Reset The Modelview Matrix
glTranslatef (xpos, ypos, -18.0f); // Translate 6 Units Into The Screen
glRotatef (angle, 0.0, 0.0f, -1.0f); // Rotate On The Y-Axis By angle
glBegin (GL_QUADS); // Begin Drawing Triangles
glColor3f (1.f, 0.f, 0.f); glVertex3f( 0.0f, 1.0f, 1.0f);
glColor3f (0.f, 1.f, 0.f); glVertex3f( 1.0f, 1.0f, 1.0f);
glColor3f (0.f, 0.f, 1.f); glVertex3f( 1.0f, 0.0f, 1.0f);
glColor3f (1.f, 0.f, 1.f); glVertex3f( 0.0f, 0.0f, 1.0f);
glEnd (); // Done Drawing Triangles

Now what i want to be able to do is to rotate my quad from the centre of it. At the moment it is rotating from the 2nd vertex that i draw.

Could someone point me in the right direction please???

2. ## Re: rotating a quad (Newbie)

glTranslatef (xpos, ypos, -18.0f); // Translate 6 Units Into The Screen
glRotatef (angle, 0.0, 0.0f, -1.0f); // Rotate On The Y-Axis By angle
glBegin (GL_QUADS); // Begin Drawing Triangles
glColor3f (1.f, 0.f, 0.f); glVertex3f( 0.0f, 1.0f, 1.0f);
glColor3f (0.f, 1.f, 0.f); glVertex3f( 1.0f, 1.0f, 1.0f);
glColor3f (0.f, 0.f, 1.f); glVertex3f( 1.0f, 0.0f, 1.0f);
glColor3f (1.f, 0.f, 1.f); glVertex3f( 0.0f, 0.0f, 1.0f);
glEnd (); // Done Drawing Triangles

----------------
you have to translate to the middle of your quad and THEN rotate. the middel of the quad seems to be sth like 0.5/0.5/1.0

translate to this position, and then rotate

seb

3. ## Re: rotating a quad (Newbie)

thanks! after a little bit of experimentation i changed the vertex coordinates to 0.5 and -0.5 and it works perfect now! Thanks for your help!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•