Jump to content
  • Advertisement
Sign in to follow this  
one mind

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.

If you intended to correct an error in the post then please contact us.

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


Link to post
Share on other sites
Advertisement
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 this post


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



glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//fov used to zoom in/out
gluPerspective(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 this post


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


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


Link to post
Share on other sites
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 :)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!