Question about glrotatef
Hi guys! When you rotate using glrotatef(...) is there a restriction that you can't go beyond 90 degrees on any of the axis or something? I am doing rotations but whenever i go beyond 90 degrees on a given axis, and then try to rotate (jkust one degree) around another axis, my modelview matrix goes berserk. If I stay within 90 degrees the rotation works fine. Update : I should also mention that I am storing my actor's transform matrix (Up, Right and Out vectors) each time i make a rotation, and I rotate around those axes when I rotate and not around (1,0,0), (0,1,0) or (0,0,1).
There can be only one.
No, there is no such restriction. Remember, however, that successive glRotatef() calls all pick up from where the last rotation finished.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
The following code rotates the player each frame:
Then,
The following method updates my player axes after each rotation:
glPushMatrix(); glLoadIdentity(); glRotatef( Player->GetYaw(), Player->GetUpVector().GetX(), // rot around local y axis Player->GetUpVector().GetY(), Player->GetUpVector().GetZ()); glRotatef( Player->GetPitch(), Player->GetRightVector().GetX(), // rot around local x axis Player->GetRightVector().GetY(), Player->GetRightVector().GetZ()); glRotatef( Player->GetRoll(), Player->GetOrientation().GetX(), //rot around "out"/forward vector Player->GetOrientation().GetY(), Player->GetOrientation().GetZ()); glGetFloatv(GL_MODELVIEW_MATRIX, mat); Player->UpdateAxes();
Then,
The following method updates my player axes after each rotation:
void Actor::UpdateAxes(){ GLfloat mat[16]; // temp modelview mat glRotatef( GetYaw(), GetUpVector().GetX(), GetUpVector().GetY(), GetUpVector().GetZ()); glRotatef( GetPitch(), GetRightVector().GetX(), GetRightVector().GetY(), GetRightVector().GetZ()); glRotatef( GetRoll(), GetOrientation().GetX(), GetOrientation().GetY(), GetOrientation().GetZ()); glGetFloatv(GL_MODELVIEW_MATRIX, mat); SetRightVector(Vector3D(mat[0],mat[1],mat[2])); SetUpVector(Vector3D(mat[4],mat[5],mat[6])); SetOrientation(Vector3D(mat[8],mat[9],mat[10]));}
There can be only one.
Btw, my code is indented. I just don't know how to make it appear as such on here. ;)
There can be only one.
Quote:
Original post by Gice
Btw, my code is indented. I just don't know how to make it appear as such on here. ;)
Use the
- tags.<br>[edit]<br>Nevermind - source-tags also work [smile]<br>[/edit]
Well I found one bug ;
I had to call glLoadIdentity() before I update the player axes, but I just changed that and it still messes up. This is driving me nuts.
I had to call glLoadIdentity() before I update the player axes, but I just changed that and it still messes up. This is driving me nuts.
There can be only one.
I'm not good at this kind of things, but I think you shouldn't be rotating three times, because the third vector ( Player->GetOrientation() ) is implicit in the other two.
This means that by rotating around the y and x axis, you already get the rotation about the z one.
I hope this makes sense (supposing it is correct)
This means that by rotating around the y and x axis, you already get the rotation about the z one.
I hope this makes sense (supposing it is correct)
The problem you are having is gimble lock. If you pitch downwards 90 degrees(facing down), then try to roll, you are actually yawing, or the other way around. The solutions are either to use quaternions, limit the rotations so they don't combine in this fasion(maybe ordering them differently depending on what you are doing), or maybe using matrices, though I believe that matrices still are affected by gimbal lock. I have never had to use quaternions myself because I can just order and limit my rotations, but I have never made a truly unlimited flight simulator where you can go upside down and all around either.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement