• FEATURED

View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

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.

6 replies to this topic

#1Nexus  Members

Posted 24 October 1999 - 08:34 AM

Hi.

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
glRotated(roll,0,0,1);
glRotated(yaw,0,1,0);
glRotated(pitch,1,0,0);
glTranslated(x,y,z);

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?

Thanks,

Nex

#2pdown  Members

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.
http://www.gamasutra.com/features/programming/19980703/quaternions_04.htm

#3Nexus  Members

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:
//setup
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
//more setup
loop {
gluPerspective(90,1.25,.5,20.0);
//respond to kb
// clamp angles between 0 and 359
glRotated(pitch,1,0,0);
glRotated(yaw, 0,1,0);
glRotated(roll, 0,0,1);
glTranslated(-xEye,-yEye,-zEye);
//draw simple cubes
glFlush();
SwapBuffers( hDC );
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

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.

Thanks,
Nex

#4Anonymous Poster_Anonymous Poster_*  Guests

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.

Jonathan

#5Nexus  Members

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.

ARRRRRRGH,
Nex

#6Max  Members

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.

#7Anonymous Poster_Anonymous Poster_*  Guests

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.