I am using a tracking device (only rotation tracked, not position) for input and I send its rotation matrix to an OpenGL application. The tracker sends an identity matrix when it’s aligned with it’s axis system, i.e when the tracker is facing towards its Y axis and the up direction of the tracker is facing it’s Z axis. As seen in the right hand side of the illustration.

If I rotate the tracker however, the corresponding rotation in my opengl program is wrong. To try to remedy that I tried to multiply the matrix provided by the tracker with:
1 0 0 0
0 0 1 0
0 -1 0 0
0 0 0 1
To remap but no matter what I try it seems like always one of the three rotations is wrong.
Is there some matrix that I could multiply my tracker’s matrix with to get the rotations right?
===== EDIT =====
Android’s remapCoordinateSystem seems to achieve what I want but I can’t understand the code in there:
https://github.com/android/platform_frameworks_base/blob/master/core/java/android/hardware/SensorManager.java#L1459
The following worked to translate the matrix to work properly with OpenGL.
I don’t know why it worked, but it worked.