Archived

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

Neo the great Hacker

glTranslatef + glRotatef

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
Hi,

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

glRotatef()
glTranslatef()

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