Facebook
From Denim Lion, 1 Year ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 74
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <gl/freeglut.h>
  4. #include <windows.h>
  5. #include <math.h>
  6. #include <cstdio>
  7.  
  8.  
  9. void init()
  10. {
  11.         glClearColor(0, 0, 0, 1);
  12.         glMatrixMode(GL_PROJECTION);
  13.         glLoadIdentity();
  14.         glOrtho(-500, 500, -500, 500, -500, 500);
  15.         glMatrixMode(GL_MODELVIEW);
  16. }
  17.  
  18. void front()
  19. {
  20.         glColor3f(1, 1, 1);
  21.         glPushMatrix();
  22.         glTranslatef(-450, -250, 0);
  23.         glScalef(0.01, 0.3, 0.85);
  24.         glutSolidCube(600);
  25.         glColor3f(1, 1, 1);
  26.         glutWireCube(600);
  27.         glPopMatrix();
  28.  
  29.         glColor3f(1, 1, 1);
  30.         glPushMatrix();
  31.         glTranslatef(-370, -70, 0);
  32.         glRotatef(-45, 0, 0, 1);
  33.         glScalef(0.01, 0.4, 0.85);
  34.         glutWireCube(600);
  35.         glPopMatrix();
  36. }
  37.  
  38. void back()
  39. {
  40.         glColor3f(1, 1, 1);
  41.         glPushMatrix();
  42.         glTranslatef(450, -250, 0);
  43.         glScalef(0.01, 0.3, 0.85);
  44.         glutSolidCube(600);
  45.         glColor3f(1, 1, 1);
  46.         glutWireCube(600);
  47.         glPopMatrix();
  48.  
  49.         glColor3f(1, 0, 0);
  50.         glPushMatrix();
  51.         glTranslatef(380, -80, 0);
  52.         glRotatef(38, 0, 0, 1);
  53.         glScalef(0.01, 0.35, 0.85);
  54.         glColor3f(1, 1, 1);
  55.         glutWireCube(600);
  56.         glPopMatrix();
  57. }
  58.  
  59. void top()
  60. {
  61.         glColor3f(0, 0, 1);
  62.         glPushMatrix();
  63.         glTranslatef(15, 20, 0);
  64.         glScalef(1, 0.01, 0.85);
  65.         glutSolidCube(600);
  66.         glColor3f(1, 1, 1);
  67.         glutWireCube(600);
  68.         glPopMatrix();
  69. }
  70.  
  71. void bottom()
  72. {
  73.         glColor3f(0.35, 0.16, 0.14);
  74.         glPushMatrix();
  75.         glTranslatef(0, -350, 0);
  76.         glScalef(1.5, 0.01, 0.85);
  77.         glutSolidCube(600);
  78.         glColor3f(1, 1, 1);
  79.         glutWireCube(600);
  80.         glPopMatrix();
  81. }
  82.  
  83. void left()
  84. {
  85.         glColor3f(0, 0, 1);
  86.         glPushMatrix();
  87.         glTranslatef(0, -250, 250);
  88.         glScalef(1.5, 0.3, 0.01);
  89.         glutSolidCube(600);
  90.         glColor3f(1, 1, 1);
  91.         glutWireCube(600);
  92.         glPopMatrix();
  93. }
  94.  
  95. void right()
  96. {
  97.         glColor3f(0, 0, 1);
  98.         glPushMatrix();
  99.         glTranslatef(0, -250, -250);
  100.         glScalef(1.5, 0.3, 0.01);
  101.         glutSolidCube(600);
  102.         glColor3f(1, 1, 1);
  103.         glutWireCube(600);
  104.         glPopMatrix();
  105. }
  106.  
  107. void wheel(int x, int y, int z)
  108. {
  109.         float th;
  110.         glColor3f(0.184314, 0.309804, 0.309804);
  111.         for(int j=0;j<50;j+=10)
  112.         {
  113.                 glBegin(GL_POLYGON);
  114.                 for (int i = 0; i < 360; i++)
  115.                 {
  116.                         th = i * 3.142 / 180;
  117.                         glVertex3f(x+70*cos(th),y+70*sin(th),z+j);
  118.                 }
  119.                 glEnd();
  120.         }
  121. }
  122.  
  123. void border()
  124. {
  125.         glPushMatrix();
  126.         glTranslatef(-50, -160, 250);
  127.         glScalef(0.01, 0.6, 0.01);
  128.         glColor3f(1, 1, 1);
  129.         glutWireCube(600);
  130.         glPopMatrix();
  131.  
  132.         glPushMatrix();
  133.         glTranslatef(-50, -160, -250);
  134.         glScalef(0.01, 0.6, 0.01);
  135.         glColor3f(1, 1, 1);
  136.         glutWireCube(600);
  137.         glPopMatrix();
  138. }
  139.  
  140. void car()
  141. {
  142.         front();
  143.         back();
  144.         top();
  145.         bottom();
  146.         left();
  147.         right();
  148.         wheel(-300, -400, 200);
  149.         wheel(300, -400, 200);
  150.         wheel(-300, -400, -200);
  151.         wheel(300, -400, -200);
  152.         border();
  153. }
  154.  
  155. float theta;
  156.  
  157. void display()
  158. {
  159.         theta += 0.1;
  160.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  161.         glLoadIdentity();
  162.         glRotatef(theta, 1, 1, 0);
  163.         glScalef(0.5, 0.5, 0.5);
  164.         car();
  165.         glutSwapBuffers();
  166.         glutPostRedisplay();
  167. }
  168.  
  169. void main(int argc, char** argv)
  170. {
  171.         glutInit(&argc, argv);
  172.         glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
  173.         glutInitWindowPosition(0, 0);
  174.         glutInitWindowSize(500, 500);
  175.         glutCreateWindow("Testing Prog");
  176.         init();
  177.         glutDisplayFunc(display);
  178.         glEnable(GL_DEPTH_TEST);
  179.         glutMainLoop();
  180. }
  181.  
  182.