# [OGL] 2D Rotation

## 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!

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628333
• Total Posts
2982125

• 23
• 9
• 9
• 13
• 11