//********************************************************************y // simple planetary system: // a spinning yellow moon orbiting around a red sun // Demonstrates: // modelling and transformations use, animation, use of double buffering, // depth buffer use, // and idle callback // Modified from the Red Book example // GK. 10/9/2003 //******************************************************************** #include #include #include #include // *********** Global declarations and named constants **************** #define RADMOON 0.3 #define RADSUN 1.0 #define RADORBIT 3.0 static int day, //rotation angle fro moon spin year; //rotatoon angle for mmon orbiting around the sun // ********* Prototypes ************************************************ void myinit(); void display(); void idle(); // **************************************************************************** void myinit() { // we will make a transparent polyhedra, so we will use the alpha value for blending glClearColor(0.0, 0.0, 0.0,0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2.25*RADORBIT,2.25*RADORBIT,-2.25*RADORBIT,2.25*RADORBIT, -2.25*RADORBIT,2.25*RADORBIT); glMatrixMode(GL_MODELVIEW); glEnable(GL_DEPTH_TEST); // use Z-buffering } //**************************************************************************** // updates rotating angles void idle() { day = (day+5)%360; year=(year+1)%360; glutPostRedisplay(); } // **************************************************************************** void display() { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(75, 1, 0, 0); // change view glColor3f(1.0, 0.0, 0.0); glutWireSphere(RADSUN, 20, 16); // draw sun //instantiate moon in orbit glRotatef( year, 0, 0, 1); glTranslatef(RADORBIT, 0, 0); glRotatef(day, 0,0,1); glColor3f(1.0, 1.0, 0.0); glutWireSphere(RADMOON, 10, 8); // draw moon glPopMatrix(); glutSwapBuffers(); } // ********* main()************** int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutCreateWindow("Solar System"); glutDisplayFunc(display); glutIdleFunc(idle); myinit(); glutMainLoop(); return 0; }