Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: rotation point

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2003
    Posts
    26

    rotation point

    How can I move my rotation point?
    Normaly I rotate around point(0,0,0)
    That's correct. When I want to change the
    rotation point I first do glrotate and then gltranstate to the rotation point but then my object jumps to the rotation point.
    I hope I explain this understandable.
    Can anybody help me?

  2. #2
    Guest

    Re: rotation point

    I would suggest you flip the order of your command bearing in mind that opengl works in reverse. So if you want to achieve a rotation about a non zero point then the sequence of commands need to be

    glrotate ....
    gltranslate ...
    rendering commands etc.

    At the moment I am assuming that you have the command sequence the other way round

  3. #3
    Senior Member Regular Contributor
    Join Date
    Apr 2003
    Location
    Toulouse, France
    Posts
    133

    Re: rotation point

    to rotate around a point, using glTranslate and glRotate function, you have to:

    C is the camera/object position
    P is the point

    compute the vector CP in local coordinates (camera/object)
    translate using this vector
    apply rotation
    translate using -CP

  4. #4
    Guest

    Re: rotation point

    Oops, the sequence should be

    gltranslate back to where it was
    glrotate
    gltranslate rotation point to zero

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2003
    Posts
    26

    Re: rotation point

    I supposed with the following code it would work,
    Z = the Z-value of the rotation

    When I change the Z-value with my object in a certain angle
    the rotation point is correct but my object jumps on the screen in Z-direction to the rotation point!

    glTranslatef 0, 0, -Z
    glRotatef xAngle, 0.5, 0, 0
    glRotatef yAngle, 0, 0.5, 0
    glRotatef zAngle, 0, 0, 0.5
    glTranslatef 0, 0, Z
    glScalef schaal, schaal, schaal

  6. #6
    Junior Member Newbie
    Join Date
    Feb 2003
    Posts
    26

    Re: rotation point

    If you do a translation, a rotation and then a new Translation without drawing anything between, isn't that the same as do the sum of the two translations in one translation and then rotate???

  7. #7
    Member Contributor
    Join Date
    Jul 2002
    Location
    Southampton, PA, USA
    Posts
    61

    Re: rotation point

    No. The sum of the two translations would be zero, anyway. You are moving away from the origin so that you can simulate a rotation about an arbitrary point, then moving the object back to its original location.

  8. #8
    Junior Member Newbie
    Join Date
    Feb 2003
    Posts
    26

    Re: rotation point

    OK, but what's the real solution to my problem?? I want to transfer, rotate and then change the rotation point, rotate again and so on without my object jumps when I change the rotation point!

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

    Re: rotation point

    Here is something that confuses people about rotation/translation, in openGL the last rotation/translation is acted on first.

    example:

    #1
    glRotate
    glTranslate

    is not the same as

    #2
    glTranslate
    glRotate

    The first example we translate then rotate, which means the object is translated first from it's origin then rotated. Note we always rotate around the worlds origin, but now the objects origin is no longer 0,0.
    Example would be if you placed a string on the object with one end of the string tied to 0,0,0 and the other to the object moved out some distance from the origin. Then move the object along the path created by the string in a circular motion.

    The second example we rotate first then translate the object. So now we have rotated the ball around it's origin(0,0,0) and then moved it out to some point.


    Let say we have a Cude and it's origin is at one corner, we need to have it at the cubes center.

    Our cude is 4 unit's in size, so the center will be at 2 units. We difine our cube as one near lower corner is 0,0,0 and the far upper corner is 4,4,4.

    glRotate( 15, 0, 1, 0);
    glTranslate(-2,-2,-2); Move cude so origin is now at center
    DrawCube( 4 );

    What we have done is moved the cude so that is center is now located 0,0,0 of our world coords. Since all rotations are done around the worlds origin, the cube is now rotated around its center.

    Now if you are doing this and it does not look correct them maybe you should post some of your code so we can see what you are doing.

    Hope this helps.

    Originally posted by fobru:
    OK, but what's the real solution to my problem?? I want to transfer, rotate and then change the rotation point, rotate again and so on without my object jumps when I change the rotation point!

  10. #10
    Junior Member Newbie
    Join Date
    Feb 2003
    Posts
    26

    Re: rotation point

    A last, maybe stupid question, then I gone sleep over it!
    Are the values of gltranslate and glrotate always absolute to the world center(0,0,0)
    or relative to the last position of the object in the world??

Page 1 of 2 12 LastLast

Similar Threads

  1. viewpoint and rotation point
    By vbovio in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 04-13-2007, 10:47 AM
  2. Rotation around a point in 3d
    By infinitecmdz in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 11-09-2005, 12:04 AM
  3. Rotation for point sprites
    By Escondida in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 07-02-2003, 10:20 AM
  4. point vector rotation
    By mphanke in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 03-27-2002, 12:20 PM
  5. rotation at the specified pivot point
    By GT5 in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 05-16-2001, 11:00 PM

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