[Solved]The results of perspective transform are different(QMatrix4x4 vs raw array)?



  • Studying opengl from this site
    "opengl":http://www.arcsynthesis.org/gltut/

    The result of raw array and QMatrix4x4 are different

    The codes of raw array
    @
    float const fFrustumScale = 1.0f; float const fzNear = 0.5f; float const fzFar = 3.0f;

    float theMatrix[16] = {0};
    theMatrix[0] = fFrustumScale;
    theMatrix[5] = fFrustumScale;
    theMatrix[10] = (fzFar + fzNear) / (fzNear - fzFar);
    theMatrix[14] = (2.0 * fzFar * fzNear) / (fzNear - fzFar);
    theMatrix[11] = -1.0f;
    
    int matPosition = program_.uniformLocation("perspectiveMatrix");
    glUniformMatrix4fv(matPosition, 1, GL_FALSE, theMatrix);
    

    @

    The codes of QMatrix4x4
    @
    QMatrix4x4 mat;
    float const fzNear = 1.0f; float const fzFar = 3.0f;
    mat(2, 2) = (fzFar + fzNear) / (fzNear - fzFar);
    mat(2, 3) = (2.0 * fzFar * fzNear) / (fzNear - fzFar);
    mat(3, 2) = -1.0;
    program_.setUniformValue("perspectiveMatrix", mat);
    @

    vertex shader of matrix transform
    @
    attribute vec4 position;
    attribute vec4 color;

    varying vec4 theColor;

    uniform vec2 offset;
    uniform mat4 perspectiveMatrix;

    void main()
    {
    vec4 cameraPos = position + vec4(offset.x, offset.y, 0.0, 0.0);

    gl_Position = perspectiveMatrix * cameraPos;
    theColor = color;
    }
    @

    result of QMatrix4x4
    "matrix":http://www.flickr.com/photos/92283971@N04/8734697996/in/photostream

    result of raw array
    "manual":http://www.flickr.com/photos/92283971@N04/8734698028/in/photostream



  • I found the problem, the last element of the QMatrix4x4 should be 0

    @
    mat(3, 3) = 0;
    @

    This line could fix the problem


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.