PDA

View Full Version : Independent Rotation Problems

IgnoranceIsBliss
11-24-2002, 12:54 PM
I'm probably going to be seriously flamed as some kind of uber-newbie here, but I am having difficulty getting my axes of rotation to work independantly.

Eg. I store three values, H, R and B for each object in the scene. These are supposed to reflect axes of rotation BASED ON THE DIRECTION IN WHICH THE OBJECT IS FACING. So, as an example, if I increase 'H', the 'front' of the object should always raise up, regardless of other rotations.

The following code makes 'R' an independant axis (it is not effected by the others), simply because it is 'first'...

glRotated(B,0,0,1);
glRotated(H,1,0,0);
glRotated(R,0,1,0);

I can make 'H' an independant axis by compensating for 'R'

glRotated(R,0,1,0);
glRotated(H,1,0,0);
glRotated(-R,0,1,0);

But this then throws 'R' out, making it effected by 'H'.

I know there is a way to do this. I know it is probably incredibly simple. I also know that I an having a great deal of trouble figuring out how the @*\$& it is done! Can someone give me a little help please?

Thanks.

zen
11-24-2002, 07:37 PM
I can't say I can positively answer that question but maybe I can help out a bit.Those BHR angles you're reffering to are more commonly called Euler angles or yaw,roll and pitch.Now what you want to do is represent an object's orientation.Euler angles are a way to do this(no the best),so are matrices and quaternions.I suggest some google research with the terms I've mentioned to see if you can find anything useful.Be careful though that although quats or matrices might look cool you'd better stick with more simple things first if they do the job(you won't be doing any slerp yet will ya?).Also I've read in some docs I had lying around(the matrix and quaternion faq,you'll propably come across it in your search.Read it,at least the matrix portion to begin with) that the usual way to combine these roations is x-axis first then y then z,but I can't guarantee it will work for you.

nexusone
11-25-2002, 04:01 AM
Very simple by using glPush/PopMatrix commands.

The clock program on my website is an good example: http://www.angelfire.com/linux/nexusone/

Here is a simple usage:
glRotatef(rot, 1, 0, 0); // rotate

glPushMatrix()// save matrix
glRotate(rot_a,0,0,1); // Rotate object a only
draw_object_a() // Note this object is still effected by the rotate that was done before the push.
// Note now matrix is back to where is was before operations inside the push/pop, only objects inside the push/pop matrix are effected.

glPushMatrix()
glRotate(rot_b,0,0,1);
draw_object_b() // Also this object is effected by the rotate done before any push/pop
glPopMatrix()

Originally posted by IgnoranceIsBliss:
I'm probably going to be seriously flamed as some kind of uber-newbie here, but I am having difficulty getting my axes of rotation to work independantly.

Eg. I store three values, H, R and B for each object in the scene. These are supposed to reflect axes of rotation BASED ON THE DIRECTION IN WHICH THE OBJECT IS FACING. So, as an example, if I increase 'H', the 'front' of the object should always raise up, regardless of other rotations.

The following code makes 'R' an independant axis (it is not effected by the others), simply because it is 'first'...

glRotated(B,0,0,1);
glRotated(H,1,0,0);
glRotated(R,0,1,0);

I can make 'H' an independant axis by compensating for 'R'

glRotated(R,0,1,0);
glRotated(H,1,0,0);
glRotated(-R,0,1,0);

But this then throws 'R' out, making it effected by 'H'.

I know there is a way to do this. I know it is probably incredibly simple. I also know that I an having a great deal of trouble figuring out how the @*\$& it is done! Can someone give me a little help please?

Thanks.