Why does my translation matrix needs to be transposed?

前端 未结 2 1534
闹比i
闹比i 2020-12-15 17:15

I\'m working on a small graphics engine using OpenGL and I\'m having some issues with my translation matrix. I\'m using OpenGL 3.3, GLSL and C++. The situation is this: I ha

相关标签:
2条回答
  • 2020-12-15 17:58

    For OpenGL

    1, 0, 0, 0
    0, 1, 0, 0
    0, 0, 1, 0
    x, y, z, 1
    

    Is the correct Translation Matrix. Why? Opengl Uses column-major matrix ordering. Which is the Transpose of the Matrix you initially presented, which is in row-major ordering. Row major is used in most math text-books and also DirectX, so it is a common point of confusion for those new to OpenGL.

    See: http://www.mindcontrol.org/~hplus/graphics/matrix-layout.html

    0 讨论(0)
  • 2020-12-15 18:19

    You cannot swap matrices in a matrix multiplication, so A*B is different from B*A. You have to transpose B before swapping the matrices.

    A * B = t(B) * A
    

    try

    void DisplayObject::updateMatrices()
    {
        modelMatrix = identityMatrix();
        modelMatrix = translateMatrix( xPos, yPos, zPos ) * modelMatrix;
    
        /* update modelview-projection matrix */
        mvpMatrix = modelMatrix * (*projMatrix);
    }
    
    0 讨论(0)
提交回复
热议问题