Jump to content
  • Advertisement
Sign in to follow this  
Uphoreum

[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.

If you intended to correct an error in the post then please contact us.

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!