Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a object at the center. Other set of objects rotating around center in first orbit. Now i want other objects to rotate around the objects in 1st orbit. enter image description here

In the above fig, set of triangles are rotating around the square and circles are rotating around the triangle. I have the code which works for 1st orbit, but i am not able to render that second orbit.

I am calling display in loop. i is static global variable. which transformations will do the second orbit?

share|improve this question
up vote 3 down vote accepted

You can do it by inserting another "push, transform, draw, pop" sequence before your pop. Something like this:

// your current code

    // new code


The idea is that since the operations for the circle are done before the triangle's transform is popped, all the triangle's transforms will apply to the circle as well. For instance, the translation to set the circle's position will be relative to the triangle's position.

BTW, your code is a bit odd in that you're applying two separate rotations to the translation vector. You're calculating the translation vector using cos and sin, so the vector will already be rotated by angle1. Then, since you're doing a glRotate before your glTranslate, the translation vector will be rotated again by i. You could simplify this by just rotating by angle1 + i from the beginning, and removing all the glRotate calls. (Since you're undoing the rotation by i before you draw, none of the rotations are applying to your actual models.)

share|improve this answer
why do we need push matrix again in the second phase ? – user1737197 Sep 11 '13 at 4:25
@Roshan If you just have one circle to draw, you could get rid of the inner push and pop. But if, say, you wanted to draw multiple circles relative to the same triangle, you would need a push/pop around each circle to restore the triangle's transform after each circle. – Nathan Reed Sep 11 '13 at 5:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.