#include #include #include #define Z 30.0 double dist = -50.0; double theta = 0.0; void myKeyboard(unsigned char key, int x, int y) { if (key == 27) exit(0); } void myDisplay(void) { int i = 0; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glPushMatrix(); /* Move view point */ gluLookAt(0.0, 2.0, dist, 0.0, 2.0, dist+1.0, 0.0, 2.0, 0.0); glPushMatrix(); //red teapot glTranslated(1.0, 2.0, 0.0); glRotated(theta, 1.0, 1.0, 0.0); glColor3d(1.0, 0.0, 0.0); glutWireTeapot(1.0); glPopMatrix(); glPushMatrix(); //red teapot2 glTranslated(1.0, 2.0, 79.8); glRotated(theta, 1.0, 1.0, 00.0); glColor3d(1.0, 0.0, 0.0); glutWireTeapot(1.0); glPopMatrix(); glPushMatrix(); //blue teapot glTranslated(-1.0, 2.0, 30.0); glRotated(theta, 2.0, 3.0, 4.0); glColor3d(0.0, 0.0, 1.0); glutWireTeapot(1.0); glPopMatrix(); glColor3d(1.0, 1.0, 1.0); // draw floor glBegin( GL_LINES ); for ( i=-100; i< 100; i+=2 ) { glVertex3i( i, 0,-100); glVertex3i( i, 0, 100); glVertex3i(-100, 0, i); glVertex3i( 100, 0, i); } glEnd(); glPopMatrix(); glutSwapBuffers(); } void myIdle(void) { dist += 0.5; if (dist >= Z ) dist = -50.0; theta = fmod(theta + 2, 360.0); glutPostRedisplay(); } void myInit(char *progname) { int width = 640, height = 480; glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(width, height); glutInitWindowPosition(0, 0); glutCreateWindow(progname); glClearColor(0.0, 0.0, 0.0, 1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90.0, (double)width / (double)height, 0.1, 80.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glShadeModel(GL_FLAT); } int main(int argc, char** argv) { glutInit(&argc, argv); myInit(argv[0]); glutKeyboardFunc(myKeyboard); glutIdleFunc(myIdle); glutDisplayFunc(myDisplay); glutMainLoop(); return 0; }