Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


rgc183

Member Since 12 Dec 2012
Offline Last Active Oct 05 2014 11:23 PM

#5091215 Animation with glut

Posted by rgc183 on 02 September 2013 - 11:59 PM

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

 

 
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);
glLoadIdentity();
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();
 
}

 

 

Attached Thumbnails

  • sample.png



PARTNERS