Results 1 to 3 of 3

Thread: rotating objects in a double orbit

  1. #1
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    318

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

    image1.jpg
    I am calling display in loop. i is static global variable. which transformations will do the second orbit?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,104
    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
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    318
    Thanks a lot..

Similar Threads

  1. Using Shader Buffer Objects with Double or Triple Buffering
    By saski in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 07-08-2017, 01:31 PM
  2. Rotating several objects
    By d_ash77 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-11-2017, 11:53 AM
  3. Rotating Objects - Light Rotating not expected
    By SparkyNZ in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 08-12-2015, 07:52 PM
  4. Rotating one of a set of double doors 90 degrees
    By PyroMessiah86 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-02-2011, 03:21 PM
  5. rotating objects
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-01-2001, 07:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean