Skip to main content
deleted 858 characters in body
Source Link
user1737197
  • 205
  • 3
  • 11

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

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

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

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

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

edited title
Link
House
  • 73.5k
  • 17
  • 188
  • 276

Animation with glut not working properly How do I orbit one object around another?

added 66 characters in body
Source Link
user1737197
  • 205
  • 3
  • 11

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 working as per expectedin 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

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

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

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

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();
 
}
Source Link
user1737197
  • 205
  • 3
  • 11
Loading