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;

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 :)

BionicBytes

12-11-2011, 12:31 PM

Before you draw anything use glPushMatrix then you can use glTranslate and glRotatef. After the draw (glutSolidSphere) you then restore the modelview matrix. There are variations on this theme such as saving the modelview and the use glLoadMatrix instead.

ncikw

12-11-2011, 03:05 PM

Thanks so much for that I've now got all the inner planets. However I'm having trouble adding a second moon to mars. Because obviously glPushMatrix uses the Sun as a reference.