Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

QMatrix4x4::lookAt() resulting in upside down camera



  • 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


Log in to reply