# glulookat() and rotation

This topic is 5470 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I am using glulookat() for my cameras in a modeller I am making. To pan i just change the x,y,z values of the eye and origin, to zoom in perpective i move the eyez and originz and in ortho i divide the ortho values by a zoom factor. All this is working fine but i cant figure out how to rotate. I am thinking maybe there is a better way to view the seen without glulookat(). Do most people use it or is it better to make your own camera. Is it even possible to rotate glulookat? Any help would be great Thanks :)

##### Share on other sites
What do you mean?
Rotate the camera about a fixed point?
Just change the eye coordinates...

eyeX = sin(angle)
eyeZ = cos(angle)

for example...

##### Share on other sites
Thanks dotproduct

I am trying to make the camera move on its own axis
eg
if i move the mouse left the camera will look left like your head moving left and right and up and down :P

That code u gave me gave me a wierd jerking movement

I'll keep on searchin

Thanks again :)

##### Share on other sites
I think this is a good approach(perspective viewing):

glMatrixMode(GL_PROJECTION);glLoadIdentity();//fov used to zoom in/outgluPerspective(cam.fov,ratio,nearz,farz);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glRotatef(cam.RotX,1,0,0);glRotatef(cam.RotY,0,1,0);glTranslatef(-cam.x,-cam.y,-cam.z);//and to render objects:glPushMatrix();//place any transformations...RenderObject();glPopMatrix();

##### Share on other sites
Thanks Mikeman :)

that was to easy, cheers :)

##### Share on other sites
Hi again, now i have got my camera rotating nicely, i want to be able to move forward. Forward being the direction the camera is facing. All my attemps so far have me traveling in the -z direction regardless of which way i am facing. Is there a way to translate the view matrix localy? is the the right wording? :)

Thanks again

##### Share on other sites
just a really small hint: your typical matrix looks like this:
local right in world coords
local up in world coords
local forward in world coords
position in world coords

to set it as view matrix you need to invert it, if you dont do anything fancy you just transpose the 3x3 "direction" part and -dot the position with each direction for the new position.

dont even start with storing rotation angles unless you just want a typical shooter camera anyway or you will soon find out that you cant just throw away the order in which rotations happened unless you spend a lot of pointless extra work and do everything in polar coords.

if you cant be bothered with doing your own matrix math ("repairing" them every now and then just feels kind of messy anyway) you can abuse opengl, load a matrix, rotate, read it back (just dont do it for thousands of objects per frame)

##### Share on other sites
It wasn't to hard to figure it out
Thanks again :)

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 13
• 14
• 45