#include <GL/gl.h> #include <GL/glu.h> #include "aux.h" #define GRAD 360 static int year = 0, day = 0; void dayAdd (void) { day = (day + 10) % GRAD; } void daySubtract (void) { day = (day - 10) % GRAD; } void yearAdd (void) { year = (year + 5) % GRAD; } void yearSubtract (void) { year = (year - 5) % GRAD; } void display(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); glPushMatrix(); /* draw sun */ auxWireSphere(1.0); /* draw smaller planet */ glRotatef ((GLfloat) year, 0.0, 1.0, 0.0); glTranslatef (2.0, 0.0, 0.0); glRotatef ((GLfloat) day, 0.0, 1.0, 0.0); auxWireSphere(0.2); glPopMatrix(); glFlush(); } void myinit (void) { glShadeModel (GL_FLAT); } void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef (0.0, 0.0, -5.0); } int main(int argc, char** argv) { auxInitDisplayMode (AUX_SINGLE | AUX_RGB); auxInitPosition (0, 0, 500, 500); auxInitWindow (argv[0]); myinit (); auxKeyFunc (AUX_LEFT, yearSubtract); auxKeyFunc (AUX_RIGHT, yearAdd); auxKeyFunc (AUX_UP, dayAdd); auxKeyFunc (AUX_DOWN, daySubtract); auxReshapeFunc (myReshape); auxMainLoop(display); }