# glRotate

I used glRotatef(0.0f,0.0f,45.0f).
I am getting clockwise rotation instead of counterclockwise.How??

With that call, your program shouldn’t even compile. You are only passing three parameters, while glRotatef requires four.

First you are using the function wrong:

glRotatef(angle, X, Y, Z);

Where angle is rotation in degrees.
X Y Z = 1 for rotate axis or 0 for no rotation.

To rotate only the X axis then the function would look like this:
glRotatef( 45.0, 1.0, 0.0, 0.0) // rotate X by 45
glRotatef( 15.0, 0.0, 1.0, 0.0) // rotate Y by 15

Originally posted by azariah:
I used glRotatef(0.0f,0.0f,45.0f).
I am getting clockwise rotation instead of counterclockwise.How??

woops! I typed wrongly.Sorry…
Actually I used glRotatef(45.0f,0.0f,0.0f,1.0f)
But I am getting clockwise rotation instead of counterclockwise.How?

[This message has been edited by azariah (edited 03-18-2002).]

[This message has been edited by azariah (edited 03-18-2002).]

maybe because your angle is positive? use ‘-45.0f’

Originally posted by azariah:
woops! I typed wrongly.Sorry…
Actually I used glRotatef(45.0f,0.0f,0.0f,1.0f)
But I am getting clockwise rotation instead of counterclockwise.How?

It could be the location of the camera — glRotatef(45,0,0,1) rotates CCW around +Z.

For example, with gluLookAt(0,0,-1, 0,0,0, 0,1,0) it would rotate clockwise.

I tried with
glRotatef(45,0,0,1);
gluLookAt(0,0,1, 0,0,0, 0,1,0);

Still I am getting clockwise rotation about +z axis.Where am i going wrong???

Ever thought of rotating around -z (i.e. glRotatef(45.0f, 0.0f, 0.0f, -1.0f). Changing the sign is the same as changing the direction of rotation.

I am using the following code …

void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);

gluLookAt(0.0f,0.0f,1.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);

glColor3f(1.0f,0.0f,0.0f);
glutSolidSphere(10.0f,15,15);

glColor3f(1.0f,1.0f,0.0f);
glRotatef(45.0f,0.0f,0.0f,1.0f);
glTranslatef(50.0f,0.0f,0.0f);
glutSolidSphere(10.f,15,15);

glutSwapBuffers();
}

Here the coordinate system is rotated in clockwise direction.
It should be in counter clockwise direction.
Where am I going wrong here???

[This message has been edited by azariah (edited 04-02-2002).]