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: a problem about ROTATION, thanks.

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2002
    Location
    China
    Posts
    9

    a problem about ROTATION, thanks.

    I want image rotation controled by hand.
    For example if i press left key then image rotate horizontally,
    I want to control the image in 6 direction(left ,right ,up ,down ,outside and inside according to the screen).
    At first I use glRotatef(X.XX,1.0,0.0,0.0);glRotatef(X.XX,0.0,1.0 ,0.0);glRotatef(X.XX,0.0,0.0,1.0);
    But it can't rotate according to screen, later rotate axis was affected by the former rotation.if have a example code will be the best.

    thanks a lot, help me please.
    my e-mail: arjie_yes@hotmail.com

  2. #2

    Re: a problem about ROTATION, thanks.

    If I understand right you only want the rotation to work once for each axis at a time...

    EG... Pressing UP/DOWN will only rotate the object on the y axis and leaves the x and z axis alone... similar for LEFT/RIGHT for x and +/- for z

    If so then I would suggest that you use 3 live variables xRot,yRot and zRot and 3 stored variables oldx,oldy,oldz and do something like the following:

    Scene
    FirstPartOfScene();
    glPushMatrix();
    glRotatef(xRot,1,0,0);
    glRotatef(yRot,0,1,0);
    glRotatef(zRot,0,0,1);
    DrawObject();
    glPopMatrix();
    RestOfScene();

    Keys
    if (key == UP) yRot++;
    if (key == DN) yRot--;
    if (key == LT) xRot++;
    if (key == RT) xRot--;
    if (key == '+') zRot++;
    if (key == '-') zRot--;

    Something like this would keep the history of the rotation angles but would only rotate the angles on the next scene draw if the appropriate button was drawn otherwise the last angle used when be kept and thus no rotation.

    Theoretically anyway... I did a quick test with one of my programs and this theory worked... just remember the Pop and Push Matrix to make sure that the object rotates on its own axis.

    Hope this helps somewhat..

    Tina
    Learning OpenGL while working on sourceforge projects:
    https://sourceforge.net/projects/simulant/ and
    https://sourceforge.net/projects/projectnova/

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2002
    Location
    China
    Posts
    9

    Re: a problem about ROTATION, thanks.

    thanks for tina.
    I do as your think at first,but I need continuesly change the rotation angle.And later I use glMultMatrixf(float &a);It can rotate at each own asix.But It can't rotate according to the screen(in another word, rotate in a fixed coordinate, image rotate the rotate asix didn't rotate).

Posting Permissions

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