Hi,
I’ve decided to try and make a small program which simulates the solar system, purely to help me better understand openGL. At the moment I have made an Sun, Earth, Moon system however I cant think of how to make another planet that will orbit the Sun rather than the last model I drew (namely the moon). Part of code for display sun, earth, moon;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
GLfloat red[] = {1,0.2,0,1};
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
glutSolidSphere(1.0, 50, 50);
glRotatef((GLfloat) year, 0.0, 1.0, 0.0);
glTranslatef(7.0, 0.0, 0.0);
glRotatef((GLfloat) day, 0.0, 1.0, 0.0);
GLfloat blue[] = {0,0.2,1,1};
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue);
glutSolidSphere(0.2,40,30);
glRotatef((GLfloat) lunar, 0.0, 1.0, 0.0);
glTranslatef(0.5,0.0,0.0);
GLfloat grey[] = {0.7,0.7,0.8,1};
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, grey);
glutSolidSphere(0.05, 100, 30);
glPopMatrix();
glutSwapBuffers();
}
I tried to create a point at the center of the earth by translating the reverse of how i created the moon and the again to make a point at the center of the Sun . However this did not work.
Is there a function that can choose where you translate from? Or in other words how do I go about solving this?
Thank you