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

Thread: Represent Rotate and Translate by one Translate

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2000
    Posts
    7

    Represent Rotate and Translate by one Translate

    Hi,
    I can get my desired result by

    --some transformations exist before next--
    glRotatef(angle, 0.f, 1.f, 0.f);
    glTranslatef(0.f, 0.f, 0.7f);
    DrawObject;

    Now, I want to represent shift of the origin point ((0,0,0,1)) of the above two transformations by one glTranslatef first in order to track the object position, and put glRotatef after that:

    --some transformations exist before next--
    glTranslatef(?, ?, ?);
    glRotatef(angle, 0.f, 1.f, 0.f);
    DrawObject;

    I tried the next, but did not work

    --some transformations exist before next--
    glTranslatef(0.7f*(float)sin(angle), 0.f, 0.7f*(float)cos(angle));
    glRotatef(angle, 0.f, 1.f, 0.f);
    DrawObject;

    What is the right expression in glTranslatef(?, ?, ?) ? Thank you in advance for any help.

    Luin

    [This message has been edited by Luin (edited 07-02-2000).]

  2. #2
    Intern Contributor
    Join Date
    Apr 2000
    Posts
    62

    Re: Represent Rotate and Translate by one Translate

    Well for one thing you need to convert your angle to radians before passing it to sin() cos().

    #define PI 3.141596
    float a = angle * (PI / 180);

    cos(a)

    or you can combine it ... cos(angle * (PI/180))
    Sean E. Dolan

  3. #3
    Guest

    Re: Represent Rotate and Translate by one Translate

    As someone said, you must use radians. Also, the way GL multiplies matricies, you should put the order of translation/rotation backwards; i e start at where you draw, and put each operation above the drawing, going upwards.

    Code :
    Shape:: DrawSelf() {
     glTranslatef(m_pos.x, m_pos.y, m_pos.z);
     glRotatef(m_angle/180., 0., 1., 0.);
     Render();
    }
    This will result in the thing being first rotated about its internal Y axis, and then positioned where you wish it. If you think about it, it makes sense, because you start
    by rotating the viewer and translating the world. You can use glPushMatrix() to great effect if you do recursive structures:

    Code :
    Shape:: Draw() {
     glPushMatrix();
     DrawSelf();
     glPopMatrix();
    }
    Of course, once you start performance tuning, you may wish to keep an aggregate translation matrix and just glLoadIdentity() and apply the (single) matrix for each item, instead. But save that for the optimization phase; no use confusing the issue while you're still getting your rendering up.

    PS: dontcha hateit when some perfectly innocent code turns into smiley faces just because the method name happens to start with a "D"?

    [This message has been edited by bgl (edited 07-02-2000).]

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2000
    Posts
    7

    Re: Represent Rotate and Translate by one Translate

    SED and bgl, thank you for pointing out “radians.” It works now!

    Matrix method suggestions seems helpful, too.

    Have a nice day!

    Luin

Posting Permissions

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