Results 1 to 8 of 8

Thread: Weird thing with glRotatef()

  1. #1
    Senior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Poland
    Posts
    196

    Weird thing with glRotatef()

    Hi,

    I've got this piece code:

    Code :
    glTranslatef( -0.5f, 0, -0.5f );
    glRotatef( yRot, 0, 1, 0 );
    glTranslatef( -0.5f, 0, -0.5f );
    and that:

    Code :
    glTranslatef( 0.5f, 0, 0.5f );
    glRotatef( yRot, 0, 1, 0 );
    glTranslatef( -0.5f, 0, -0.5f );
    Those pieces contains rotating two objects aroud their own axises, one object is translated with XZ -0.5f, -0.5f and the second is 0.5f, 0.5f. Everything works fine, but after rotation I always translate them in negative direction with -0.5f, -0.5f. But why? First object is located in different place than the second after first translation ???



    [This message has been edited by glYaro (edited 07-29-2003).]

  2. #2
    Senior Member Regular Contributor
    Join Date
    Feb 2003
    Location
    Westerville, Oh, USA
    Posts
    201

    Re: Weird thing with glRotatef()

    Are you asking why glTranslatef(-0.5, 0.0, -0.5); glRotatef(yRot, 0, 1, 0); puts the object in a different place than glTranslatef(0.5, 0.0, 0.5); glRotatef(yRot, 0, 1, 0);??

    What your code is doing in both instances is translating first and then rotating about the global origin. If you want the object to be rotated and then end up at (0.5, 0.0, 0.5), do the rotation first, then the translation.

    Sorry if I didn't understand your question.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Poland
    Posts
    196

    Re: Weird thing with glRotatef()

    My question contains this that the second translation in both two codes translates object with negative direction. I want to rotate an object around his own axis, and those codes work. But shouldn't it be that (the second code):
    Code :
    glTranslatef( -1, 0, -1 ); // translate in negative direction
    glRotatef( yRot, 0, 1, 0 );
    glTranslatef( 1, 0, 1 ); // translate in positive direction
    Above code doesn't work. In order to make it work OK ( rotate around -1, -1 axis ) I have to change the second call of glTranslatef with negative direction, why? It is not logical, If I won't use glRotatef so the code:
    Code :
    glTranslatef( -1, 0, -1 );
    //glRotatef( yRot, 0, 1, 0 );
    glTransletef( -1, 0, -1 );
    will twice a time translate the object with XZ -1, -1 and the object position will be -2, -2. So object should not return to its position after rotation.

    [This message has been edited by glYaro (edited 07-30-2003).]

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    23

    Re: Weird thing with glRotatef()

    Well, let me see if i understand...

    You are trying to translate an object, rotate that object, then move back to the origin and do the same for another object. Well, the only thing i can see that might be wrong is that you are not "unrotating" after you rotate the object, you are simply translating back. You might wanna try a line like glRotatef(-yrot,0.0f,1.0f,0.0f). If this isnt the issue, im not sure i understand.

  5. #5
    Senior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Poland
    Posts
    196

    Re: Weird thing with glRotatef()

    OK, let's say we've got two objects:
    1. A cube with origin vertex in (5, 0, 5)
    2. A buce with origin veretx in (-5, 0, -5)

    I want to rotate it around its origin vertex Y axis: (5, 0, 5) and the second (-5, 0, -5) with glRotatef(0, 1, 0).

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Weird thing with glRotatef()

    Don't hold me to this I am doing in my head..

    should look like this if I undstand the question correctly.

    glRotate( A, 0, 1, 0);
    glPushMatrix()
    glTranslatef( -5, 0, -5);
    draw_cube();
    glPopMatrix();

    glPushMatrix();
    glTranslatef(5, 0, 5);
    draw_buce();
    glPopMatrix();





    Originally posted by glYaro:
    OK, let's say we've got two objects:
    1. A cube with origin vertex in (5, 0, 5)
    2. A buce with origin veretx in (-5, 0, -5)

    I want to rotate it around its origin vertex Y axis: (5, 0, 5) and the second (-5, 0, -5) with glRotatef(0, 1, 0).

  7. #7
    Senior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Poland
    Posts
    196

    Re: Weird thing with glRotatef()

    Thanks. I forgot about tricks with matrix stack

  8. #8
    Junior Member Newbie
    Join Date
    Jul 2003
    Location
    Belgrade, Serbia, Serbia & Montenegro
    Posts
    3

    Re: Weird thing with glRotatef()

    Just for the sake of clearing thigs up, the problem created without using glPushMatrix()-glPopMatrix() seems to be that when you rotate an object with glRotatef() and do not push the previous matrix onto the stack you do get what you want, but when trying to traslate back to the previous position your modelview matrix is now rotated around making the ipression that the negative values compared to your previous translation are not going backwards like they should. Think about what every matrix multiplication is doing to your modelview matrix or you'll find yourself in a virtual mirror house

    [This message has been edited by TheAnt (edited 07-31-2003).]

Similar Threads

  1. Replies: 6
    Last Post: 06-14-2007, 03:04 AM
  2. Replace two glRotatef() with one glRotatef()?
    By tgtt in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 02-24-2004, 02:33 PM
  3. Weird thing with WinXP
    By yaro_dup1 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-12-2003, 03:31 PM
  4. weird thing with glClearColor
    By bumby in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 06-04-2003, 07:46 AM
  5. Weird thing with DescribePixelFormat
    By Zocleus in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 09-15-2000, 10:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean