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 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: Simple transformation problem

  1. #1
    Intern Contributor
    Join Date
    Oct 2004
    Posts
    63

    Simple transformation problem

    Servus!

    I just started to use the OpenGL API.
    The problem I can't solve currently is about transformations.
    Yes, I know that it was discussed before, but these discussions in this forum couldn't really help me.

    I want to rotate around two axes.
    The problem is that my program rotates with the identity matrix when I call glRotatef.
    But I want to rotate using the current model view matrix.

    Thanks for your help!

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    586

    Re: Simple transformation problem

    Servus.

    Prior to any rotations (translations, scales, whatever) all you have is an identity matrix.

    rotate your object about the first axis, then rotate it about the second axis (um..and don't call glLoadIdentity()).

    could you post some code showing what you're doing?

  3. #3
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Simple transformation problem

    Not sure if it is your case but you can reverse the order of your rotations.
    It is a common problem due to matrix multiplications.
    And are you sure there is no glLoadIdentity where you don't need it ?

  4. #4
    Intern Contributor
    Join Date
    Oct 2004
    Posts
    63

    Re: Simple transformation problem

    The current modelview matrix is the transformed one before I make the glrotatef calls. I checked it with glGetFloatv.

    I call

    glRotatef((float)xangle , 1.0f, 0.0f, 0.0f);
    glRotatef((float)yangle , 0.0f, 1.0f, 0.0f);

    ...
    glPushMatrix()
    glTranslatef(...)
    drawStuff
    glPopMatrix()
    ...
    glPushMatrix()
    glTranslatef(...)
    drawStuff
    glPopMatrix()
    ...

    The result is that it's rotating around the (1,0,0) and (0,1,0) vector that belongs to the identity matrix, but not the current modelview matrix. But I want that the rotation transformation is using the current modelview matrix.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    586

    Re: Simple transformation problem

    Do you have any transformations going on before this ?:

    Code :
     
    glRotatef((float)xangle , 1.0f, 0.0f, 0.0f);
    glRotatef((float)yangle , 0.0f, 1.0f, 0.0f);
    If you don't, all you have is an identity modelview matrix and everything is happening exactly as it should. If you're saying that you're getting the modelview matrix *right before* those glRotatef calls and it's not coming up as the identity but your glRotatef calls are producing results as if it where, well then I'm at a total loss as that's sort of...well...impossible.

    Sorry, I'm a bit thick-headed and it's not so clear as to what you're trying to accomplish.

    EDIT: remember also that the results of one glRotatef call change your coordinate system.
    a rotate about the x axis by 90 degrees for example would effectively swap your y and z axes.
    is this the unexpected behavior you're seeing?

  6. #6
    Intern Contributor
    Join Date
    Oct 2004
    Posts
    63

    Re: Simple transformation problem

    This is what I am doing:

    Code :
    void RenderFrame(void)
    {
       glClear(...);
       glMatrixMode(GL_MODELVIEW);
     
       glGetFloatv(GL_MODELVIEW_MATRIX, Current_MV_Matrix);
     
       if(rotate_x)
       {
          glRotatef((float)Angle_x, 1.0f, 0.0f, 0.0f);
          Angle_x = 0;
          rotate_x = FALSE;
       }
       else
       {
          glRotatef((float)Angle_y, 0.0f, 1.0f, 0.0f);
          Angle_y = 0;
          rotate_x = TRUE;
       }
     
       glPushMatrix();
       glTranslatef(...);
       drawStuff;
       glPopMatrix();
     
       glPushMatrix();
       glTranslatef(...);
       drawStuff;
       glPopMatrix();
    }
    "Current_MV_Matrix" gives me the identity matrix for the first frame and in all other frames the transformed ones.

    The result is that I don't rotate around the (1,0,0) and (0,1,0) vectors of the translated modelview matrix like I wanted, but around the identity modelview matrix vectors.

    Please give me a note if you need more details.

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    586

    Re: Simple transformation problem

    where else are you setting Angle_x and Angle_y ?

    On the first frame you haven't done any transformations yet, so it makes sense that you have the identity modelview.

    after that, if you aren't setting Angle_x and/or Angle_y each frame outside of Display() you're rotating by 0 degrees each frame.

  8. #8
    Intern Contributor
    Join Date
    Oct 2004
    Posts
    63

    Re: Simple transformation problem

    These variables are global (just for testing) and are changed dynamically (by mouse-input).

  9. #9
    Intern Contributor
    Join Date
    Oct 2004
    Posts
    63

    Re: Simple transformation problem

    PLEASE HEEELLLP!
    It's driving me cracy. :-/

  10. #10
    Guest

    Re: Simple transformation problem

    There is no obvious error in the code that you provided, so it must be somewhere else in your code.

    You cast Angle_x/Angle_y to an float which makes me think they are probably integers. Maybe you are calculating them wrong? If you do something like:

    Code :
    int Angle_x = 12/11;
    The result will be 0 and hence there will be no rotation. Or perhaps rotate_x/rotate_y is always false...

    This is where the debugger comes in handy. Set breakpoints to your glRotate() calls and check what values you are passing to OpenGL.

Posting Permissions

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