cube rotating unexpectedly in open gl es

Hi everyone ,im new to this forum :wink:
hey buddies i am facing diffculty in solving some issues related to cube transformations :sorrow:

Im trying to rotate a 3D cube on touch. the distance moved to left or right is taken as the angle of rotation with respect to Y axis and the distance moved to up or down is taken as the angle of rotation with respect to X axis .
So these are the rotations im making
glrotate(angleXdistance, 0, 1, 0); // with respect to Y axis
glrotate(angleYdistance, 1, 0, 0); // with respect to X axis

so every time i add the angles with previous angles lik angleXdiatance + = angleXdiatance; in touch event

so the problem im facing is :
1.) when i rotate to right or left for 90 degree it rotates corectly ,and after when i rotate to up or down it rotates with respect to Z axis instead of Y axis
2.)when i rotate to right or left for 180 degree it rotates corectly ,and after when i rotate to up it rotates
down , to say in it rotates in opposite direction .

i could analyse that after 90/180 degree roataions the default axes changes , so it will roatate with respect to current axes , so i tried to chk the condition if it crosses 90 thn instead of rotating with respect to X rotate with respect to Z , and after 180 , reverse the rotation angle sign … it works :smiley: but nt always :evil: … sm prblm occurs in sm other condition,

so i found out all posibilities , at certain angle of rotation , these are the current axes and thn passes those axes but still din work coz two rotations are happening so tht the number of possiblities increaes which is nt possible to find all conditions…

so if anyone has idea how to solve this issue plz help … my cube and my head rotating unexpectedly :shock: plz help to rotate them correctly :roll:
i could see many examples or applications with such problem there also …

all transformation are applied to the current matrix, so when you rotate you are rotating around the current local reference.

If you rotate around X by 90 deg the next transformation will find the axis swapped.

This append for every angle, (180, 45, 60, 34, 0.003) so compute a special case for every possible angle is not a good idea. :stuck_out_tongue:

If you want to rotate round the global axis you have to compute the global axis in the local reference system

The solution is in this thread (that you have already spotted):
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=280849#Post280849

Ya i saw that post which gave me good idea :slight_smile: , i tried but it don work for all posibilities …
if i rotate the other way first then same problem exists…
i tried to combine lik this :

GLfloat currentModelViewMatrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, currentModelViewMatrix);
glRotatef(xRotation, currentModelViewMatrix[1], currentModelViewMatrix[5], currentModelViewMatrix[9]);
glGetFloatv(GL_MODELVIEW_MATRIX, currentModelViewMatrix);
glRotatef(yRotation, currentModelViewMatrix[0], currentModelViewMatrix[4], currentModelViewMatrix[8]);

but it doesnt work …

so can you please tell exactly

and even i tried to calculate the rotation matrix manually
by usinf the rotation matric defifnitions ,.
given in
http://www.songho.ca/opengl/gl_anglestoaxes.html#anglestoaxes

but the values i found out are not in correct order they are mixed…

so could please help me by telling …
if
glrotate(angleA,1,0,0)
glrotate(angleB,0,1,0)
glrotate(angleC,0,0,1)
are 3 roatations thn wt is the order for composite matrix
Rx Ry Rz or Rz Ry Rx ?? coz i have ehard the rotation ouucr in reverse order …