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 4 123 ... LastLast
Results 1 to 10 of 34

Thread: glRotate Question.

  1. #1
    Intern Contributor
    Join Date
    Aug 2002
    Posts
    95

    glRotate Question.

    Ok, if i have a model that has a center of 0,0,0 and I want to rotate it 30 degrees around that center on the Y, I would do this

    glRotatef(30, 0,1,0);

    but if i move the object over to where the center is 0,4,0, and i STILL wanted to rotate around its center. What would i call to rotate it? The same glRotate as above??

    I am currently moving my objects around the scene (tracking them, not PHYSICALY moving them). But i am physicaly moving there bounding sphere, so i always know where the center of the object is. Would i use that center as my rotation axis? Or would I use the original center as my rotation axis??

    Or should I simply Rotate on the Original Center as my axis, and then translate??

  2. #2
    Intern Newbie
    Join Date
    Aug 2002
    Posts
    42

    Re: glRotate Question.

    OH MY GOD! From reading the previous thread you started, I don't think I even want to touch this one with you.

    Find a good book like the OpenGL programmer's guide. It has a good chapter explaining how transformations work. Something that you obviously don't understand very well.

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    654

    Re: glRotate Question.

    glPushMatrix()
    glTranslatef(0.0, 4.0, 0.0)
    glRotatef(30.0, 0.0, 1.0, 0.0)
    glPopMatrix()

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,755

    Re: glRotate Question.

    It's all about order of operations. For instance...

    glTranslate();
    glRotate();

    Gives different results than

    glRotate();
    glTranslate();

    Because of the way matrix math is applied in OpenGL, you can think of it as though the last transformation function called is the first one actually executed on your object.

    So... in the first case above, your object is rotated around it's central axis (assuming it's central axis is the same as the global axis), then moved.

    The second example up there, the object is moved and then rotated around the global axis.

    Now... if you have an object who's center is not quite where you want it, you can do a combination of transformations where you move it to the center, rotate, then move it back. Say for instance you want to rotate the model around an x-axis at the top of it, and the 0,0,0 point of the model is 2 units below the top. You would do something like so..

    glTranslatef(0.0, 2.0, 0.0); //moves it back
    glRotatef(ang, 1.0, 0.0, 0.0); // does the rotation
    glTranslatef(0.0, -2.0, 0.0); // moves top of model to 0,0,0
    Deiussum
    Software Engineer and OpenGL enthusiast

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    654

    Re: glRotate Question.

    Doh! 'its centre'. Sorry

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

    Re: glRotate Question.

    Have you tried looking at any of the opengl tutor sites and the example programs?

    nehe.gamedev.net is a good place to learn.

    The best thing for you is to start with a simple program with one object on the screen, and play around making move around the screen.
    This will help you get the hand of how things move.

    You seem to think that the glRotate or Translate effect every scene created after it. but that is not the case with each new scene you start a zero again..

    example rotating cube:

    first render pass throuh display() routine

    glPushMatrix();
    glRotatef(cube_angle, 0, 1, 0); cube_angle = 15;
    Draw_cube();
    glPopMatrix();


    Next scene render pass through display()
    // we increase the angle
    cube_angle = cube_angle + 15;
    if (cube_angle > 360 ) cube_angle = 0; // check of angle going past 360.

    glPushMatrix();
    glRotatef(cube_angle, 0, 1, 0); cube_angle = 30;
    Draw_cube();
    glPopMatrix();

    and we repeat the above over and over, increasing the angle each pass to give us a rotating cube


    Originally posted by LostInTheWoods:
    Ok, if i have a model that has a center of 0,0,0 and I want to rotate it 30 degrees around that center on the Y, I would do this

    glRotatef(30, 0,1,0);

    but if i move the object over to where the center is 0,4,0, and i STILL wanted to rotate around its center. What would i call to rotate it? The same glRotate as above??

    I am currently moving my objects around the scene (tracking them, not PHYSICALY moving them). But i am physicaly moving there bounding sphere, so i always know where the center of the object is. Would i use that center as my rotation axis? Or would I use the original center as my rotation axis??

    Or should I simply Rotate on the Original Center as my axis, and then translate??

  7. #7
    Intern Contributor
    Join Date
    Aug 2002
    Posts
    95

    Re: glRotate Question.

    Ok, Tell me if this is correct. I have rotated my camera/world with a call to glRotate, and glTranslate for the players view.

    Now I have a box whos actual physical center is at 0,10,0 And i want to rotate that box around its center for 30 degrees about the x axis and then move it 4 more units in the y direction. I would do this.

    glPushMatrix(); //Save the current view
    glTranslatef(0,-10,0); //Set back to the origin.
    glRotatef(30, 1,0,0); //Rotate about its 'new' center, aka the origin
    glTranslatef(0,14,0); make up for the reverse move made earlier.
    Is this about right?

    Edit: i forgot the last call should be
    glPopMatrix(); // reset the matrix to the current view

    [This message has been edited by LostInTheWoods (edited 08-07-2002).]

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    654

    Re: glRotate Question.

    Try it! Now you have the general idea a bit of trial and error will do the world of good!

  9. #9
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,755

    Re: glRotate Question.

    As Gavin said, trial and error is a great thing.

    One thing, your translates may be backwards based on your example. Think of it as the last transformation being the first to affect your object.
    Deiussum
    Software Engineer and OpenGL enthusiast

  10. #10
    Junior Member Newbie
    Join Date
    Aug 2002
    Posts
    25

    Re: glRotate Question.

    I think it helps out a ton if you draw what you want to do on some paper. That way you'll see the effect of glRotate and glTranslate and stuff like that.

Posting Permissions

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