Sign in to follow this  
bojkarPL

Camera rotate

Recommended Posts

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 this post


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


glRotatef(RotX,1,0,0);//Look left/right
glRotatef(RotY,0,1,0);//Look up/down
glRotatef(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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this