#include #include #include #include #include #include void init() { glClearColor(0, 0, 0, 1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-500, 500, -500, 500, -500, 500); glMatrixMode(GL_MODELVIEW); } void front() { glColor3f(1, 1, 1); glPushMatrix(); glTranslatef(-450, -250, 0); glScalef(0.01, 0.3, 0.85); glutSolidCube(600); glColor3f(1, 1, 1); glutWireCube(600); glPopMatrix(); glColor3f(1, 1, 1); glPushMatrix(); glTranslatef(-370, -70, 0); glRotatef(-45, 0, 0, 1); glScalef(0.01, 0.4, 0.85); glutWireCube(600); glPopMatrix(); } void back() { glColor3f(1, 1, 1); glPushMatrix(); glTranslatef(450, -250, 0); glScalef(0.01, 0.3, 0.85); glutSolidCube(600); glColor3f(1, 1, 1); glutWireCube(600); glPopMatrix(); glColor3f(1, 0, 0); glPushMatrix(); glTranslatef(380, -80, 0); glRotatef(38, 0, 0, 1); glScalef(0.01, 0.35, 0.85); glColor3f(1, 1, 1); glutWireCube(600); glPopMatrix(); } void top() { glColor3f(0, 0, 1); glPushMatrix(); glTranslatef(15, 20, 0); glScalef(1, 0.01, 0.85); glutSolidCube(600); glColor3f(1, 1, 1); glutWireCube(600); glPopMatrix(); } void bottom() { glColor3f(0.35, 0.16, 0.14); glPushMatrix(); glTranslatef(0, -350, 0); glScalef(1.5, 0.01, 0.85); glutSolidCube(600); glColor3f(1, 1, 1); glutWireCube(600); glPopMatrix(); } void left() { glColor3f(0, 0, 1); glPushMatrix(); glTranslatef(0, -250, 250); glScalef(1.5, 0.3, 0.01); glutSolidCube(600); glColor3f(1, 1, 1); glutWireCube(600); glPopMatrix(); } void right() { glColor3f(0, 0, 1); glPushMatrix(); glTranslatef(0, -250, -250); glScalef(1.5, 0.3, 0.01); glutSolidCube(600); glColor3f(1, 1, 1); glutWireCube(600); glPopMatrix(); } void wheel(int x, int y, int z) { float th; glColor3f(0.184314, 0.309804, 0.309804); for(int j=0;j<50;j+=10) { glBegin(GL_POLYGON); for (int i = 0; i < 360; i++) { th = i * 3.142 / 180; glVertex3f(x+70*cos(th),y+70*sin(th),z+j); } glEnd(); } } void border() { glPushMatrix(); glTranslatef(-50, -160, 250); glScalef(0.01, 0.6, 0.01); glColor3f(1, 1, 1); glutWireCube(600); glPopMatrix(); glPushMatrix(); glTranslatef(-50, -160, -250); glScalef(0.01, 0.6, 0.01); glColor3f(1, 1, 1); glutWireCube(600); glPopMatrix(); } void car() { front(); back(); top(); bottom(); left(); right(); wheel(-300, -400, 200); wheel(300, -400, 200); wheel(-300, -400, -200); wheel(300, -400, -200); border(); } float theta; void display() { theta += 0.1; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glRotatef(theta, 1, 1, 0); glScalef(0.5, 0.5, 0.5); car(); glutSwapBuffers(); glutPostRedisplay(); } void main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); glutInitWindowPosition(0, 0); glutInitWindowSize(500, 500); glutCreateWindow("Testing Prog"); init(); glutDisplayFunc(display); glEnable(GL_DEPTH_TEST); glutMainLoop(); }