1

I am trying to rotate a cube 90 degrees on the Y axis, and then 90 degrees on the Z axis, but when I apply the rotation on the Z axis, it actually changes the angle only on the X axis.

This is my code:

glRotatef(90.0, 0.0, 1.0, 0.0);
glRotatef(90.0, 0.0, 0.0, 1.0);

What is the correct way to achieve the result I want - I.e. 90 degrees on Y and then 90 degrees on Z?

Is there a good tutorial that explains how to use glRotate() correctly with examples?

SomethingSomething
  • 11,491
  • 17
  • 68
  • 126
  • 3
    Have you tried to swap these calls? It usually works. If you need to rotate around local axis and it rotates around global axis and vice versa, you just swap 2 transformations. – HolyBlackCat Aug 16 '15 at 20:05
  • 3
    The order of operations/transformations is important. I'd advise trying to rate on Z first, then on X. To get a hang of it, I'd increment the angle over time and maybe add keyboard shortcut/slider to play with the axes as well. You can also combine the axes: ```glRotatef(90.0, 0.0, 1.0, 1.0);```, might be fun to learn. If you want to get in depth knowledge I recommend [3D Math Primer](http://gamemath.com/about-the-book/) as it eases you into linear algebra concepts (vectors/matrices/quaternions), indepent of OpenGL. – George Profenza Aug 16 '15 at 20:06
  • Amazing!!!!! It got solved when I changed the order to Z->X->Y. Do you want to post an answer? I'll of course accept it and it'll remain a reference for others in the future – SomethingSomething Aug 16 '15 at 20:12

1 Answers1

0

do it once but set which angle you want to rotate within one function

glRotatef(90.0, 0.0, 1.0, 1.0);
krehwell
  • 182
  • 2
  • 9