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 3 of 3

Thread: moving in x direction using glLookAt()

  1. #1
    Guest

    moving in x direction using glLookAt()

    I just started using openGL. I'm having trouble with moving the view of the camera. I want to move the scene a little to the left when i click on the left side in my program. Is there something i have to do to refresh the view? here's what i have in the myMouse function:

    if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN && x < (win_width/2)){
    printf ("X is on the left side of the screen at %i\n", x);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(-2.0, 2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    }

    This should work i thought but it doesn't change the scene at all, x used to be 2.0 and i'm changing it to -2.0 when i click once, just something simple, thanks!

  2. #2

    Re: moving in x direction using glLookAt()

    I've never used gluLookAt in this way. But I do know that when I do the following it works fine...


    In RenderScene (after setting MatrixMode to ModelView) use
    gluLookAt(px,py,pz,vx,vy,vz,ux,uy,uz);
    where each variable is set to a value either here directly or earlier in the program as an initial setting say in initGL routine.

    In your KeyPress routine adjust the variable for the direction you want to change with something like the following:

    px++; which will increase px by 1

    The next time the renderscene is executed the camera/view will have altered to suit. You will only really notice this though if something is nearby to be affected by the movement.

    Tina
    Learning OpenGL while working on sourceforge projects:
    https://sourceforge.net/projects/simulant/ and
    https://sourceforge.net/projects/projectnova/

  3. #3
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    New Zealand
    Posts
    112

    Re: moving in x direction using glLookAt()

    you just need to call glutPostRedisplay(); at the end of your mouse function to reprint the screen again i have assumed you are using glut

    Originally posted by Chadyo:
    I just started using openGL. I'm having trouble with moving the view of the camera. I want to move the scene a little to the left when i click on the left side in my program. Is there something i have to do to refresh the view? here's what i have in the myMouse function:

    if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN && x < (win_width/2)){
    printf ("X is on the left side of the screen at %i\n", x);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(-2.0, 2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    }

    This should work i thought but it doesn't change the scene at all, x used to be 2.0 and i'm changing it to -2.0 when i click once, just something simple, thanks!

Posting Permissions

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