Matrix mult order in Direct3D

前端 未结 2 1261
予麋鹿
予麋鹿 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:40

    The problem is the order you are multiplying the matrices to get the composite transform matrix is reversed from what it should be. You are doing: wm = rotatem * translatem, which follows the order of operations you are doing for OpenGL, but for DirectX the matrix should have been wm = translatem * rotatem

    The fundamental difference between OpenGL and DirectX arises from the fact that OpenGL treats matrices in column major order, while DirectX treats matrics in row major order.

    To go from column major to row major you need to find the transpose ( swap the rows and the columns ) of the OpenGL matrix.

    So, if you write wm = rotatem * translatem in OpenGL, then you want the transpose of that for DirectX, which is:

    wmT = (rotatem*translatem)T = translatemT * rotatemT
    

    which explains why the order of the matrix multiply has to be reversed in DirectX.

提交回复
热议问题