Decompose glRotatef

110 views Asked by At

I have the function glRotatef with these parameters.

glRotatef(-119.718,-0.58064,-0.575698,-0.575699);

If I do this...

glRotatef(-119.718,-0.58064,0.0,0.0);
glRotatef(-119.718,0.0,-0.575698,0.0);
glRotatef(-119.718,0.0,0.0,-0.575699);

I do not get the same rotation as using the above. So, how do I get the rotation of each element (x, y, z) from this?

glRotatef(-119.718,-0.58064,-0.575698,-0.575699);
1

There are 1 answers

1
Spektre On BEST ANSWER
  1. create unit matrix glLoadIdentity();
  2. rotate the matrix by glRotatef(-119.718,-0.58064,-0.575698,-0.575699);
  3. get the matrix to CPU side code by glGetDoublev
  4. compute the Euler angles from it using trigonometry in order you need

So the first 3 bullets are straightforward ...

double m[16];
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glRotatef(-119.718,-0.58064,-0.575698,-0.575699);
glGetDoublev(GL_MODELVIEW_MATRIX,m);
glPopMatrix();

the last bullet depends on your Euler angles order and coordinate system notations and its a pure math... So either derive the equations your self (atan2 and acos are your friends) or google:

extracting euler angles from rotation matrix

And find a hit matching your order... To implement it you also need to understand the stuff so see my:

Also from the OP I got the feeling you do not understand how glRotate works. In a nutshell it rotates around point (0,0,0) and arbitrary 3D vector as axis. See Rodrigues_rotation_formula in the previous link but its doable also by exploiting cross and dot product and using axis aligned rotation.

Now to get back to your question after you obtain the Euler angles (assuming order ax,ay,az) then the rotation itself would look like this:

glRotatef(ax,1.0,0.0,0.0);
glRotatef(ay,0.0,1.0,0.0);
glRotatef(az,0.0,0.0,1.0);

And must be done in the same order as your Euler angles are ...