# The Industry's Foundation for High Performance Graphics

1. ## Animation with glut

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 which is not working as per expected. Let me know where it is going wrong.
I have added expected image as well
Code :
```
void DrawShapes()
{
static float angle = 0;

glClear(GL_COLOR_BUFFER_BIT);

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glColor3f(0.0f, 0.3f, 0.2f);

glBegin(GL_POLYGON);
glVertex2f(-0.2, -0.2);
glVertex2f(0.2, -0.2);
glVertex2f(0.2, 0.2);
glVertex2f(-0.2, 0.2);
glEnd();

static int i = 0;
distance_x = 0.3 * cos(i*3.14 / 180);
distance_y = 0.3*   sin(i*3.14 / 180);
i++;
if (i > 360)
i = 0;

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(distance_x, distance_x, 0.0);
glBegin(GL_POLYGON);
glVertex2f(-0.2, -0.2);
glVertex2f(0.2, -0.2);
glVertex2f(0.2, 0.2);
glVertex2f(-0.2, 0.2);
glEnd();

glPopMatrix();
glutSwapBuffers();

}```

2. Originally Posted by debonair
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
Your display function should render one frame then return. If you want animation, register a timer function which calls glutPostRedisplay().

3. Originally Posted by GClements
Your display function should render one frame then return. If you want animation, register a timer function which calls glutPostRedisplay().
problem i am facing is not about the frames, i am able to get the animation, only thing is that the output is not as per expected.

4. Guys help me out please..

5. Here is my code which is not working as per expected.
In what way is it "not working as per expected"?

6. Originally Posted by Alfonse Reinheart
In what way is it "not working as per expected"?
the motion of other square is not in a orbit instead it moves along a diagonal of middle one.

7. So it moves in a diagonal. Almost as if you passed the same value for the X and Y components of the position...

8. Originally Posted by Alfonse Reinheart
So it moves in a diagonal. Almost as if you passed the same value for the X and Y components of the position...
I dont know how did i write same parameters for both axes .. Thanks a lot.

9. Code :
```// glTranslatef (distance_x, distance_x, 0.0);
glTranslatef (distance_x, distance_y, 0.0);```

10. how can i achieve the same effect with glRotatef() without using above manipulation?

#### Posting Permissions

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