# GlRotatef

This topic is 3885 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello there, i have following question: I call this following function: glRotatef(12.0, 12.0, 12.0, 0.0); // 12 degrees for x- and y-Axis Can somebody tell me how the upper called function would look like in the modelview matrix and in code ????? I mean something like this: glRotatef(12.0, 0.0, 12.0, 0.0); // WRONG! glRotatef(12.0, 12.0, 0.0, 0.0); // WRONG! This is not the same like above. Why ??? M = Rx(12 Grad) * Ry(12 Grad) // This is wrong too, i know I would be very thankful if somebody could help me.... Gruss SmartyShark

##### Share on other sites
Nobody can help me???

##### Share on other sites
I don't understand what you're asking.

BTW, you only need to put a 1 for each axis
ex: glRotatef( 12.0f, 1.0f, 1.0f, 0.0f );

##### Share on other sites
Quote:
 Original post by SmartySharkNobody can help me???
Um...it's only been 20 minutes! :)

Anyway:
glRotatef(12.0, 12.0, 12.0, 0.0); // 12 degrees for x- and y-Axis
This does not represent a 12 degree rotation about the x and y axes, but rather a rotation about an axis that lies along the diagonal of the positive quadrant of the xy plane. As such, the two code excerpts you posted will not produce the same results.

##### Share on other sites
Thank you very much for reply,

So what would represent this called function :

glRotate(12.0, 12.0, 12.0, 0.0); ?????

Greets
SmartyShark

##### Share on other sites
I mean in one by one steps like :

glRotate(12.0, 1.0, 0.0, 0.0) etc.

Which code would as an alternative represent this:

glRotate(12.0, 12.0, 12.0, 0.0)

??

##### Share on other sites
I mean in one by one steps like :

glRotate(12.0, 1.0, 0.0, 0.0) etc.

Which code would as an alternative represent this:

glRotate(12.0, 12.0, 12.0, 0.0)

??

##### Share on other sites

can nobody help me??

##### Share on other sites
"glRotate(12.0, 12.0, 12.0, 0.0)"

If I understand well what you wanna do, you just want to make a first rotation of 12 degrees along the x axis, and then a second rotation of 12 degrees along the y axis.

Just make that :

glRotatef (12.0, 1.0, 0.0, 0.0); // First rotation about the X axis
glRotatef (12.0, 0.0, 1.0, 0.0); // Second rotation about the Y axis

And, of course, it's not the same as :

glRotatef (12.0, 0.0, 1.0, 0.0);
glRotatef (12.0, 1.0, 0.0, 0.0);

If you wanna make those rotations by yourself, just create two matrices :

Matrix4 mat1, mat2, matFinal;
matFinal = mat1 * mat2;

glMultMatrix (&matFinal.m00);

It's exactly the same as using glRotatef, since glRotatef affects the modelview matrix.

Said you make glRotatef (12.0, 1.0, 0.0, 0.0), internally, OpenGL creates a rotation matrix along X axis :

1.0 0.0 0.0 0.0;
0.0 cAngle -sAngle 0.0
0.0 sAngle cAngle 0.0;
0.0 0.0 0.0 1.0

with cAngle is the cosine of the angle in radians, and sAngle the sinus of the angle in radians.

And then multiplies this matrix with the modelview matrix.

And with your own functions :
Matrix4 mat1;
mat1.RotationAboutXAxis (12.0), it creates a matrix, and with the function glMultMatrix (&mat1.m00), you multiplies the modelview matrix with that matrix.

Hope I didn't say to much false things, since I never learned matrices at school, just with books, alone :p.

##### Share on other sites
Quote:
 Original post by SmartySharkI mean in one by one steps like :glRotate(12.0, 1.0, 0.0, 0.0) etc.Which code would as an alternative represent this:glRotate(12.0, 12.0, 12.0, 0.0)??

Why do you put 12.0 for the vector part? Yes, GL normalizes the vector but it looks like you are experimenting and just throwing numbers at GL.
This kind of stuff is explained in the GL spec in case you are interested in long technical documents.

##### Share on other sites
Hi,

glRotatef(12, 1.0, 1.0, 0.0) is definitly not the same as :

glRotatef(12, 0.0, 1.0, 0.0)
glRotatef(12, 1.0, 0.0, 0.0)

Thats why you should use in that case so-called Quaternionen.

1) Example-Code :

glRotatef(12.0, 1.0, 0.0, 0.0); // X-Axis
glBegin(GL_POINTS);
glVertex3f(1.0, 0.0, 2.0) // P
glEnd();

The Modelview-Matrix would look like this :

M = Rx(12) * P // Right

Ok so far so good.

2) Example-Code :

glRotatef(12.0, 1.0, 1.0, 0.0); // X-Y-Axis, diagonal
glBegin(GL_POINTS);
glVertex3f(1.0, 0.0, 2.0) // P
glEnd();

M = Rx(12) * Ry(12) * P // WRONG!

You understand ? You cannot wright a rotation about two axis
so easy...

So how it would be right?

Greets

##### Share on other sites
More simple question :

glRotatef(12.0, 1.0, 1.0, 0.0);

- How is the modelview-Matrix in 4x4 Coordinates?
You can represent this matrix as an multiplication of several
matrices something like :

M = Rx * Ry..... * P

But i dont know how is the right answer?

##### Share on other sites
"glRotatef(12.0, 1.0, 1.0, 0.0);"

I'm not sure it is possible. I think that the vector part must be a unit vector, but I'm not sure. So take the vector [1.0 1.0 0.0], then normalize it :
[0.707107 0.707107 0.0], and now it should work :

glRotatef (12.0, 0.707107, 0.707170, 0.0).

But I'm not sure about that.

EDIT : moreover, glRotatef builds that matrix :

( xx(1-c)+c xy(1-c)-zs xz(1-c)+ys 0 )| |
| yx(1-c)+zs yy(1-c)+c yz(1-c)-xs 0 |
| xz(1-c)-ys yz(1-c)+xs zz(1-c)+c 0 |
| |
( 0 0 0 1 )

So glRotatef makes :

ModelViewMatrix = ModelViewMatrix * thatMatrix;

##### Share on other sites
The vector part of glRotate* does not need to be normalized. glRotatef(12, 1, 1, 0) will work just fine.

##### Share on other sites
I think you dont understand what i mean...

Somehow you can rewrite this call :

glRotatef(12.0, 1.0, 1.0, 0.0);

, into several matrices and you will get the same
result...

But i dont know how.