Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Use gluLookAt to navigate around the world

  1. #1
    Intern Contributor
    Join Date
    Mar 2008
    Posts
    91

    Use gluLookAt to navigate around the world

    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?
    Code :
    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
    Code :
    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

  2. #2
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: Use gluLookAt to navigate around the world

    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/og...l_fps_controls

  3. #3
    Intern Contributor
    Join Date
    Jul 2008
    Posts
    89

    Re: Use gluLookAt to navigate around the world

    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_boa...100#Post242100

  4. #4
    Intern Contributor
    Join Date
    Jan 2001
    Posts
    82

    Re: Use gluLookAt to navigate around the world

    Thanks for posting that, _NK47.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •