I have a rotating object rotating about 0,0,0. I now want another object to rotate about the other object. so kind of like the earth rotating around the sun and then the moon rotating around the earth.
I am not sure how to go about this.
void earth(){
glPushMatrix();
glRotatef(anglee, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0,20,0);
glutSolidSphere(0.8,50,50);
glPopMatrix();
glPushMatrix();
glRotatef(anglee, 0.0f, 0.0f, 0.0f);
glTranslatef(0.0,20.0,8);
glutSolidSphere(0.4,50,50);
glPopMatrix();
anglee+=4.0f;
}
I have got the first rotation correct, but i am not sure how to go about the second rotation.
Here’s a hint.. do this in your display callback function:
Try commenting some lines from both the draw planet and moon parts and see the difference, will help you understand it.
Hope this helps!