PDA

View Full Version : Use gluLookAt to navigate around the world



David Doria
10-22-2008, 03:59 PM
I am trying to make a simple program that will zoom, pan, and rotate around a scene using the mouse. It seems natural to use gluLookAt to do this since I want to move the camera. I got zooming to work (using gluPerspective), but I dont know how to smoothly rotate or pan?


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective (50.0*ViewingFrustrum.zoom, ViewingFrustrum.aspect(), ViewingFrustrum.zNear, ViewingFrustrum.zFar);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 10, 10, 0, 0, 0, 0, 1, -1); // eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz


Then to zoom, I handle a middle mouse hold+move which does this


ViewingFrustrum.zoom += increment;


That is very easy because the zoom does not depend on the location. However, the pan and rotate are location dependent. Is there an easy way to modify this so that left mouse will rotate?

Thanks,

Dave

_NK47
10-23-2008, 03:11 AM
of course you can do it with gluLookAt. gluLookAt accepts 3 axes which makes up your transformation matrix. by your code those values are fixed so nothing gets changed. if you rotate something about the Y axis f.e. you get a left right rotation. so all you need is to compute right vectors and pass them to gluLookAt to update the matrix.

a sample on how to implement fps controls:
http://www.codesampler.com/oglsrc/oglsrc_5.htm#ogl_fps_controls

Z-Knight
10-23-2008, 09:54 AM
Also, I started a similar topic here...I have example JOGL code that you can run as well and you could get my code from one of the posts in the thread and basically convert it to OpenGL pretty easily.

http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=242100#Post242100

MarkS
10-23-2008, 04:56 PM
Thanks for posting that, _NK47.