Camera rotate

Started by
6 comments, last by bojkarPL 19 years, 5 months ago
Hello! How to rotate camera in gluLookAt() ??
Advertisement
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.
oki but how? i have translatef and rotatef object and now i must add next translatef and rotatef to camera?
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]
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?
You just have to swap pop and push.
You should never let your fears become the boundaries of your dreams.
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();
Big THX for hellp :)

Greetz for all


This topic is closed to new replies.

Advertisement