Sign in to follow this  
Uphoreum

[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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this