Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

enter image description here

I am trying to do animation using glut. I have 2 squares overlapping to each other and i want other square to rotate around this central object without rotating themselves. I want to rotate in orbit manner. I am calculating circular path using parametric equation and translating that one of the square to that distance. i am calling this function in a loop.

Here is my code in which the motion of other square is not in a orbit instead it moves along a diagonal of middle one. Let me know where it is going wrong. I have added expected image as well

share|improve this question
What exactly is not working as expected? – Adrian Maire Sep 3 '13 at 7:27
@AdrianMaire the motion of other square is not in a orbit instead it moves along a diagonal of middle one. – user1737197 Sep 3 '13 at 8:05
up vote 4 down vote accepted

First some little tips:

1) Instead of:

if (i > 360) i=0;


i %= 360;

2) glPushMatrix and glPopMatrix are useless in your code, as you apply them on the identity matrix.


4) Avoid global variables, they cause a lot of problems.


Probably a typo:


glTranslatef(distance_x, distance_x, 0.0);


glTranslatef(distance_x, distance_y, 0.0);
share|improve this answer
how can i achieve the same effect with glRotatef() without using above manipulation? – user1737197 Sep 4 '13 at 21:05
You may use 3 manipulation: glRotatef(i, 0.0f, 0.0f , 1.0f); glTranslatef(0.3f, 0.0f, 0.0f); glRotatef(-i, 0.0f, 0.0f, 1.0f); – Adrian Maire Sep 5 '13 at 8:08

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.