1

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);
Javier Ramírez
  • 1,001
  • 2
  • 12
  • 23
  • 3
    Are you sure that you want to? Or that you *need* to? Decomposing an orientation into 3 axial rotations (aka: Euler angles) is usually the sign of a bad design. – Nicol Bolas Nov 10 '18 at 03:57
  • Well, what I want is to obtain from the first function, the angles to pass them to the second form. – Javier Ramírez Nov 10 '18 at 04:12
  • 3
    I *know* what you want. I'm saying that you *shouldn't want* that. You want those angles in order to do something with them; I'm saying that what you're trying to do with those angles can be better achieved another way that doesn't involve those angles. – Nicol Bolas Nov 10 '18 at 04:30
  • I do not doubt there are other ways. But I need to do it that way. – Javier Ramírez Nov 10 '18 at 04:48
  • This question is rather a mathematical than a programmer issue. Read about [Euler angles](https://en.wikipedia.org/wiki/Euler_angles). – Rabbid76 Nov 10 '18 at 07:54
  • @JavierRamírez: Why do you need to do it that way? We may be having an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) here. Please tell us, what it really is, you need to accomplish. What *exactly* do you need these particular angles for? Maybe there's a better way to get at these angles in the first place, than trying to decompose a rotation. – datenwolf Nov 10 '18 at 12:05

1 Answers1

2
  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 ...

Spektre
  • 49,595
  • 11
  • 110
  • 380