Hi, I'm wanting to rotate a gluSphere around a fixed point in a circular motion, like a planet going around the sun.
Would it be best to use glRotatef or glTranslate?
Cheers!
From stackoverflow
-
glRotatef will multiply the current matrix by a rotation matrix. This can (given the right vector) do what you are attempting.
glTranslatef will multiply the current matrix by a translation matrix, which would effectively "move" the object, not rotate it, so it will not be what you want.
: So for a circular motion what glRotatef should I use to rotate around a set point?Tartley : I think it's true to say that he needs one of each - translate the object away from the origin, and then rotate about the origin. (where 'origin' is the center that you want to rotate around) -
Translate away from the center and then rotate all the way
-
You'll have to do a little of both:
- Make sure the sphere is "facing" the fixed point, so that translating forward with respect to the sphere puts you closer to the center of its orbit
- glTranslatef the gluSphere forward to the point around which you want it to rotate
- glRotatef the direction you want the sphere to orbit
- glTranslatef backwards just as far as you went forward
That way, your sphere stays the same distance from the center, but gets translated "around" in a nice orbit.
: Cheers, spot on!
0 comments:
Post a Comment