Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Animation with glut

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    204

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

    Click image for larger version. 

Name:	sample.jpg 
Views:	162 
Size:	5.8 KB 
ID:	1143
    Last edited by debonair; 09-02-2013 at 02:35 PM.

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    Quote Originally Posted by debonair View Post
    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. #3
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    204
    Quote Originally Posted by GClements View Post
    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. #4
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    204
    Guys help me out please..

  5. #5
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    Here is my code which is not working as per expected.
    In what way is it "not working as per expected"?

  6. #6
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    204
    Quote Originally Posted by Alfonse Reinheart View Post
    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. #7
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    So it moves in a diagonal. Almost as if you passed the same value for the X and Y components of the position...

  8. #8
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    204
    Quote Originally Posted by Alfonse Reinheart View Post
    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. #9
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    175
    Code :
    // glTranslatef (distance_x, distance_x, 0.0);  
       glTranslatef (distance_x, distance_y, 0.0);

  10. #10
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    204
    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
  •