Matrix mult order in Direct3D

前端 未结 2 1256
予麋鹿
予麋鹿 2021-02-10 15:37

I\'ve received two conflicting answers in terms of multiplying matrices in Direct3D to achieve results. Tutorials do state to multiply from left to right and that\'s fine but it

2条回答
  •  时光说笑
    2021-02-10 16:15

    See this answer. In OpenGL, each subsequent operation is a pre-multiplication of all the operations before it, not a post-multiplication. You can see a matrix multiplication of a vector as a function evaluation.

    If what you want is to first rotate a vector and then translate your rotated vector, which you in OpenGL would have solved by first calling glRotatef and then calling glTranslatef, you could express that using function calls as

    myNewVector = translate(rotate(myOldVector))
    

    The rotate function does this

    rotate(anyVector) = rotationMatrix * anyVector
    

    and the translate function does this

    translate(anyOtherVector) = translationMatrix * anyOtherVector
    

    so your equivalent expression using matrix multiplications would look like

    myNewVector = translationMatrix * rotationMatrix * myOldVector
    

    That is, your combined transformation matrix would look be translationMatrix * rotationMatrix.

提交回复
热议问题