Advertisement
mhdew

Untitled

Dec 13th, 2020
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.31 KB | None | 0 0
  1. #include <GL/glut.h>
  2. #include <GL/glu.h>
  3. #include <math.h>
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. float cc[20][2];
  8.  
  9. void init(void);
  10. void display(void);
  11. void keyboard(unsigned char, int, int);
  12. void resize(int, int);
  13. void draw_star(float,float);
  14. void house(float,float,float);
  15. void apart(float,float,float);
  16. void circle1(float);
  17. void stand(float ,float ,float );
  18. float  h=5,h1=6,d1=4,g=1,g1=2;
  19.  
  20. int main (int argc, char **argv)
  21. {
  22.     glutInit(&argc, argv);
  23.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  24.     glutInitWindowSize(1100, 1100);
  25.     glutInitWindowPosition(100, 10);
  26.     glutCreateWindow("3D map");
  27.     init();
  28.    
  29.     glutDisplayFunc(display);
  30.     glutKeyboardFunc(keyboard);
  31.  
  32.     glutReshapeFunc(resize);
  33.  
  34.     glutMainLoop();
  35.     return 0;
  36. }
  37.  
  38. void apart(float x,float y,float z)
  39. {
  40.     int i;
  41.     int j;
  42.     glColor3f(0.7,0.7,0.7);
  43.     glBegin(GL_POLYGON);
  44.     glVertex3f(x,y,z+0.5);
  45.     glVertex3f(x+45,y,z+0.5);
  46.     glVertex3f(x+45,y+100,z+0.5);
  47.     glVertex3f(x,y+100,z+0.5);
  48.     glEnd();  glColor3f(0.8,0.8,0.8);
  49. for(j=0;j<8;j++)
  50. {
  51.  
  52.     glPushMatrix();
  53.         glTranslatef(0,-12*j,0);
  54.     for(i=0;i<4;i++)
  55.     {
  56.         glPushMatrix();
  57.         glTranslatef(11*i,0,0);
  58.     glBegin(GL_POLYGON);
  59.     glVertex3f(x+2,y+98,z);
  60.     glVertex3f(x+10,y+98,z);
  61.     glVertex3f(x+10,y+88,z);
  62.     glVertex3f(x+2,y+88,z);
  63.     glEnd();
  64.     glPopMatrix();
  65.     }glPopMatrix();
  66. }glColor3f(0,0,0);
  67. for(j=0;j<8;j++)
  68. {
  69.  
  70.     glPushMatrix();
  71.         glTranslatef(0,-12*j,0);
  72.     for(i=0;i<4;i++)
  73.     {
  74.         glPushMatrix();
  75.         glTranslatef(11*i,0,0);
  76.         glBegin(GL_LINE_LOOP);
  77.     glVertex3f(x+2,y+98,z);
  78.     glVertex3f(x+10,y+98,z);
  79.     glVertex3f(x+10,y+88,z);
  80.     glVertex3f(x+2,y+88,z);
  81.     glEnd();
  82.     glPopMatrix();
  83.     }glPopMatrix();
  84. }
  85.  
  86. glColor3f(0.6,0.6,0.6);
  87.     glBegin(GL_POLYGON);
  88.     glVertex3f(x,y,z+45-0.5);
  89.     glVertex3f(x+45,y,z+45-0.5);
  90.     glVertex3f(x+45,y+100,z+45-0.5);
  91.     glVertex3f(x,y+100,z+45-0.5);
  92.     glEnd();    glColor3f(0.8,0.8,0.8);
  93.  
  94. for(j=0;j<8;j++)
  95. {
  96.  
  97.     glPushMatrix();
  98.         glTranslatef(0,-12*j,0);
  99.     for(i=0;i<4;i++)
  100.     {
  101.         glPushMatrix();
  102.         glTranslatef(11*i,0,0);
  103.     glBegin(GL_POLYGON);
  104.     glVertex3f(x+2,y+98,z+45);
  105.     glVertex3f(x+10,y+98,z+45);
  106.     glVertex3f(x+10,y+88,z+45);
  107.     glVertex3f(x+2,y+88,z+45);
  108.     glEnd();
  109.     glPopMatrix();
  110.     }glPopMatrix();
  111. }glColor3f(0,0,0);
  112.  
  113. for(j=0;j<8;j++)
  114. {
  115.  
  116.     glPushMatrix();
  117.         glTranslatef(0,-12*j,0);
  118.     for(i=0;i<4;i++)
  119.     {
  120.         glPushMatrix();
  121.         glTranslatef(11*i,0,0);
  122.     glBegin(GL_LINE_LOOP);
  123.     glVertex3f(x+2,y+98,z+45);
  124.     glVertex3f(x+10,y+98,z+45);
  125.     glVertex3f(x+10,y+88,z+45);
  126.     glVertex3f(x+2,y+88,z+45);
  127.     glEnd();
  128.     glPopMatrix();
  129.     }glPopMatrix();
  130. }
  131.  
  132. glColor3f(0.6,0.6,0.6);
  133.     glBegin(GL_POLYGON);
  134.     glVertex3f(x+0.5,y,z);
  135.     glVertex3f(x+0.5,y,z+45);
  136.     glVertex3f(x+0.5,y+100,z+45);
  137.     glVertex3f(x+0.5,y+100,z);
  138.     glEnd();
  139.     glColor3f(0.8,0.8,0.8);
  140. for(j=0;j<8;j++)
  141. {
  142.  
  143.     glPushMatrix();
  144.         glTranslatef(0,-12*j,0);
  145.     for(i=0;i<4;i++)
  146.     {
  147.         glPushMatrix();
  148.         glTranslatef(0,0,11*i);
  149.     glBegin(GL_POLYGON);
  150.     glVertex3f(x,y+98,z+2);
  151.     glVertex3f(x,y+98,z+10);
  152.     glVertex3f(x,y+88,z+10);
  153.     glVertex3f(x,y+88,z+2);
  154.     glEnd();
  155.     glPopMatrix();
  156.     }glPopMatrix();
  157. }glColor3f(0,0,0);
  158. for(j=0;j<8;j++)
  159. {
  160.  
  161.     glPushMatrix();
  162.         glTranslatef(0,-12*j,0);
  163.     for(i=0;i<4;i++)
  164.     {
  165.         glPushMatrix();
  166.         glTranslatef(0,0,11*i);
  167.         glBegin(GL_LINE_LOOP);
  168.     glVertex3f(x,y+98,z+2);
  169.     glVertex3f(x,y+98,z+10);
  170.     glVertex3f(x,y+88,z+10);
  171.     glVertex3f(x,y+88,z+2);
  172.     glEnd();
  173.     glPopMatrix();
  174.     }glPopMatrix();
  175. }
  176.  
  177. glColor3f(0.6,0.6,0.6);
  178.  
  179.     glBegin(GL_POLYGON);
  180.     glVertex3f(x+45-0.5,y,z-0.5);
  181.     glVertex3f(x+45-0.5,y,z+45-0.5);
  182.     glVertex3f(x+45-0.5,y+100,z+45-0.5);
  183.     glVertex3f(x+45-0.5,y+100,z-0.5);
  184.     glEnd(); glColor3f(0.8,0.8,0.8);
  185. for(j=0;j<8;j++)
  186. {
  187.  
  188.     glPushMatrix();
  189.         glTranslatef(0,-12*j,0);
  190.     for(i=0;i<4;i++)
  191.     {
  192.         glPushMatrix();
  193.         glTranslatef(0,0,11*i);
  194.     glBegin(GL_POLYGON);
  195.     glVertex3f(x+45,y+98,z+2);
  196.     glVertex3f(x+45,y+98,z+10);
  197.     glVertex3f(x+45,y+88,z+10);
  198.     glVertex3f(x+45,y+88,z+2);
  199.     glEnd();
  200.     glPopMatrix();
  201.     }glPopMatrix();
  202. }
  203. glColor3f(0,0,0);
  204. for(j=0;j<8;j++)
  205. {
  206.  
  207.     glPushMatrix();
  208.         glTranslatef(0,-12*j,0);
  209.     for(i=0;i<4;i++)
  210.     {
  211.         glPushMatrix();
  212.         glTranslatef(0,0,11*i);
  213.         glBegin(GL_LINE_LOOP);
  214.     glVertex3f(x+45,y+98,z+2);
  215.     glVertex3f(x+45,y+98,z+10);
  216.     glVertex3f(x+45,y+88,z+10);
  217.     glVertex3f(x+45,y+88,z+2);
  218.     glEnd();
  219.     glPopMatrix();
  220.     }glPopMatrix();
  221. }
  222.  
  223. glColor3f(0.5,0.5,0.5);
  224. glBegin(GL_POLYGON);
  225.     glVertex3f(x,y,z-0.5);
  226.     glVertex3f(x+45,y,z-0.5);
  227.     glVertex3f(x+45,y,z+45-0.5);
  228.     glVertex3f(x,y,z+45-0.5);
  229.     glEnd();
  230.  
  231.     glBegin(GL_POLYGON);
  232.     glVertex3f(x,y+100,z);
  233.     glVertex3f(x+45,y+100,z);
  234.     glVertex3f(x+45,y+100,z+45);
  235.     glVertex3f(x,y+100,z+45);
  236.     glEnd();
  237. }
  238.  
  239. void house(float x,float y,float z)
  240. {
  241.     glColor3f(0.01,0.05,0.3);
  242.     glBegin(GL_POLYGON);
  243.     glVertex3f(x,y,z);
  244.     glVertex3f(x,y,z+30);
  245.     glVertex3f(x,y+15,z+30);
  246.     glVertex3f(x,y+15,z);
  247.     glEnd();
  248.  
  249.     glColor3f(0.01,0.05,0.3);
  250.     glBegin(GL_POLYGON);
  251.     glVertex3f(x-15,y,z);
  252.     glVertex3f(x-15,y+15,z);
  253.     glVertex3f(x-15,y+15,z+30);
  254.     glVertex3f(x-15,y,z+30);
  255.     glEnd();
  256.  
  257.     glColor3f(0.01,0.05,0.3);
  258.     glBegin(GL_POLYGON);
  259.     glVertex3f(x,y,z+30);
  260.     glVertex3f(x-15,y,z+30);
  261.     glVertex3f(x-15,y+15,z+30);
  262.     glVertex3f(x,y+15,z+30);
  263.     glEnd();
  264.  
  265.     glColor3f(0.01,0.05,0.3);
  266.     glBegin(GL_POLYGON);
  267.     glVertex3f(x-15,y,z);
  268.     glVertex3f(x-15,y+15,z);
  269.     glVertex3f(x,y+15,z);
  270.     glVertex3f(x,y,z);
  271.     glEnd();
  272.  
  273.     glColor3f(0.01,0.05,1.5);
  274.     glBegin(GL_POLYGON);
  275.     glVertex3f(x-15,y,z);
  276.     glVertex3f(x,y,z);
  277.     glVertex3f(x,y,z+30);
  278.     glVertex3f(x-15,y,z+30);
  279.     glEnd();
  280.  
  281.  
  282.     glColor3f(0.51,0.015,0.008);
  283.     glBegin(GL_POLYGON);
  284.     glVertex3f(x+1.69*3,y+3.5*3,z);
  285.     glVertex3f(x-2.5*3,y+7.5*3,z);
  286.     glVertex3f(x-2.5*3,y+7.5*3,z+30);
  287.     glVertex3f(x+1.69*3,y+3.5*3,z+30);
  288.     glEnd();
  289.  
  290.  
  291.     glColor3f(0.51,0.015,0.008);
  292.     glBegin(GL_POLYGON);
  293.     glVertex3f(x-6.69*3,y+3.5*3,z);
  294.     glVertex3f(x-6.69*3,y+3.5*3,z+30);
  295.     glVertex3f(x-2.5*3,y+7.5*3,z+30);
  296.     glVertex3f(x-2.5*3,y+7.5*3,z);
  297.     glEnd();
  298.  
  299.  
  300. glColor3f(0.1,0.015,0.13);
  301.     glBegin(GL_POLYGON);
  302.     glVertex3f(x,y+15,z);
  303.     glVertex3f(x-15,y+5,z);
  304.     glVertex3f(x-2.5*3,y+7.5*3,z);
  305.     glEnd();
  306.  
  307. glColor3f(0.1,0.015,0.13);
  308.     glBegin(GL_POLYGON);
  309.     glVertex3f(x,y+15,z+30);
  310.     glVertex3f(x-15,y+15,z+30);
  311.     glVertex3f(x-2.5*3,y+7.5*3,z+30);
  312.     glEnd();
  313. }
  314.  
  315.  
  316. void house1()
  317. {
  318.  
  319.     house(120,0.1,50);
  320.  
  321.     house(120,0.1,90);
  322.  
  323.     house(160,0.1,90);
  324.  
  325.     house(80,0.1,90);
  326.  
  327.     house(160,0.1,50);
  328.  
  329.     house(80,0.1,50);
  330.  
  331.     house(-130,0.1,120);
  332.  
  333.     house(-130,0.1,160);
  334.  
  335.     house(-90,0.1,120);
  336.  
  337.     house(-60,0.1,120);
  338.  
  339.     house(-90,0.1,160);
  340.  
  341.     stand(-10,6,130);
  342.     stand(30,6,130);
  343.  
  344.     house(-60,0.1,160);
  345.     apart(150,0,-150);
  346.     apart(80,0,-90);
  347.  
  348.     apart(150,0,-90);
  349.     apart(150,0,-30);
  350.  
  351.     apart(-150,0,-30);
  352.     apart(-150,0,-110);
  353.  
  354.     apart(-150,0,-180);
  355.  
  356. }
  357. void circle1(float c[20][2])
  358. {
  359. float x=0,y=03;
  360. int i;
  361. for(i=0;i<20;i++)
  362. {
  363. c[i][0]=x*cos((i+1)*36*(3.142/360))-y*sin((i+1)*36*(3.142/360));
  364. c[i][1]=x*sin((i+1)*36*(3.142/360))+y*cos((i+1)*36*(3.142/360));
  365. }
  366.  
  367. for(i=0;i<19;i++)
  368. {
  369.     glBegin(GL_POLYGON);
  370. glVertex3f(c[i][0],c[i][1],0);
  371. glVertex3f(c[i][0],c[i][1],40);
  372. glVertex3f(c[i+1][0],c[i+1][1],40);
  373. glVertex3f(c[i+1][0],c[i+1][1],0);
  374. glEnd();
  375. }
  376.  
  377. glBegin(GL_POLYGON);
  378. glVertex3f(c[0][0],c[0][1],0);
  379. glVertex3f(c[0][0],c[0][1],40);
  380. glVertex3f(c[19][0],c[19][1],40);
  381. glVertex3f(c[19][0],c[19][1],0);
  382. glEnd();
  383.  
  384. }
  385.  
  386.  
  387. void init(void)
  388. {
  389.         glClearColor(0.0,0.0,0.0,0.0);
  390. glEnable(GL_DEPTH_TEST);
  391.     glMatrixMode(GL_MODELVIEW);
  392. }
  393.  
  394. void draw_star(GLfloat x, GLfloat y)
  395. {
  396.     glColor3f(1.0,1.0,1.0);
  397.     glBegin(GL_POLYGON);
  398.         glVertex2f(x,y);
  399.         glVertex2f(x+1.5,y-4);
  400.         glVertex2f(x+6.5,y-5.5);
  401.         glVertex2f(x+2.5,y-9);
  402.         glVertex2f(x+4.5,y-14);
  403.         glVertex2f(x,y-11.5);
  404.         glVertex2f(x-4.5,y-14);
  405.         glVertex2f(x-3,y-9);
  406.         glVertex2f(x-6.5,y-5.5);
  407.         glVertex2f(x-1.5,y-5);
  408.         glVertex2f(x,y);
  409.     glEnd();
  410. }
  411.  
  412.  
  413. void stand(float x,float y,float z)
  414. {
  415.     glColor3f(1,0.8,0);
  416.     glBegin(GL_POLYGON);
  417. glVertex3f(x,y,z);
  418. glVertex3f(x,y-h1,z+d1);
  419. glVertex3f(x+h,y-h1,z+d1);
  420. glVertex3f(x+h,y,z);
  421. glEnd();
  422.     glColor3f(1,0.5,0);
  423.     glBegin(GL_POLYGON);
  424. glVertex3f(x,y,z);
  425. glVertex3f(x+h,y,z);
  426. glVertex3f(x+h,y-h1,z-d1);
  427. glVertex3f(x,y-h1,z-d1);
  428. glEnd();
  429.  
  430. glColor3f(0.6,0.12,0.4);
  431.  
  432. glBegin(GL_POLYGON);
  433. glVertex3f(x,y-h1,z+d1);
  434. glVertex3f(x,y-h1-2,z+d1);
  435. glVertex3f(x+1,y-h1-2,z+d1);
  436. glVertex3f(x+1,y-h1,z+d1);
  437. glEnd();
  438.  
  439. glColor3f(0.6,0.12,0.4);
  440. glBegin(GL_POLYGON);
  441. glVertex3f(x+h,y-h1,z+d1);
  442. glVertex3f(x+h,y-h1-2,z+d1);
  443. glVertex3f(x+h-1,y-h1-2,z+d1);
  444. glVertex3f(x+h-1,y-h1,z+d1);
  445. glEnd();
  446.  
  447. glColor3f(0.6,0.12,0.4);
  448.  
  449. glBegin(GL_POLYGON);
  450. glVertex3f(x,y-h1,z-d1);
  451. glVertex3f(x,y-h1-2,z-d1);
  452. glVertex3f(x+1,y-h1-2,z-d1);
  453. glVertex3f(x+1,y-h1,z-d1);
  454. glEnd();
  455.  
  456. glColor3f(0.6,0.12,0.4);
  457.  
  458. glBegin(GL_POLYGON);
  459. glVertex3f(x+h,y-h1,z-d1);
  460. glVertex3f(x+h,y-h1-2,z-d1);
  461. glVertex3f(x+h-1,y-h1-2,z-d1);
  462. glVertex3f(x+h-1,y-h1,z-d1);
  463. glEnd();
  464. }
  465.  
  466. void display(void)
  467. {
  468.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  469.     /* draw the floor */
  470.     glBegin(GL_QUADS);
  471.     glColor3f(0.8,0.6,0.4);
  472.         glVertex3f(-200.0, 0.0, -200.0);
  473.             glColor3f(0.8,0.6,0.4);
  474. glVertex3f(-200.0, 0.0, 200.0);
  475.     glColor3f(0.8,0.6,0.4);
  476.         glVertex3f(200.0, 0.0, 200.0);
  477.     glColor3f(0.8,0.6,0.4);
  478.         glVertex3f(200.0, 0.0, -200.0);
  479.     glEnd();
  480.     glFlush();
  481.  
  482.     draw_star(20,240);
  483.     draw_star(180,220);
  484.     draw_star(-30,280);
  485.     draw_star(190,280);
  486.     draw_star(100,220);
  487.     draw_star(-230,250);
  488.     draw_star(-190,210);
  489.     draw_star(-88,260);
  490.     draw_star(88,270);
  491.     draw_star(-170,280);
  492.  
  493.  
  494.     glColor3f(0.3,0.015,0.13);
  495.     glPushMatrix();
  496.     glTranslatef(-15,1,50);
  497.     glutSolidCube(7);
  498.     glPopMatrix();
  499.  
  500.     glColor3f(0.3,0.015,0.13);
  501.     glPushMatrix();
  502.     glTranslatef(-15,1,-40);
  503.     glutSolidCube(7);
  504.     glPopMatrix();
  505.  
  506.     glColor3f(0.3,0.015,0.13);
  507.     glPushMatrix();
  508.     glTranslatef(-15,1,20);
  509.     glutSolidCube(7);
  510.     glPopMatrix();
  511.  
  512.     glColor3f(0.3,0.015,0.13);
  513.     glPushMatrix();
  514.     glTranslatef(-15,1,-10);
  515.     glutSolidCube(7);
  516.     glPopMatrix();
  517.  
  518.     glColor3f(0.3,0.015,0.13);
  519.     glPushMatrix();
  520.     glTranslatef(-15,1,-80);
  521.     glutSolidCube(7);
  522.     glPopMatrix();
  523.  
  524.     glColor3f(0.3,0.015,0.13);
  525.     glPushMatrix();
  526.     glTranslatef(-15,1,-120);
  527.     glutSolidCube(7);
  528.     glPopMatrix();
  529.  
  530.     glColor3f(0.3,0.015,0.13);
  531.     glPushMatrix();
  532.     glTranslatef(-15,1,-160);
  533.     glutSolidCube(7);
  534.     glPopMatrix();
  535.  
  536.  
  537.  
  538.  
  539.     glColor3f(0.015,0.3,0.13);
  540.     glPushMatrix();
  541.     glTranslatef(-15,24,50);
  542.     glScalef(1.1,2.3,0.8);
  543.     glutSolidSphere(10,15,6);
  544.     glFlush();
  545.     glPopMatrix();
  546.  
  547.     glColor3f(0.015,0.3,0.13);
  548.     glPushMatrix();
  549.     glTranslatef(-15,24,-40);
  550.     glScalef(1.1,2.3,0.8);
  551.     glutSolidSphere(10,15,4);
  552.     glFlush();
  553.     glPopMatrix();
  554.  
  555.     glColor3f(0.015,0.3,0.13);
  556.     glPushMatrix();
  557.     glTranslatef(-15,24,20);
  558.     glScalef(1.1,2.3,0.8);
  559.     glutSolidSphere(10,15,4);
  560.     glFlush();
  561.     glPopMatrix();
  562.  
  563.     glColor3f(0.015,0.3,0.13);
  564.     glPushMatrix();
  565.     glTranslatef(-15,24,-10);
  566.     glScalef(1.1,2.3,0.8);
  567.     glutSolidSphere(10,15,4);
  568.     glFlush();
  569.     glPopMatrix();
  570.  
  571.     glColor3f(0.015,0.3,0.13);
  572.     glPushMatrix();
  573.     glTranslatef(-15,24,-80);
  574.     glScalef(1.1,2.3,0.8);
  575.     glutSolidSphere(10,15,4);
  576.     glFlush();
  577.     glPopMatrix();
  578.  
  579.     glColor3f(0.015,0.3,0.13);
  580.     glPushMatrix();
  581.     glTranslatef(-15,24,-120);
  582.     glScalef(1.1,2.3,0.8);
  583.     glutSolidSphere(10,15,4);
  584.     glFlush();
  585.     glPopMatrix();
  586.  
  587.     glColor3f(0.015,0.3,0.13);
  588.     glPushMatrix();
  589.     glTranslatef(-15,24,-160);
  590.     glScalef(1.1,2.3,0.8);
  591.     glutSolidSphere(10,15,4);
  592.     glFlush();
  593.     glPopMatrix();
  594.  
  595.  
  596.     glBegin(GL_QUADS);
  597.         glColor3f(0.2, 0.2, 0.2);
  598.         glVertex3f(0,0.01,-200); /* road */
  599.         glColor3f(0.2, 0.2, 0.2);
  600.         glVertex3f(0,0.01,200);
  601.         glColor3f(0.2, 0.2, 0.2);
  602.         glVertex3f(18,0.01,200);
  603.         glColor3f(0.2, 0.2, 0.2);
  604.         glVertex3f(18,0.01,-200);
  605.         glEnd();
  606.  
  607.     glBegin(GL_QUADS);
  608.         glColor3f(1.0, 1.0, 1.0);
  609.         glVertex3f(8.5,0.02,-200); /* road */
  610.         glColor3f(1.0, 1.0, 1.0);
  611.         glVertex3f(8.5,0.02,200);
  612.         glColor3f(1.0, 1.0, 1.0);
  613.         glVertex3f(9.5,0.02,200);
  614.         glColor3f(1.0, 1.0, 1.0);
  615.         glVertex3f(9.5,0.02,-200);
  616.         glEnd();
  617.  
  618. glBegin(GL_QUADS);
  619.         glColor3f(0.2, 0.2, 0.2);
  620.         glVertex3f(44,0.01,-200); /* road */
  621.         glColor3f(0.2, 0.2, 0.2);
  622.         glVertex3f(44,0.01,160);
  623.         glColor3f(0.2, 0.2, 0.2);
  624.         glVertex3f(54,0.01,160);
  625.         glColor3f(0.2, 0.2, 0.2);
  626.         glVertex3f(54,0.01,-200);
  627.         glEnd();
  628.  
  629.         glBegin(GL_QUADS);
  630.         glColor3f(0.2, 0.2, 0.2);
  631.         glVertex3f(54,0.01,-180); /* road */
  632.         glColor3f(0.2, 0.2, 0.2);
  633.         glVertex3f(54,0.01,-160);
  634.         glColor3f(0.2, 0.2, 0.2);
  635.         glVertex3f(200,0.01,-160);
  636.         glColor3f(0.2, 0.2, 0.2);
  637.         glVertex3f(200,0.01,-180);
  638.         glEnd();
  639.  
  640.  
  641. glBegin(GL_QUADS);
  642.         glColor3f(0.2, 0.2, 0.2);
  643.         glVertex3f(18,0.01,160); /* road */
  644.         glColor3f(0.2, 0.2, 0.2);
  645.         glVertex3f(18,0.01,170);
  646.         glColor3f(0.2, 0.2, 0.2);
  647.         glVertex3f(200,0.01,170);
  648.         glColor3f(0.2, 0.2, 0.2);
  649.         glVertex3f(200,0.01,160);
  650.         glEnd();
  651.  
  652.  
  653. glBegin(GL_QUADS);
  654.         glColor3f(0.2, 0.2, 0.2);
  655.         glVertex3f(-200,0.01,90); /* road */
  656.         glColor3f(0.2, 0.2, 0.2);
  657.         glVertex3f(-200,0.01,100);
  658.         glColor3f(0.2, 0.2, 0.2);
  659.         glVertex3f(0,0.01,100);
  660.         glColor3f(0.2, 0.2, 0.2);
  661.         glVertex3f(0,0.01,90);
  662.         glEnd();
  663.  
  664. glBegin(GL_QUADS);
  665.         glColor3f(0.2, 0.2, 0.2);
  666.         glVertex3f(-90,0.01,-200); /* road */
  667.         glColor3f(0.2, 0.2, 0.2);
  668.         glVertex3f(-90,0.01,90);
  669.         glColor3f(0.2, 0.2, 0.2);
  670.         glVertex3f(-80,0.01,90);
  671.         glColor3f(0.2, 0.2, 0.2);
  672.         glVertex3f(-80,0.01,-200);
  673.         glEnd();
  674.     house1();
  675.     glFlush();
  676.     glutSwapBuffers();
  677.  
  678.  
  679. }
  680.  
  681.  
  682. void keyboard(unsigned char key, int x, int y)
  683. {
  684.     switch (key)
  685.     {
  686.     case 'a':
  687.     case 'A':
  688.         glTranslatef(5.0, 0.0, 0.0);
  689.         break;
  690.     case 'd':
  691.     case 'D':
  692.         glTranslatef(-5.0, 0.0, 0.0);
  693.         break;
  694.     case 'w':
  695.     case 'W':
  696.         glTranslatef(0.0, 0.0, 5.0);
  697.         break;
  698.     case 's':
  699.     case 'S':
  700.         glTranslatef(0.0, 0.0, -5.0);
  701.         break;
  702.     case 'q':
  703.     case 'Q':
  704.             glRotatef(-2,1.0,0.0,0.0);
  705.  
  706.     case 'e':
  707.     case 'E':
  708.             glRotatef(2,0.0,1.0,0.0);
  709.  
  710.     }
  711.     display();
  712. }
  713.  
  714. void resize(int width, int height)
  715. {
  716.     if (height == 0) height = 1;
  717.  
  718.     glMatrixMode(GL_PROJECTION);
  719.     glLoadIdentity();
  720.  
  721. gluPerspective(80.0, width / height, 1.0, 600.0);
  722.  
  723.     glTranslatef(0.0, -15.0, -320.0);
  724.  
  725.     glMatrixMode(GL_MODELVIEW);
  726. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement