PDA

View Full Version : Can i have an explanation of glRotatef()?



skorman00
05-24-2003, 10:59 AM
I have a small program which draws a triangle with color and smooth shading, and I am able to rotate it. However, I find it odd that in order to rotate it on 2 axes properly, I need to call the function twice.

If I use these lines:
glRotatef(angle,0.0f,1.0f,1.0f);
angle+=0.5f;
the result is the triangle spinning on the y-axis, but only tilted on the z. If the z is <= the y parameter, the tilt is at a degree of whatever is passed to it. But when I pass a higher number for z than y, then the triangle rotates on the z axis and is tilted on the y.

If I use these line:
glRotatef(angle, 0.0f, 1.0f, 0.0f);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
angle+=0.5f;
the result is the triangle spinning on both axes continuously like I want it too.

I've read a few explanations of how glRotatef() works, and it seems to me like I should be able to get it to rotate on both axes with just one call of the function.
I find it odd how the first bit of code causes a rotation and a tilt instead of two rotations, but maybe thats just me.

Any explanation of why it doesn't work would be greatly appreciated.

chennes
05-24-2003, 05:29 PM
I think the confusion is a misunderstanding of the last three parameters to the function:




glRotatef (angle, x, y, z)


In this function, (x,y,z) is defining a vector to rotate about. So what (0,1,1) is saying is rotate "angle" around a vector halfway between the y and z axes, in the x plane. The result is a triangle spinning around that axis.

skorman00
05-25-2003, 04:48 PM
I may not understand it completely. from what you're saying, it seems like calling glRotatef(angle, 1, 0, 1) should rotate it on an axis between z and x. so if z was coming straight at me, and x was going left to right, the axis it should spin on would be going toward me and to the right.

That's the image I'm getting. If I'm wrong, maybe I'm confused one what you mean by vector.

mhayenga
05-26-2003, 03:38 AM
Sounds like ya got it... Like he said, it just defines a vector axis for it to rotate around, and then just think of right hand rule to see how it would rotate....