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

Thread: glLookAt problem

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    12

    Exclamation glLookAt problem

    Hi Everybody, I have a small problem.

    I am using gluLookAt in with keyboard char 'f' so when i press the 'f' key the camera zooms towards the object its meant to zoom until it can go no more, when it reaches the end the camera returns to its original position.

    My problem is I have previously done this code and it worked fine, I had it commented out for a while until I completed everything else and for some reason now its not working at all.


    Here is my relevant code:




    gluPerspective(45.0f, fAspect, 1.0, 600.0);




    GLfloat eyePosition = 500.0;//default position




    void normalKeys(unsigned char key, int x, int y)
    {
    if (key == 'f')
    {
    eyePosition = eyePosition - 100.0;
    glutPostRedisplay();
    }
    }




    void RenderScene(void)
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode (GL_MODELVIEW);
    glPushMatrix();

    glTranslatef(0.0f, 0.0f, -100.0f);
    gluLookAt(0.00,0.00,eyePosition,
    0.00,0.00,0.00,//centre
    0.00,1.00,0.00);//up

    glLoadIdentity();
    /* DRAWING CODE HERE */

    glFlush(); //execute drawing commands in buffer

    glutSwapBuffers();
    }
    Last edited by donmitz; 01-06-2013 at 12:08 PM.

  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,067
    Move glLoadIdentity at the position of glPushMatrix. glPushMatrix can be removed since it probably does nothing, as well as glFlush. gluLookAt shoud be the first command after glLoadIdentity, since it is a complete view transformation. glTranslate can be incorporated into gluLookAt. Please read third chapter of some of the previous releases of OpenGL Programming Guide.

Tags for this Thread

Posting Permissions

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