Jump to content

  • Log In with Google      Sign In   
  • Create Account


rotating objects in a double orbit


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 rgc183   Members   -  Reputation: 152

Like
0Likes
Like

Posted 10 September 2013 - 06:02 PM

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.

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

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

Attached Thumbnails

  • image1.png


Sponsor:

#2 Maple Wan   Members   -  Reputation: 214

Like
2Likes
Like

Posted 10 September 2013 - 07:26 PM

Well, you should know the concepts of relative coordinate system and world coordinate system. Your triangles should save your relative point list and the center point. Then update the relative point list when rotate for some radius and redraw it. Give some simple code:

#define PI 3.1415926535

typedef struct 
{
    double x, y;
} POINT, *LPPOINT;
typedef class Triangle
{
private:
    POINT pointList[3];
    POINT centerPoint;
public:
    Triangle() { };  // Constructor
    ~Triangle() { };  // Destructor
    BOOL Draw();    // Realize your Draw method
    BOOL Rotate(double theta);    // Rotate method
} TRIANGLE, *LPTRIANGLE;

BOOL TRIANGLE::Rotate(double theta)
{
    double cosVal, sinVal;
    for (int i = 0; i < 3; i++)
    {
        cosVal = cos(theta * PI / 180);
        sinVal = sin(theta * PI / 180);
        // Compute the relative coordinate after rotate
        this->pointList[i].x = this->pointList[i].x * cosVal - this->pointList[i].y * sinVal;
        this->pointList[i].y = this->pointList[i].x * sinVal + this->pointList[i].y * cosVal;
    }
    return this->Draw();

BOOL TRIANGLE::Draw()
{
    // In your draw method, you should change your relative coordinate to world coordinate.
}

Do my best to improve myself, to learn more and more...





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS