简体   繁体   中英

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

I use these functions from android.OpenGL.Matrix to create my view and projection 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?

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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