/* * OpenGL (GLUT) calls this routine to display the scene */ void display() { const double len=1.5; // Length of axes int i = 0; // Erase the window and the depth buffer glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Enable Z-buffering in OpenGL glEnable(GL_DEPTH_TEST); // Undo previous transformations glLoadIdentity(); if (view){ double Ex = -2*dim*Sin(th)*Cos(ph); double Ey = +2*dim *Sin(ph); double Ez = +2*dim*Cos(th)*Cos(ph); gluLookAt(Ex, Ey, Ez, 0,0,0, 0,Cos(ph),0); } else { // Set view angle glRotatef(ph,1,0,0); glRotatef(th,0,1,0); } // Decide what to draw switch (mode) { // Draw cubes case 2: truck(0,0,0 , 0.2,0.2,0.2 , 0); truck(1,0,2 , 0.1,0.1,0.1 , 30); truck(0,1,0 , 0.4,0.3,0.2 , 90); break; // Draw spheres case 1: taxi(0,0,0 , 0.2,0.2,0.2 , 0); taxi(0,0,0 , 0.2,0.2,0.2 , 0); taxi(0,0,0 , 0.2,0.2,0.2 , 0); //tree(0,0,0,1); break; case 0: // printf("ph: %f\t th: %f\t zh:%f\n", ph, th, zh); //road glBegin(GL_QUADS); glColor3f(0.3, 0.3, 0.3); glVertex3f(-100, -.1,-1); glVertex3f(100, -.1, -1); glVertex3f(100, -.1, 3); glVertex3f(-100, -.1, 3); //stripes glColor3f(1,1,0); for(i=-10; i<100; i++){ glVertex3f(i, -.1+offset, 1); glVertex3f(i+.7, -.1+offset, 1); glVertex3f(i+.7, -.1+offset, 1.1); glVertex3f(i, -.1+offset, 1.1); } glEnd(); truck((zh-120)*0.1,.1,1.5, .15,.15,.15, 180); taxi(-(zh-120)*0.15,0,.5, .1,.1,.1, 0); truck(2-(zh-120)*0.1,.1,.1, .1,.1,.1, 0); taxi(-5+(zh-100)*0.07,.2,1.5, .1,.1,.1, 180); sleep(10000); truck(10-(zh-120)*0.15,.1,.5, .1,.1,.1, 0); // taxi(-2-(zh-120)*0.05,0,1, .1,.1,.1, 0); break; case 3: // Cube truck(-1,0,0 , 0.2,0.2,0.2 , 3*zh); // Ball //vaxisphere2(0,0,0 , 0.3); taxi(Cos(zh), Sin(zh), Cos(zh)*Sin(zh), .1,.1,.1,1 ); break; } // White glColor3f(1,1,1); // Draw axes if (mode != 0) if (axes) { glBegin(GL_LINES); glVertex3d(0.0,0.0,0.0); glVertex3d(len,0.0,0.0); glVertex3d(0.0,0.0,0.0); glVertex3d(0.0,len,0.0); glVertex3d(0.0,0.0,0.0); glVertex3d(0.0,0.0,len); glEnd(); // Label axes glRasterPos3d(len,0.0,0.0); Print("X"); glRasterPos3d(0.0,len,0.0); Print("Y"); glRasterPos3d(0.0,0.0,len); Print("Z"); } // Five pixels from the lower left corner of the window glWindowPos2i(5,5); // Print the text string Print("Angle=%d,%d",th,ph); // Render the scene glFlush(); // Make the rendered scene visible glutSwapBuffers(); }
int main(void) { *b = 10; return taxi(9); }