# How to convert decomposed transformations between different coordinate systems?

I am converting some Unity3D scenes to a proprietary json format to be used by my OpenGL renderer that uses a different coordinate system from Unity's.

I have multiple sets of {translation, rotation(quat), scale} pairs that describe some node transformations. The engine that uses them (Unity) uses the positive x-axis looking to the right, the positive y-axis looking up and the positive z-axis looking front.

I want to convert each pair into a {new_translation, new_rotation(quat), new_scale} in order to use them in my engine using the same coordinate convention with the z-axis inverted (positive z-axis looking back, the most common OpenGL convention).

How should the new pairs be constructed?

Maybe not the best solution but one that should work would be to multiply them by matrix like $$\begin{bmatrix}-1&0&0\\0&1&0\\0&0&-1\end{bmatrix}$$ And multiply by this your mvp matrix to convert meshes vertices (this could be done offline).

Quaternion can be change to matrix form, multiply and save as quaternion.

You also need to change culling in OpenGL because triangle order will be inverted.

I did this in one project and it works fine. If I will find this project I will write something more about it.

//EDIT

This matrix will invert your Z-axis and X-axis

//EDIT2

To apply this solution to each to component you need to:

1. Change translation x and z component to -x and -z.

2. Rotation in matrix form multiply by matrix above and change it to quaternion.

3. Scale leave how it is.

4. Iterate through all meshes and multiply each of their vertices by this matrix.

//EDIT3

Instead of matrix you can just multiply rotation by quaternion (0, 0, 1, 0) (in order (w, x, y, z)) and new quaternion will look like this: (-y,z,w,-x). This operation (and matrix too) just rotate object by 180 degree in y-axis.

• This solution is kinda obvious, and far from the question asked. Goal of the question is to find a solution that operates to the uncombined tranform components, before creating any model matrix. – Fr0stBit Jan 23 '17 at 14:56
• But you can apply this solution to uncombined transform components. You can of course simplify it, e.g. change sign in position instead of multiply it by matrix but idea is the same. Applying it to model matrix will apply it also to mesh vertices and you don't need to change models. – Derag Jan 23 '17 at 15:03
• Of course if you apply this matrix to scale you don't need to worry about meshes but scale like (1,1,-1) isn't intuitive. – Derag Jan 23 '17 at 16:26
• Modifying mesh vertices for some simple transformation doesn't seem a good idea, seems more like it will complicate things to a new level. – Fr0stBit Jan 23 '17 at 18:55
• When I think about it now, maybe I was wrong. With translation and rotation like this meshes should look alright and no changing in culling should be needed. – Derag Jan 23 '17 at 21:23