# [OGL] 2D Rotation

This topic is 4125 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have an orthogonal projection setup, and I'm trying to rotate a square. The square is drawn fine with:
glVertex3f( 0,            0,             0 );
glVertex3f( SQUARE_WIDTH, 0,             0 );
glVertex3f( SQUARE_WIDTH, SQUARE_HEIGHT, 0 );
glVertex3f( 0,            SQUARE_HEIGHT, 0 );


But, if I rotate it with glRotatef, it ends up being a line, rather than a square. Truth be told, I don't know what I'm doing, because I can't figure out what the last 3 parameters, x, y, and z, are referring to. All I can find is that they are a "vector" and that's pretty obvious. What exactly do the last 3 parameters refer to? And could you give me an example of proper parameters for rotating a 2D image? Like the square?

##### Share on other sites
The x y z components refer to the axis around whitch you want to rotate. In your case, the z axis (since your square is in the x-y plane). So to rotate phi radians around the z axis do:

glRotatef(phi, 0, 0, 1);

//Emil

##### Share on other sites
Wow, I can't believe I didn't try that.

I was thinking the opposite, that I would want to ignore the Z completely, but I guess it was the key all along.

Thanks!

• 34
• 12
• 10
• 9
• 9
×