Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: rotating objects in a double orbit

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

    rotating objects in a double orbit

    I have a object at the center. Other set of objects rotating around center in first orbit. Now i want other objects to rotate around the objects in 1st orbit.

    n the above fig, set of triangles are rotating around the square and circles are rotating around the triangle. I have the code which works for 1st orbit, but i am not able to render that second orbit.
    Code :
     
    void display()
    {
    for (int k = 0; k < 10; k++)
    {
     
    distance_x = 0.4 * cos(angle1*3.14 / 180);
    distance_y = 0.4 * sin(angle1*3.14 / 180);
    angle1 += 60;
    glPushMatrix();
    glRotatef(i, 0.0f, 0.0f, 1.0f);
    glTranslatef(distance_x, distance_y, 0.0f);
    glRotatef(-i, 0.0f, 0.0f, 1.0f);
     
    DrawTriangle();
    glPopMatrix();
    }
    }

    Click image for larger version. 

Name:	image1.jpg 
Views:	49 
Size:	4.9 KB 
ID:	1150
    I am calling display in loop. i is static global variable. which transformations will do the second orbit?

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    Quote Originally Posted by debonair View Post
    I have a object at the center. Other set of objects rotating around center in first orbit. Now i want other objects to rotate around the objects in 1st orbit.
    Code :
    drawSun();
    glPushMatrix();
    glRotatef(planet_angle, 0, 0, 1);
    glTranslatef(planet_distance, 0, 0);
    drawPlanet();
    glPushMatrix();
    glRotatef(moon1_angle, 0, 0, 1);
    glTranslatef(moon1_distance, 0, 0);
    drawMoon1();
    glPopMatrix();
    glPushMatrix();
    glRotatef(moon2_angle, 0, 0, 1);
    glTranslatef(moon2_distance, 0, 0);
    drawMoon2();
    glPopMatrix();
    glPopMatrix();
    Note that the angles will accumulate, i.e. the moon angles are relative to the line from the sun to the planet. If necessary, you can subtract the previous angle (or add a counter-rotation) to maintain a consistent base direction.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    Thanks a lot..

Posting Permissions

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