Advertisement Jump to content
Sign in to follow this  

Convert euler angles by different coordinate systems

This topic is 4986 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, i'm coding an export script from a 3D modeler (Blender) to my own engine written in OpenGL. Every object in the modeler has its own position, rotation, scale. I've a little trouble converting those values because where OpenGL uses the Z axis for depth (more depth -> negative values, less depth -> positive values) Blender instead uses the Y one instead (more depth -> POSITIVE values, less depth -> NEGATIVE values). I've converted x,y,z positions passing them as x, z, -y to my engine. Scaling instead is passed as x, z, y My trouble is converting rotation values. In the engine i use quaternions for handling in an easier way the calculations. I use this math library I'd like to pass the Euler angles of the rotation instead of the 4 components of the quarternion that Blender can calculate itself because people can better understand the rotation reading the xml file "by eye". Having the 3 angles Blender rotate first the object on its X angle, after the Y and finally the Z. I've tried to pass the angles in the x, z, y order to my engine. The quaterion class can be set with yaw, pitch, rool angles. So first i've multipled my "zero" quaternion with a quaternion setted with only x (pitch) value. But when in Blender the object rotate in a sense, in OpenGL in the other one. If i add also the other values the result in unpredictable. I'd like to know if i've to recalculate the angles in some ways because the depth axis is reversed and different or what. Thanks :)

Share this post

Link to post
Share on other sites
This kind of stuff can be confusing, but I'll take a shot at it.

If I'm not mistaken, Blender uses a left-handed coordinate system. Also, as you note, +y is forward. Presumably +z is up, so that puts +x to the left. Assuming standard convention, positive rotations about an axis are clockwise when viewed looking down the axis toward the origin.

OpenGL is right-handed, -z forward, +y up, +x right. Positive rotations about an axis are CCW.

The trick is to take an ordered Euler angle triple XYZ in Blender and convert it so that it will produce the same rotation in OpenGL.

X is applied first; in both Blender and OpenGL a positive rotation should pitch the object up. So we'll leave X as-is.

Next comes Y, which is roll in Blender. The rotation is CCW from the point of view of the object. In OpenGL this corresponds to a positive Z rotation.

Finally, a positive Z rotation in Blender corresponds to a -Y rotation in OpenGL.

So if the Blender angles are X, Y, Z, the equivalent OpenGL commands would be:

glRotate(-Z, 0, 1, 0);
glRotate(Y, 0, 0, 1);
glRotate(X, 1, 0, 0);

Note that the axes are 'out of order'. If you want them in xyz order, you could create the matrix as above and then refactor. There's probably some obvious shortcut, but I'm not thinking of it atm.

I still get confused by Euler angles, so the above may be totally wrong. But you might at least try plugging in those lines of code and see if your Blender and OpenGL rotations match.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!