Poken1151
Poken1151

Reputation: 580

Converting OpenGL's glRotated to Maya's cmds.rotate

I have a C++/OpenGL program that creates a lot of cylinders at various rotations so they all appear connected. I added on an export method to write a python script of the same draw methods for Maya so I could load the script.

I know when OpenGL creates and rotates a Cylinder, it does so aligning it to the Z-axis and it rotates and translates it by it's "base".

So I've been careful in my Maya conversion move the pivots before any transformations and also, to pre-align the cylinders to OpenGL's standard (and afterwards freezing the transformation, thus creating the OpenGL basis).

The translations all seem to move to the correct spot, but I worry if I'm doing the conversion between the rotation functions correctly. I understand both Maya and OpenGL do rotations in degrees. However, the function in OpenGL is:

glRotated(angle, x, y, z);

And in Maya's Python:

cmds.rotate(x-deg, y-deg, z-deg);

So what I have been doing is taking the angle from the OpenGL and multiplying it by the given axis for the Maya method:

cmds.rotate(angle * x, angle * y, angle * z);

I figured this would work and give me what I want. but the rotations still seem off. I cant find a good explanation of weather or not this could work the way I expect. So can anyone confirm this relationship?

Upvotes: 0

Views: 276

Answers (1)

Andreas Haferburg
Andreas Haferburg

Reputation: 5520

This won't work in general, only if the rotation axis is aligned with one of the principal axes.

Your rotation is given as axis+angle, and you need to convert it to Euler angles. You could either do this manually after reading up on it e.g. on Wikipedia, or you could construct an MQuaternion, use the setAxisAngle() method (uses radians, not degrees), then convert it to MEulerAngle.

Upvotes: 1

Related Questions