PDA

View Full Version : glRotate



08-09-2002, 03:59 AM
When I use the Rotate function like this:
glRotatef(x,0.0f,0.0f,0.0f)
x increases with 45.0f / DrawGLScene

Why does my cube move into the screen and comes out again with its back first.

If someone would like to help my stupid brain I'd be glad. Thanks.

Jonas

nexusone
08-09-2002, 05:22 AM
You need to post more of the code...
But I see the following problems:

maybe a error on your part in typing the message but glRotatef(x, 0.0, 0.0, 0.0) does nothing, no rotation will take place. one of the axis must be 1 in order to rotate that axis. zero causes no rotation to take place.

your problem could be a couple of things.

One you are not rotating your cube from the center.
Two you could have your gltranslate at the wrong location.
three you are not using glpush/pop.

You cube shuold be drawn with 0,0,0 being the center of the cube, else if a corner starts at 0,0,0 you are rotating from the corner not the center.

if you need to move and rotate a cube here is example code:

glPushMatrix();
glTranslatef(......); move somewhere on the screen.

glRotatef(.......); Rotate cube around axis.

draw_cube();

glPopMatrix();



Originally posted by Grower:
When I use the Rotate function like this:
glRotatef(x,0.0f,0.0f,0.0f)
x increases with 45.0f / DrawGLScene

Why does my cube move into the screen and comes out again with its back first.

If someone would like to help my stupid brain I'd be glad. Thanks.

Jonas



[This message has been edited by nexusone (edited 08-09-2002).]

Gavin
08-09-2002, 05:23 AM
because the rotate function is about 0,0,0 and the centre of your cube is not at 0,0,0
I think thats what you mean anyway.

Jambolo
08-09-2002, 08:32 AM
Maybe it's because the 2nd, 3rd, and 4th parameters are the axis of rotation. 0,0,0 is not valid.

For example:

a,1,0,0 rotates a degrees around the x axis
a,0,1,0 rotates a degrees around the y axis
a,0,0,1 rotates a degrees around the z axis