简体   繁体   English

OpenGL在模型视图中使用左手坐标系

[英]OpenGL use left handed coordinate system in model view

In my OpenGL I want to use a left handed coordinate system for the model space but a right handed for the view space. 在我的OpenGL中,我想在模型空间中使用左手坐标系,而在视图空间中使用右手坐标系。 That's because if I think of me as the origin of the coordinate system: 那是因为如果我认为我是坐标系的原点:

  • for me it is common that thigs that are far away and in front of me have a positiv z koordinate so I have to use a left handed coordinate system in model view 对我来说,很常见的是,距离较远且位于我前面的thig具有正z坐标,因此我必须在模型视图中使用左手坐标系
  • if I walk back I can put z -= 1 in the setLookAtM method which creates my view matrix and it is common that if I walk back I have to subtract the z value if I go backwards 如果我往回走,可以在创建我的视图矩阵的setLookAtM方法中放入z -= 1 ,这很常见,如果我往回走,我必须向后减去z值

I use these functions from android.OpenGL.Matrix to create my view and projection matrix: 我使用android.OpenGL.Matrix以下函数来创建我的视图和投影矩阵:

Matrix.setLookAtM(data, 0,     0, 0, 0,     0, 0, -1,     0, 1, 0);
Matrix.perspectiveM(projection, 45, width / height, 1f, 50f);

What can i do / what do I have to change to get the result discribed above so that the z axis for models points into the screen but the z axis for the camera points out of the screen? 我该怎么做/必须做些什么才能获得上面描述的结果,以便模型的z轴指向屏幕,而相机的z轴指向屏幕之外?

If this is not possible with this two matrixes I have to live with it as it is now because I do not want to applay a new operation to each modelMatrix each time I render the object because of time. 如果这两个矩阵不可​​能做到这一点,那么我就必须忍受它,因为现在我不想每次由于时间而渲染对象时都对每个modelMatrix施加新的操作。

You can use any coordinate system you want. 您可以使用任何所需的坐标系。

If you want a left handed world coordinate system, but a right handed eye coordinate system, this means that you need to flip the handedness in the view transformation. 如果要使用左手世界坐标系,而要用右手眼坐标系,则意味着您需要在视图变换中翻转惯性。 You can do this having a mirror transformation as part of the view matrix. 您可以通过将镜像转换作为视图矩阵的一部分来执行此操作。

The only slight complication is that setLookAtM() will not support that. 仅有的一点麻烦是setLookAtM()将不支持该功能。 The matrix it builds is a combination of rotation and translation, which maintains the handedness. 它建立的矩阵是旋转和平移的组合,可以保持惯用性。 You could combine the result with a mirror transform. 您可以将结果与镜像转换结合在一起。 But since the view matrix is so simple with the parameters you pass, it's just as easy to build the view matrix yourself. 但是,由于使用您传递的参数,视图矩阵非常简单,因此自己构建视图矩阵也很容易。

In fact, your setLookAtM() call: 实际上,您的setLookAtM()调用:

setLookAtM(data, 0,     0, 0, 0,     0, 0, -1,     0, 1, 0);

builds an identity matrix. 建立一个单位矩阵。 So if you want to flip the z coordinate, use this mirror transformation as the view matrix, instead of the identity matrix you have right now: 因此,如果要翻转z坐标,请使用此镜像变换作为视图矩阵,而不是现在拥有的单位矩阵:

[ 1  0  0  0 ]
[ 0  1  0  0 ]
[ 0  0 -1  0 ]
[ 0  0  0  1 ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM