Converting DirectX vertexes to OpenGL vertexes

六眼飞鱼酱① 提交于 2020-01-05 05:05:42

问题


I have a file with full of vertex data which was exported from a software which used DirectX. Now I want to create a mesh in Ogre out of it. I set Ogre to use OpenGL since I develop on a Mac, with Xcode.

My question is how can I convert these vertices to be OpenGL compatible?

For example If I have a DirectX vertex in this format: DirectXVertex vertexDX = {x, y, z} what would it look like in a OpenGL vertex: OpenGLVertex vertexGL = ?

Also in the file I have the data of the faces of the triangles with the indexes to the right vertices. Do they have to be converted too somehow, or only the vertices need to be changed?


回答1:


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

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 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.

  • 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.

  • 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.

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 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);


来源:https://stackoverflow.com/questions/16594682/converting-directx-vertexes-to-opengl-vertexes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!