PDA

View Full Version : rotating a quad (Newbie)

werdy666
06-30-2002, 10:33 PM
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???

SebastianB
06-30-2002, 11:29 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

seb

werdy666
07-01-2002, 12:02 AM
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!

http://www.opengl.org/discussion_boards/ubb/biggrin.gif