且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将DirectX顶点转换为OpenGL顶点

更新时间:2023-11-12 23:31:58

DirectX使用左手坐标系,而OpenGL使用右手坐标系.

DirectX uses a left-handed coordinate system, while OpenGL uses a right-handed system.

MSDN上的此文章描述了以另一种方式(即从OpenGL到Directx)移植数据时需要做的事情.要点是:

This article on MSDN describes what you need to do if porting data the other way (i.e. from OpenGL to Directx). The main points are:

Direct3D使用左手坐标系.如果要移植基于右手坐标系的应用程序,则必须对传递给Direct3D的数据进行两次更改.

Direct3D uses a left-handed coordinate system. If you are porting an application that is based on a right-handed coordinate system, you must make two changes to the data passed to Direct3D.

  • 翻转三角形顶点的顺序,以便系统从前面顺时针移动它们.换句话说,如果顶点是v0,v1,v2,则将它们作为v0,v2,v1传递给Direct3D.

  • Flip the order of triangle vertices so that the system traverses them clockwise from the front. In other words, if the vertices are v0, v1, v2, pass them to Direct3D as v0, v2, v1.

使用视图矩阵在z方向上按-1缩放世界空间.为此,请翻转用于视图矩阵的D3DMATRIX结构的_31,_32,_33和_34成员的符号.

Use the view matrix to scale world space by -1 in the z-direction. To do this, flip the sign of the _31, _32, _33, and _34 member of the D3DMATRIX structure that you use for your view matrix.

因此,如果上面的文章描述了如何将OpenGL从DirectX移植到DirectX,则需要执行上述相反的操作以进行另一种转换.碰巧的是,上述操作的反过程是完全相同的.

So, if the article above describes how to port fro OpenGL to DirectX, you need to do the inverse of the above to convert the other way. As it happens, the inverse of the above operations is exactly the same.

OpenGL没有像DirectX那样具有独立的模型和视图矩阵,因为它们被串联到模型视图矩阵中.您可以像这样模拟左手坐标系:

OpenGL doesn't have separate model and view matrices like DirectX does, as they are concatenated into the modelview matrix. You can simulate a left-handed coordinate system like this:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(1.0f, 1.0f, -1.0f);