Jump to content
  • Advertisement
Sign in to follow this  
bojkarPL

Camera rotate

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

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.

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
Sign in to follow this  

  • 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!