0
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\begingroup\$ What exactly is not working as expected? \$\endgroup\$ Commented Sep 3, 2013 at 7:27
  • \$\begingroup\$ @AdrianMaire the motion of other square is not in a orbit instead it moves along a diagonal of middle one. \$\endgroup\$ Commented Sep 3, 2013 at 8:05

1 Answer 1

4
\$\begingroup\$

First some little tips:

1) Instead of:

if (i > 360) i=0;

Try

i %= 360;

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

3) User GL_TRIANGLES or GL_QUADS instead of GL_POLYGON

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

Solution:

Probably a typo:

Change

glTranslatef(distance_x, distance_x, 0.0);

To

glTranslatef(distance_x, distance_y, 0.0);
\$\endgroup\$
2
  • \$\begingroup\$ how can i achieve the same effect with glRotatef() without using above manipulation? \$\endgroup\$ Commented Sep 4, 2013 at 21:05
  • 1
    \$\begingroup\$ 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); \$\endgroup\$ Commented Sep 5, 2013 at 8:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .