Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Transforming + Rotating an object without going weird?

  1. #11
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    12
    Im not understanding this. Whatever order or whatever i select, it just doesn't work. I know i'm probably being dumb.
    glTranslatef(-0, -0, -plus);
    glRotatef(rotate, 0.f, 1.f, 0.f);
    glTranslatef(0, 0, plus);

    Oh i saw your edit. But i still just don't get it. I want to be able to drive the ship around with the arrow keys, im not understanding your points business :S.
    Also i would like to be able to translate and rotate at the same time.

    Now trying glTranslatef(0, 0, plus);
    if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)){
    rotate++;
    }
    glTranslatef(0, 0, -plus);
    glRotatef(rotate, 0.f, 1.f, 0.f);
    glTranslatef(0, 0, plus);
    , it still isn't working. Even though the ship is at the centre it still rotate's around the ships spawn point when its translated back out.
    Last edited by joehot200; 12-19-2013 at 09:13 AM.

  2. #12
    Intern Newbie
    Join Date
    Mar 2013
    Posts
    42
    As i can see here, you are still using fixed function matrix pipeline of OpenGL. Did you set the matrix mode to MODELVIEW?`
    Code :
    glMatrixMode(GL_MODELVIEW);

    This may fix your problem.

  3. #13
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,143
    Well, let's try to finish this agony.
    Although you haven't got a linear algebra I hope you'll understand the following guidelines:

    1. The ship is probably drawn in the at coordinate-system's origin (the center of the ship is at (0,0,0)). If not, translate it to the origin.

    2. The transformations can be thought of using global or local coordinate-system. If you "think" in global coordinate-system, transformations are executed in opposite order considering the way they appear in the code.
    For example, consider the following sequence:

    glTranslatef(x,0,0);
    glRotatef(a,0,0,1);
    glTranslatef(0,y,0);
    DrawObject();

    The object is first translated down the Y-axis, then rotated around the Z-axis of the global coordinate-system, then translated along X-axis of the global coordinate-system.

    But if you "think" in local coordinate-system, then transformations are done in the exact order they appear in the code. So, local coordinate-system is translated along its (local) X-axis, then rotated around its (local) Y-axis, and finally translated along its (local) Y-axis. After all those transformations of the local coordinate-system the object is drawn using it. The result is the same. These are just two ways of thinking. The first moves object along global axes, while the second moves local coordinate-system along local axes.

    In your case, probably the following will do the trick:

    glTranslatef(x,0,z);
    glRotatef(a,0,1,0);

    a - azimuth of the ship, (x,0,z) - position of the ship

    Both x and z coordinates must be calculated according to previous position and azimuth.

Posting Permissions

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