Multiple Rotations fail...

Hi everybody…

Here is my problem…

I have a cone in my 3d space pointing to Z positive axix.

I want to rotate it like that:
first i want to rotate 270 degrees around X axe.
Second I want to rotate 90 degrees around Y axe but using the original Y axe not the new axe resulting from the first rotation.

Ive tried next:

GlRotatef( figura->alfa() , 1.0 , 0.0 , 0.0 );
glRotatef( figura->beta() , 0.0 , 1.0 , 0.0 );
glRotatef( figura->gamma() , 0.0 , 0.0 , 1.0 );

but i get the problem with the Y axe rotated so I tried with basic Matrix:

GLfloat maux[] = { cycz , sxsycz-cxsz , cxsycz+sxsz , 0 ,
sz , sxsysz+cxcz , cxsysz-sxcz , 0 ,
-sy , sxcy , cxcy , 0 ,
0 , 0 , 0 , 1 };

where cx,cy,cz are the cos() of x,y,z respectively and sx,sy,sz are the sin(). And Again I get the same problem…

What can I do to fix that?


    gluCylinder( obj , figura->_radio() , 0 , altura , 20 , 20 );
    gluDisk( obj , 0 , figura->_radio() , 20 , 5 );

I did not look into your matrix.
However, what you need to do is to figure out the direction of the old Y-axis in the coordination system after 270 degrees rotation about X-axis, and then you rotate 90 degrees about that direction.

You’ll have do do your own matrix maths if you want to do that. Its the order of the multipliction thats important and OpenGL allows for only one.

Be aware that openGL multiply matrices in inverse order… that means… that you have to do any transformations in inverse order too.

That is… if you wants to transalte, and then rotate… the code it must be something like this:
//geometry definition

Now try to do your rotations but in inverse order:
glRotatef( figura->gamma() , 0.0 , 0.0 , 1.0 );
glRotatef( figura->beta() , 0.0 , 1.0 , 0.0 );
GlRotatef( figura->alfa() , 1.0 , 0.0 , 0.0 );

I think it’ll work properlly now

Thanks all of you. Its been very useful for me. Zadkiel, i had read something about the inverse order but i didnt understand it. Now its clear and it works so it was the trick about transformations under OpenGL.

Qhy the hell everything is upside down in OpenGL. Was it written by english people? (I said that because they drive the wrong side) :-). Thats only a joke.

Thanks again…
check out eulars are evil

actually everyone used to driver/ride on the lefthand side of the road , until napoleon decree it to be the oppposite

Everyday you learn something. THANKS TO NAPOLEON :slight_smile:

Thanks to you too.


Hey JrbCast, where are u from?


Originally posted by mathx:

Hey JrbCast, where are u from?


Im from Spain. I Supouse you asked about it because my awful english, did you?.


Not really, I asked because of the names of the variables, I thought you`d maybe be from Brazil.