Camera rotate

Recommended Posts

Hello! How to rotate camera in gluLookAt() ??

Share on other sites
gluLookAt() is used when you want to "look" at a certain point. You can do what you ask by rotating that point around the viewpos, but I don't see the point in using gluLookAt() in that situation. Consider using glTranslatef() and glRotatef() to setup your camera.

Share on other sites
oki but how? i have translatef and rotatef object and now i must add next translatef and rotatef to camera?

Share on other sites
Just substitute your gluLookAt() call with:

glRotatef(RotX,1,0,0);//Look left/rightglRotatef(RotY,0,1,0);//Look up/downglRotatef(RotZ,0,0,1);//Don't really know the word (roll?)glTranslatef(-campos.x,-campos.y,-campos.z);//Camera position

That's what I use in my first person shooter.
Hope that helps.

-EDIT: Fixed stupid mistake in code.

[Edited by - mikeman on November 11, 2004 2:06:24 PM]

Share on other sites
glTranslatef(-camera.x, -camera.y, -camera.z);
glRotatef(camera.rot.x,1,0,0);
glRotatef(camera.rot.y,0,1,0);
glRotatef(camera.rot.z,0,0,1);

glModelMatrix(GL_MODELVIEW);

glPopMatrix();
glTranslatef(object.x, object.y, object.z);
glRotatef(object.rot.x,1,0,0);
glRotatef(object.rot.y,0,1,0);
glRotatef(object.rot.z,0,0,1);

render_objekt()

glPushMatrix();;

this is correct?

Share on other sites
You just have to swap pop and push.

Share on other sites
First of all, I made a HUGE mistake in my second post, I'm sorry: you put the rotate calls BEFORE the translate.

Besides that, _DarkWIng_ is right and also, your camera applies to the modelview matrix as well, so why you put glMatrixMode() after camera setup? Put it before,of course followed by glLoadIdentity() and then the rest. So it's:

glModelMatrix(GL_MODELVIEW);glLoadIdentity();glRotatef(camera.rot.x,1,0,0);glRotatef(camera.rot.y,0,1,0);glRotatef(camera.rot.z,0,0,1);glTranslatef(-camera.x, -camera.y, -camera.z);glPushMatrix();glTranslatef(object.x, object.y, object.z);glRotatef(object.rot.x,1,0,0);glRotatef(object.rot.y,0,1,0);glRotatef(object.rot.z,0,0,1);render_objekt()glPopMatrix();

Share on other sites
Big THX for hellp :)

Greetz for all

Create an account

Register a new account

• Forum Statistics

• Total Topics
627762
• Total Posts
2978971

• 11
• 10
• 10
• 23
• 14