I want 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? If so, in which order should I call them?
To rotate around a different point, the formula: X = cx + (x-cx)*cosA - (y-cy)*sinA, Y = cy + (x-cx)*sinA + (y-cy)*cosA, cx, cy is centre coordinates, A is the angle of rotation. The OpenGL function is glRotatef (A, x, y, z). 3. Scaling: Scaling refers to zooming in and out an object on different scales across axes.
The glRotatef function computes a matrix that performs a counterclockwise rotation of angle degrees about the vector from the origin through the point (x, y, z). The current matrix (see glMatrixMode) is multiplied by this rotation matrix, with the product replacing the current matrix.
You'll have to do a little of both:
gluSphere
is "facing" the fixed point, so that translating forward with respect to the sphere puts you closer to the center of its orbitglTranslatef
the gluSphere
forward to the point around which you want it to rotateglRotatef
the direction you want the sphere to orbitglTranslatef
backwards just as far as you went forwardThat way, your sphere stays the same distance from the center, but gets translated "around" in a nice orbit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With