Jump to content

  • Log In with Google      Sign In   
  • Create Account

Help with glRotated(Angle,x,y,z);

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Nexus   Members   -  Reputation: 122


Posted 24 October 1999 - 08:34 AM


I'm trying to make the jump to 3d and learn this OpenGL thing and I'm having a bit of difficulty. I'm specifically trying to make a small project in which I can fly the viewpoint around some simple objects. The viewpoint can move forwards, backwards, left, right, pitch, roll, and yaw. The objects should appear to stay still. Here's the problem:

I used the OpenGL programming Guide suggestion to do

Translate works fine but the rotations are screwy and the screwiness depends on the order I do them.
If I do the pitch rotation last then if I'm yawed 90 degrees pitch behaves like roll...

I'm a newbie to 3d stuff but I do have a good deal of experience in 2d and general programming. Can any of you please help me?




#2 pdown   Members   -  Reputation: 122


Posted 12 October 1999 - 04:33 PM

This is a common problem when using Euler angles called "gimbel lock". I happens with 90 degree rotaions where one axis is rotated into alignment with another. I'm not sure what the best solution is for you. But you might want to take a look at this gamasutra article.

#3 Nexus   Members   -  Reputation: 122


Posted 13 October 1999 - 04:21 PM

I only gave the 90 degree rotation as an example. The effect turns up at any nonzero rotation. I can't believe that they would list this as an example in the OpenGL Programming Guide and have it flat out not work correctly....that's why I was really hoping it was just something I was forgetting to do.

Here's a better description of the behavior:
//more setup
loop {
//respond to kb
// clamp angles between 0 and 359
glRotated(yaw, 0,1,0);
glRotated(roll, 0,0,1);
//draw simple cubes
SwapBuffers( hDC );

That is the basic layout of my code. nothing fancy at all.

the behavior is as follows:
pitch & roll interact well. (except for some weirdness when I pitch 180 degrees over, roll seems to invert behavior.)
pitch and yaw do not.
yaw seems to ignore pitch completely - if I pitch *any* angle yaw still acts like I'm facing straight down the z axis.

Is that gimbal lock? From the article it seemed that they were specifically talking about 90 degree rotation problems. Mine behaves like this all the time. It's basically behaves like quake rotation when I want descent.


#4 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:


Posted 13 October 1999 - 04:45 PM

It isn't a gimble lock, this is something that confused the hell out of me at first. The problem is that for some reason, OpenGL does the transformations in the reverse order that you specify them. Move that translate to above your rotates, and it should work fine.


#5 Nexus   Members   -  Reputation: 122


Posted 13 October 1999 - 05:45 PM

They need an icon of a smiley ripping hair out of it's head.

Thanks for the input but that didn't do it either.
I think the problem resides in this:
(after much 1 eye closed hand yawing and pitching)
The order of the yaw/pitch is important as well...but whichever I choose (I'm scaling out the roll for now.) I'm incorrect.

If I pitch then yaw then I get proper behavior if thats the way the person moves the camera (look up and turn left/right for extreme example)

If I yaw then pitch then I get improper behavior if the user pitches then yaws the camera (turn 90 left or right and then yaw up/down for extreme example - looks like rotate) but this behaves properly where the other way fails and vice versa.

This seems like something that people would do all the time in OpenGL but I've been scouring tutorials for it - cant find anything.


#6 Max   Members   -  Reputation: 122


Posted 24 October 1999 - 04:22 AM

Your problem could be solved by using the GluLookAt rutine, but you would have to rotate the eye and up vectors manualy.

The reason that OpenGl transformations appear backwards is because of the way that two matrices are multiplyed. the transformations commands (glrotate,glscale,gltranslate) multiply the current matrix C by the transformation matrix T on the right side. C:=C*T.

#7 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:


Posted 24 October 1999 - 08:34 AM

I don't know if this has anything to do directly with the problem, but I believe that gluPerspective() needs to be applied to GL_PROJECTION matrix, not the GL_MODELVIEW matrix. This code could corrupt the modelview matrix.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.