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);
glLoadIdentity();
glTranslatef(.7,.7,.7);
glColor3f(1.0,1.0,1.0);
glutSolidSphere(0.2,50,50);//Sun
glLoadIdentity();
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();
}