# Earth and sun - How to make the sun revolve around the earth in the following code?

I want to imitate the planetary system with Earth and Sun drawn as solid spheres on the same window. I have drawn the two: the earth as the bigger sphere and the sun as the smaller sphere.

Now I want the earth to revolve around the sun when I press key A and when I press key B the earth must rotate around its axes. How do I achieve this? Thanks.

Here is the code so far:

 #include <GL/glut.h>
void init(void){
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void display(void){
glClearColor(0.05,0.05,0.5,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.03,0.05,0.09);
glutSolidSphere(0.5,30,30);//Earth
glMatrixMode(GL_MODELVIEW);
glTranslatef(.7,.7,.7);
glColor3f(1.0,1.0,1.0);
glutSolidSphere(0.2,50,50);//Sun
glFlush();

}
int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowPosition(10,10);
glutInitWindowSize(400,400);
init();
glutCreateWindow("Planets");
glutDisplayFunc(display);

glFlush();
glutMainLoop();

}

• Please avoid using deprecated OpenGL! Check out this site for some modern OpenGL tutorials. – Soapy Nov 12 '15 at 16:05
• @Soapy, Hey there is no way I can avoid it because it is one required for my Computer Graphics course!!! I CANNOT oppose what the university says, right? It is not that I like to do deprecated things or something but its a requirement for the course I am doing!!! BTW, its no reason you should have down voted my question, if you don't know the question just leave it, others will answer!! – Nation Chirara Nov 12 '15 at 17:29
• @Glovanrich you could argue with it considering they're teaching outdated technology, maybe you can impress them with new OpenGL. Also I didn't give you a downvote. – Soapy Nov 12 '15 at 18:03
• The downvote says "This question does not show any research effort". Your question is considered "how to get started" as you have not shown how you tried to make your spheres spin, and you're basically asking us to write your assignment for you. – Vaillancourt Nov 12 '15 at 18:03
• @Soapy It is possible but I hate the "we are aware of that". – Nation Chirara Nov 16 '15 at 10:21