glulookat() and rotation

Started by
6 comments, last by one mind 19 years, 6 months ago
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 :)
Advertisement
What do you mean?
Rotate the camera about a fixed point?
Just change the eye coordinates...

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

for example...
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 :)
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();



Thanks Mikeman :)

that was to easy, cheers :)
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
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)
f@dzhttp://festini.device-zero.de
Thanks Trienco, I admit that i kenew nothing about matrices before this post but your reply made me do some quick research :)
It wasn't to hard to figure it out
Thanks again :)

This topic is closed to new replies.

Advertisement