将DirectX顶点转换为OpenGL顶点 [英] Converting DirectX vertexes to OpenGL vertexes

查看:508
本文介绍了将DirectX顶点转换为OpenGL顶点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个充满顶点数据的文件,该文件是从使用DirectX的软件导出的.现在,我想用它在Ogre中创建一个网格.自从我在Mac上使用Xcode进行开发以来,我就将Ogre设置为使用OpenGL.

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.

我的问题是如何将这些顶点转换为与OpenGL兼容?

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

例如,如果我具有这种格式的DirectX顶点: DirectXVertex vertexDX = {x,y,z} 在OpenGL顶点中会是什么样子: OpenGLVertex vertexGL =?

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?

推荐答案

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

这篇关于将DirectX顶点转换为OpenGL顶点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆