Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: cube rotating unexpectedly in open gl es

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2010
    Location
    India
    Posts
    7

    cube rotating unexpectedly in open gl es

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

    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 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 ...
    Logic is my Magic !!

  2. #2
    Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008
    Location
    Italy
    Posts
    352

    Re: cube rotating unexpectedly in open gl es

    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. :P

    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_boa...849#Post280849
    ~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2010
    Location
    India
    Posts
    7

    Re: cube rotating unexpectedly in open gl es

    Ya i saw that post which gave me good idea , 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_angle...l#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 ..
    Logic is my Magic !!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •