How can I determine if a view matrix is ​​left or right?

I have a camera view matrix that I received from the GL program. I know that this matrix is ​​right-handed, since this is how GL works, but how can I check if this matrix is ​​right-handed or left-handed?

For the projection matrix, I check if the matrix [3] [4] (row major) is positive if it is left. Is it correct?

Thanks.

EDIT

I tried the solution of the determinant, but unfortunately this is incorrect (at least according to my experiments):

I used the DX9 math functions to test it (to avoid possible errors in my code). I ran the following code:

D3DXVECTOR3 vEye(0,0,0); D3DXVECTOR3 vTarget(6,3,0); D3DXVECTOR3 vUp(0,0,1); D3DXMATRIX matViewLH; D3DXMATRIX matViewRH; D3DXMatrixLookAtLH(&matViewLH, &vEye, &vTarget, &vUp); D3DXMatrixLookAtRH(&matViewRH, &vEye, &vTarget, &vUp); float fLHDet = D3DXMatrixDeterminant(&matViewLH); float fRHDet = D3DXMatrixDeterminant(&matViewRH); 

And both determinants were equal (both equal 0.99999994) and, obviously, had the same sign.

As for my problem - since I have both a presentation matrix and a projection matrix, and it is relatively easy to check if the projection matrix is ​​LH or RH - I use this information to identify the coordinate system.

+4
source share
2 answers

You must take the determinant of the matrix. Other things being equal, the left and right matrices must have determinants with opposite signs.

It’s a little strange, because the “left” and “right” are rather arbitrary conventions. But matrices reflecting the world as a mirror have negative determinants, therefore, multiplication by such a matrix will change the sign of the determinant.


Edit (updated OQ): I suspect that the difference between the D3DX*LH() and D3DX*RH() functions is that they support 2 different conventions.

If so, you should know that the “left” and “right” are not an attribute of each individual matrix, but how the matrices created by these sets of functions are combined. If you stick with *LH() functions, everything should work correctly; similar to *RH() functions, but if you mix them you will most likely get unexpected results.

In any case, none of these conventions applies to GL, which has its own set of conventions that is not fully compatible with any of the D3D. For example, the GL convention for clipping Z is different from D3D; this means that the projection matrix to create the same representation will necessarily differ between systems.

So, the short answer to your question is "maybe not one."

+2
source

Just connected the same task (only for detecting mirror-transformed objects), found a simple solution by exchanging it. If there is a 3x3 part in the matrix containing 3 perpendicular axes, then you can simply do the cross product of axes 1 and 2, then make the scalar product of this result and the remaining third axis. Check if it is negative or positive - you can decide whether the right / left hand / object is mirrored or not. If I understood the question correctly ...

0
source

Source: https://habr.com/ru/post/1332389/


All Articles