opengl3dlinear-algebravrmlx3d

Convert OpenGL 4-matrix into VRML T*R*S


I am trying to export a scene from a direct-mode OpenGL program to VRML.

In both OpenGL and VRML, faces can be grouped into objects with their own translation, rotation and scale relative to the scene origin.

In OpenGL these are stored as a 4-matrix representing a translation and a rotation/scale in one matrix [1]. In VRML these must be represented as separate translation, rotation and scaling vectors [2][3].

How can I decompose an arbitrary 4-matrix in this way?

I would prefer to use a library function to do this, to minimise the code I have to maintain and to reduce the chance of errors. I am using C# on Windows and can access any CLR or windows native DLL.


Solution

  • Take a look at the Matrix.Decompose code from the Monogame sources.

    Remember - OpenGL matrices are column-major and DirectX/XNA are row-major.

    Hope that helps.