PDA

View Full Version : Replace two glRotatef() with one glRotatef()?

tgtt
02-24-2004, 04:10 AM
Hi,me again http://www.opengl.org/discussion_boards/ubb/smile.gif

I want to know Is there any way to Replace two glRotatef() with one glRotatef()?

for example
there are two glRotatef:

glRotatef(ang1,x1,y1,z1);//a
glRotatef(ang2,x2,y2,z2);//b

Now i want to make another glRotatef:
glRotatef(ang3,x3,y3,z3);//c

And c will take the function of a and b.
but how to get the ang3,x3,y3,z3?

[This message has been edited by tgtt (edited 02-24-2004).]

nexusone
02-24-2004, 04:46 AM
No, if you have diffent axis of rotations in the two statments.

These two could be made into one:
glRotatef(45,1,0,0);
glRotatef(25,1,0,0);

But not this:
glRotatef(45,1,0,0);
glRotatef(25,0,1,0);

because you would not get the same results by combining them.

mw
02-24-2004, 05:01 AM
yes there is: you have to find the rotation axis and angle which will turn the current orientation of the object to the wished orientation of the object.

a common way to solve this is to compute the resulting rotation matrix or quaternion of all axis rotations and to derive the "new" single axis rotation out of it (various math libraries around provide code to convert between different rotation types)

endash
02-24-2004, 10:04 AM
mw: I could be wrong, but I think you are. Consider glRotate(180, 1,0,0); glRotate(90,0,1,0); There is no way you can get that result from a single glRotate() call, is there?

Like you say, though, you could make a matrix that combines those transformations.

Bob
02-24-2004, 12:19 PM
Originally posted by endash:
Consider glRotate(180, 1,0,0); glRotate(90,0,1,0); There is no way you can get that result from a single glRotate() call, is there?
glRotate(180, 1, 0, 1) http://www.opengl.org/discussion_boards/ubb/rolleyes.gif

endash
02-24-2004, 02:33 PM
Oh yea, duah.