I’m developing a plugin for an application called Daz Studio (more info here, if you are curious: INFINITO plugin), using QT and OpenGL.

In the plugin glWidget, my object rotates using the local coordinate system. I need to convert those angles into world coordinate system (because the main application opengl viewport expect objects to work that way).

Matrices, math in general is my pet hate, any help greatly appreciated.

Well, a rotation in a local system won’t be (in general) also only a single rotation in the global system. But it will generally be a rotation (with different axis and different angle) plus a translation.

Let’s say M is the matrix that makes the transformation from the global system to the local system you want.

If you apply a rotation R (as a 4*4 matrix) in the local system, the results of this rotation of a point P in the local system will be:
P’ = R * P.

If you want it in the global system, it will then be
P" = M * R * P

From these results, you can then deduce the 3 axis (3 column-vectors, let’s say v1,v2,v3) and the translation (last column-vector). [note: use the matrix M*R for this]

I think you can then check the angles between v1 and i (1,0,0), v2 and j (0,1,0) and v3 and k (0,0,1). You then have the 3 angles around the 3 axis expressed in the global system, plus the required translation.

Maybe I should have given more info about what I’m trying to accomplish, I’ve the feeling I’ve created a chaotic thread and instead of posting/asking code I should have explained more in detail what I need to do.

I have a simple opengl application where I load and display .obj files. The application allows also to position, scale and rotate those models using the mouse. All those transformations happen in local space.
The application allows to export the above data in a .txt file, with the following scheme:

Later on, in a separate, commercial application, I read this .txt file and I recreate the scene, loading sequentually the obj’s files and applying the transformation values read from the .txt file.
Problem is, that the commercial application perform rotations in world space, while the angles that I “exported” are in local space.

So, what I’m trying to do is to convert those angles from local to world space so that the objects are properly rotated in the commercial application.

I’m totally confused.
What drives me crazy is that I’m so dumb to figure out what it seems to be such an easy problem.
I mean, let’s forget opengl for a moment.

I have an object rotated in local space as follows:

pitch=45, yaw=30, roll=15

Given that world axis are [1,0,0] [0,1,0] [0,0,1]

Now, let’s calculate world angles out of it… what is the math beyond it?

If M is the matrix that transforms from world space to your local space (translation + rotation + scaling for example), and you have the matrix R that does your rotation in this local space, then the matrix M*R makes the both transformations at once. Let’s call this matrix A.

A is then in the form:

a0 a1 a2 a3
a4 a5 a6 a7
a8 a9 a10 a11
0 0 0 1

Generally, the last line is (0,0,0,1).

Then, the vectors v0 (a0, a4, a8), v1 (a1, a5, a9) and v2 (a2, a6 and a10) are the eigenvectors of this matrix, which means they represent the 3 axis vectors of the local system.

Thinking a bit about your topic, I’d like to add: if the rotation center in the local space is the same than the object’s space center, then you don’t need math at all. In this way, what you have to do is simply use the ‘local-space’ angles as world-space angles and rotate objects before translating them into their position.

What do you mean with “local space”?
To do a local space transformation (ex. rotation), you need to have three arbitrary orthonormal axes, and you must build a rotation matrix relative to these axes (instead of the world’s space axes x(1,0,0), y(0,1,0), z(0,0,1)).
If you didn’t specify these axes, the rotation is expressed in world space, not local space.

The “real” local-space is expressed by your vertices in the .obj file. Every vertex of the model is in fact a vector relative to the same (local) origin (0,0,0). It’s called “local”, because you want to translate and rotate every vertex of the model in a scene without effectively modify and store the transformed vertices (the transformation is performed on the fly and so the values stored will remain always the same).

The angles are relative to the world’s axes x, y, z.
And the position is obviously in world space.
As arts said, no math is required.

If the rotation between two different applications is not the same, the problem can be related to other factors. Make sure the two applications use the same conventions (ex. pitch-yaw-roll rotations need to be applied in the same order) and make sure the camera position and orientation is the same of your application.