Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Neo the great Hacker

glTranslatef + glRotatef

This topic is 6157 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

Hi, I''m very new to OpenGL but want to make the camera rotate by 1 unit (as if you slowly turn around to look what''s happining behind you), and go forward ("into" the screen by 2 units) this is my code, but somehow it just always goes forward 2 units while the camera actually is turning. What am I doing wrong??? rotation += 1; position += 2; glRotatef(-rotation, 0.0f, 1.0f, 0.0f); glTranslatef(0.0f, 0.0f, position); Thx for help

Share this post

Link to post
Share on other sites
Guest Anonymous Poster

Due to the fact that glTranslatef and glRotatef modify a matrix, the commands will be executed in reverse order. Now, if you write


the translation will be done first. Then, the camera will be rotated. Rotating the camera around something would be rotating first, then translating. So you just have to change the order of your operations.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!