Sign in to follow this  
SoD

Convert euler angles by different coordinate systems

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 http://trenki.gippsbiz.com/math3d/ 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this