在Direct3D矩阵MULT订单

人气:1,053 发布:2022-09-11 标签: 3d directx

问题描述

我收到了两个相互矛盾的答案在Direct3D矩阵相乘取得成果方面。教程做的状态,从左边乘到右,这很好,但它不是我怎么会想象了。

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's not how I would visualize it.

下面是一个例子:

的OpenGL(读取从上到下):

OpenGL (reading from top to bottom):

GLRotatef(90.0f);
GLTranslatef(20.0f,0,0);

所以,你想象世界轴旋转30度。然后你翻译20.0对现在旋转x轴,所以它看起来像你的世界y轴往上走。

So you visualize the world axis rotating 30 degrees. Then you translate 20.0 on the now rotated x-axis so it looks like you are going up on the world y-axis.

在Direct3D的,这样做的:

In Direct3D, doing:

wm = rotatem * translatem;

是不同的。它看起来像对象只是旋转的起源和翻译在世界的X轴如此这般的权利,而不是上升。它只能有一次我颠倒了顺序,并从右至左读。

is different. It looks like the object was just rotated at the origin and translated on the world's x-axis so it goes to the right and not up. It only works once I reverse the order and read from right to left.

此外,例如,在DX10坦诚Luna的书,他就开始讲解如何做镜面反射。我得到了这一切,但是当他做,例如:

Also for example, in frank luna's book on DX10, he goes into explaining how to do mirror reflections. I get all of that but when he does for example:

reflection_matrix = world_m * reflection_m;

周围的xy平面,做我跨preT这是第一次做一个全球定位则反射或相反的?

around the xy plane, do I interpret this as first doing a the world positioning then a reflection or the opposite?

推荐答案

现在的问题是你乘以矩阵为了得到复合变换矩阵是从它应该是相反的。您正在做什么: WM = rotatem * translatem ,它遵循​​你正在做的OpenGL操作的顺序,但对DirectX矩阵应该是 WM = translatem * rotatem

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

OpenGL和DirectX之间的根本区别源于使OpenGL把矩阵中的列重大秩序,而DirectX的对待阵的行主要秩序的事实。

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.

从列主要去排大,你需要找到的转置(交换行和列)的OpenGL的矩阵。

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

所以,如果你写 WM = rotatem * translatem 在OpenGL中,那么你想的是,转支持DirectX,这就是:

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

这就解释了为什么在矩阵的乘法顺序有DirectX中得到扭转。

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

209