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 8 of 8

Thread: Translate after rotate

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    10

    Translate after rotate

    I am trying to translate an object in world space after rotating it at the origin. The problem is, after I rotate an object while it's at the origin, its local coordinate system rotates as well, so its axes are not parallel with the world coordinate axes anymore. So, for example, if I needed to translate an object to the point (3, 0, 5) after rotating the object around the y-axis, I would not be able to do this since the object's local coordinate system isn't the same as the world coordinate system. For example:

    Code :
    glRotatef(45, 0.0, 1.0, 0.0);
    glTranslatef(3.0, 0.0, 5.0);
    glutSolidCube(1);               // This won't be at (3,0,5) like how I need it

    How can I overcome this?

  2. #2
    Intern Newbie
    Join Date
    Nov 2002
    Posts
    39
    Try:
    glTranslatef(3.0, 0.0, 5.0);
    glRotatef(45, 0.0, 1.0, 0.0);

    Instructions are executed in reverse order.

  3. #3
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,159
    Or even better, read Ch3 of the Red Book.
    Instructions are not executed in reverse order! They are executed in the order they are issued.
    If you "think in local coordinate system", commands actually move local coordinate system, and all transformations are done in local coordinate system.
    If you "think in global coordinate system", object are moved in that system as the transformations are done in global system, but in the reverse order.
    Of course, OpenGL Programming Guide would explain everything much better.

  4. #4
    Intern Contributor
    Join Date
    Oct 2011
    Posts
    52
    Is this what you are trying to do?:

    pushMatrix()
    loadIdentity()

    for(every object){

    pushMatrix()
    translate()
    rotate()

    drawObject()

    popMatrix()
    }

    popMatrix()

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    10
    Thanks guys, that cleared things up for me
    And thanks for the link, I didn't even know the red book was online!

  6. #6
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    456
    It's a very old version that's online (version 1.1). Recent editions of the red book (is it now orange?) include more of the up to date stuff, with the most recent version covering OpenGL 4.3 AFAIK.

  7. #7
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,159
    Nope! The latest is OpenGL Programming Guide: The Official Guide to Learning OpenGL, Versions 3.0 and 3.1 (7th Edition).
    The greatest part of the book is about legacy OpenGL. Shaders are just mentioned and without a context (not GL context, but how to use).

  8. #8
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    456
    Ah yeah, it says "This title has not yet been released"/"Publication Date: 7 Feb 2013" on Amazon for the 8th edition.

Posting Permissions

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