Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMatrix4x4::lookAt() resulting in upside down camera

QMatrix4x4::lookAt() resulting in upside down camera

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    modeldancecontroller
    wrote on last edited by
    #1

    I have a got a simple OpenGL program which sets up the camera as follows :
    @
    void
    SimRenderer::render() {
    glDepthMask(true);

    glClearColor(0.5f, 0.5f, 0.7f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    
    glFrontFace(GL_CW);
    glCullFace(GL_FRONT);
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    
    QMatrix4x4 mMatrix;
    QMatrix4x4 vMatrix;
    
    QMatrix4x4 cameraTransformation;
    cameraTransformation.rotate(mAlpha, 0, 1, 0); // mAlpha = 25
    cameraTransformation.rotate(mBeta, 1, 0, 0);  // mBeta = 25
    
    QVector3D cameraPosition = cameraTransformation * QVector3D(0, 0, mDistance);
    QVector3D cameraUpDirection = cameraTransformation * QVector3D(0, 1, 0);
    
    vMatrix.lookAt(cameraPosition, QVector3D(0, 0, 0), cameraUpDirection);
    
    mProgram.bind();
    mProgram.setUniformValue(mMatrixUniformLoc, mProjMatrix *  vMatrix * mMatrix );
    

    // render a grid....
    }
    @

    But the result is an upside down camera !!

    !http://s30.postimg.org/7kacwnljl/topsy.png(Topsy)!

    When I change the view matrix to be set up as:
    QVector3D cameraUpDirection = cameraTransformation * QVector3D(0, -1, 0);

    It works ! But why should I need to set my up direction as negative Y when my real up direction is positive Y ?

    Complete class here : https://code.google.com/p/rapid-concepts/source/browse/trunk/simviewer/simrenderer.cpp

    http://doc.qt.digia.com/qt-maemo/qmatrix4x4.html#lookAt

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved