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: Problem with Zoom In/Out and glOrtho : Model flipped

  1. #1
    Newbie Newbie
    Join Date
    Jul 2013
    Posts
    2

    Problem with Zoom In/Out and glOrtho : Model flipped

    Hi everyone!

    I am a beginner with OpenGL so any help would be really appreciated.

    I have the following problem:

    When I zoom in, the model moves towards the screen, but
    then it is flipped and then starts moving back to the z direction
    of the screen.

    I use the glOrtho(left, right, bottom, top, near, far) function,
    so I noticed that the flip happens when bottom and top change
    their sign (from positive to negative and vice versa).

    Some details about the code:

    I have setup the mouseMoveEvent (in Qt) where I calculate
    the Z translation according to the mouse Y movement.

    zTranslation -= mouseClickYPosition - mouseLastYPosition;

    then while drawing the objects I setup the glOrtho parameters:

    left = -2.1 + zTranslation;
    right = 2.1 - zTranslation;
    bottom = -2.1 + zTranslation;
    top = 2.1 - zTranslation;
    near = -3.1 - zTranslation;
    far = -3.1 ;

    glOrtho(left, right, bottom, top, near, far);


    So what is wrong here?

    In general it is better to use glTranslatef, glRotatef, glScalef or glOrtho?

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    495
    Quote Originally Posted by HephaestusGR View Post
    In general it is better to use glTranslatef, glRotatef, glScalef or glOrtho?
    Use glOrtho for the projection matrix, and the others for the model-view matrix. Also, avoid using negative scale factors with the model-view matrix, as that will turn the model inside-out (i.e. it will change whether faces are front-facing or back-facing for the purposes of culling and lighting).

Posting Permissions

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