Advertisement
FaisalAhemdBijoy

asik 56

Apr 25th, 2021
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 25.09 KB | None | 0 0
  1. #include<GL/gl.h>
  2. #include <GL/glu.h>
  3. #include <GL/glut.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <windows.h>
  7. #include<math.h>
  8. #include<iostream>
  9. using namespace std;
  10.  
  11. const int width = 500;
  12. const int height = 400;
  13. const float rat = 1.0 * width / height;
  14.  
  15. GLfloat eyeX = 0;
  16. GLfloat eyeY = 18;
  17. GLfloat eyeZ = 30;
  18.  
  19. GLfloat lookX = 0;
  20. GLfloat lookY = 5;
  21. GLfloat lookZ = 0;
  22.  
  23. float light_height = 20;
  24. float light_width = -29.5;
  25. float light_length = -30;
  26.  
  27. float light1_height = 20;
  28. float light1_width = 29.5;
  29. float light1_length = -30;
  30.  
  31. float light2_height = 28;
  32. float light2_width = -15;
  33. float light2_length = -20;
  34.  
  35. float spt_cutoff = 30;
  36.  
  37. float rot = 0, f_spin = 0.0, d_spin = 0.0, c_spin1 = 360.0, c_spin2 = 360.0;
  38.  
  39. bool t = true, t1 = true, t2 = false;
  40.  
  41. bool flagRot = false, flagDoor = true, flagClock=false;
  42.  
  43. static GLfloat v_cube[8][3] =
  44. {
  45.     {0,0,0},
  46.     {0,0,1},
  47.     {0,1,0},
  48.     {0,1,1},
  49.  
  50.     {1,0,0},
  51.     {1,0,1},
  52.     {1,1,0},
  53.     {1,1,1}
  54. };
  55.  
  56. static GLubyte c_ind[6][4] =
  57. {
  58.     {0,2,6,4},
  59.     {1,5,7,3},
  60.     {0,4,5,1},
  61.     {2,3,7,6},
  62.     {0,1,3,2},
  63.     {4,6,7,5}
  64. };
  65.  
  66. static void getNormal3p(GLfloat x1, GLfloat y1, GLfloat z1, GLfloat x2, GLfloat y2, GLfloat z2, GLfloat x3, GLfloat y3, GLfloat z3)
  67. {
  68.     GLfloat Ux, Uy, Uz, Vx, Vy, Vz, Nx, Ny, Nz;
  69.  
  70.     Ux = x2-x1;
  71.     Uy = y2-y1;
  72.     Uz = z2-z1;
  73.  
  74.     Vx = x3-x1;
  75.     Vy = y3-y1;
  76.     Vz = z3-z1;
  77.  
  78.     Nx = Uy*Vz - Uz*Vy;
  79.     Ny = Uz*Vx - Ux*Vz;
  80.     Nz = Ux*Vy - Uy*Vx;
  81.  
  82.     glNormal3f(Nx,Ny,Nz);
  83. }
  84.  
  85. void cube(float R=0.5, float G=0.5, float B=0.5, bool em=false , bool l = false)
  86. {
  87.  
  88.     GLfloat mat_no[] = {0, 0, 0, 1.0};
  89.     GLfloat mat_amb[] = {R,G,B,1};
  90.     GLfloat mat_diff[] = {R,G,B,1};
  91.     GLfloat mat_spec[] = {1,1,1,1};
  92.     GLfloat mat_sh[] = {30};
  93.  
  94.     GLfloat mat_em[] = {1,1,1,1};
  95.  
  96.     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_amb);
  97.     glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diff);
  98.     glMaterialfv(GL_FRONT, GL_SPECULAR, mat_spec);
  99.     glMaterialfv(GL_FRONT, GL_SHININESS, mat_sh);
  100.  
  101.     if(em && l)
  102.     {
  103.         glMaterialfv(GL_FRONT, GL_EMISSION, mat_em);
  104.     }
  105.     else
  106.     {
  107.         glMaterialfv(GL_FRONT, GL_EMISSION, mat_no);
  108.     }
  109.  
  110.     glBegin(GL_QUADS);
  111.     for (GLint i = 0; i <6; i++)
  112.     {
  113.         getNormal3p(v_cube[c_ind[i][0]][0], v_cube[c_ind[i][0]][1], v_cube[c_ind[i][0]][2],
  114.                     v_cube[c_ind[i][1]][0], v_cube[c_ind[i][1]][1], v_cube[c_ind[i][1]][2],
  115.                     v_cube[c_ind[i][2]][0], v_cube[c_ind[i][2]][1], v_cube[c_ind[i][2]][2]);
  116.  
  117.         for (GLint j=0; j<4; j++)
  118.         {
  119.             glVertex3fv(&v_cube[c_ind[i][j]][0]);
  120.         }
  121.     }
  122.     glEnd();
  123. }
  124.  
  125. void tube1()
  126. {
  127.     float t_length = 16;
  128.     float t_width = 1;
  129.  
  130.     glPushMatrix();
  131.     glTranslatef(-29.5,20,0);
  132.  
  133.     glPushMatrix();
  134.     glScalef(t_width,t_width,t_length);
  135.     glTranslatef(-0.5,0,-0.5);
  136.     cube(1,1,1,true,t);
  137.     glPopMatrix();
  138.  
  139.     glPushMatrix();
  140.     glTranslatef(0,0,t_length/2+t_width/2);
  141.     glScalef(t_width,t_width,t_width);
  142.     glTranslatef(-0.5,0,-0.5);
  143.     cube(0.2,0.2,0.2);
  144.     glPopMatrix();
  145.  
  146.     glPushMatrix();
  147.     glTranslatef(0,0,-t_length/2-t_width/2);
  148.     glScalef(t_width,t_width,t_width);
  149.     glTranslatef(-0.5,0,-0.5);
  150.     cube(0.2,0.2,0.2);
  151.     glPopMatrix();
  152.  
  153.     glPopMatrix();
  154.  
  155. }
  156.  
  157. void tube2()
  158. {
  159.     float t_length = 16;
  160.     float t_width = 1;
  161.  
  162.     glPushMatrix();
  163.     glTranslatef(29.5,20,0);
  164.  
  165.     glPushMatrix();
  166.     glScalef(t_width,t_width,t_length);
  167.     glTranslatef(-0.5,0,-0.5);
  168.     cube(1,1,1,true,t1);
  169.     glPopMatrix();
  170.  
  171.     glPushMatrix();
  172.     glTranslatef(0,0,t_length/2+t_width/2);
  173.     glScalef(t_width,t_width,t_width);
  174.     glTranslatef(-0.5,0,-0.5);
  175.     cube(0.2,0.2,0.2);
  176.     glPopMatrix();
  177.  
  178.     glPushMatrix();
  179.     glTranslatef(0,0,-t_length/2-t_width/2);
  180.     glScalef(t_width,t_width,t_width);
  181.     glTranslatef(-0.5,0,-0.5);
  182.     cube(0.2,0.2,0.2);
  183.     glPopMatrix();
  184.  
  185.     glPopMatrix();
  186.  
  187. }
  188.  
  189. void light()
  190. {
  191.  
  192.     GLfloat light_no[] = {0, 0, 0, 1.0};
  193.     GLfloat light_amb[] = {0.1, 0.1, 0.1, 1.0};
  194.     GLfloat light_dif[] = {1,1,1,1};
  195.     GLfloat light_spec[] = {1,1,1,1};
  196.     GLfloat light_pos[] = {light_width,light_height,light_length,1.0};
  197.  
  198.     glEnable(GL_LIGHT0);
  199.  
  200.     if(t)
  201.     {
  202.         glLightfv(GL_LIGHT0, GL_AMBIENT, light_amb);
  203.     }
  204.     else
  205.     {
  206.         glLightfv(GL_LIGHT0, GL_AMBIENT, light_no);
  207.     }
  208.     if(t)
  209.     {
  210.         glLightfv(GL_LIGHT0, GL_DIFFUSE, light_dif);
  211.     }
  212.     else
  213.     {
  214.         glLightfv(GL_LIGHT0, GL_DIFFUSE, light_no);
  215.     }
  216.     if(t)
  217.     {
  218.         glLightfv(GL_LIGHT0, GL_SPECULAR, light_spec);
  219.     }
  220.     else
  221.     {
  222.         glLightfv(GL_LIGHT0, GL_SPECULAR, light_no);
  223.     }
  224.  
  225.     glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
  226.  
  227. }
  228.  
  229. void light1()
  230. {
  231.  
  232.     GLfloat light1_no[] = {0, 0, 0, 1.0};
  233.     GLfloat light1_amb[] = {0.1, 0.1, 0.1, 1.0};
  234.     GLfloat light1_dif[] = {1,1,1,1};
  235.     GLfloat light1_spec[] = {1,1,1,1};
  236.     GLfloat light1_pos[] = {light1_width,light1_height,light1_length,1.0};
  237.  
  238.     glEnable(GL_LIGHT1);
  239.  
  240.     if(t1)
  241.     {
  242.         glLightfv(GL_LIGHT1, GL_AMBIENT, light1_amb);
  243.     }
  244.     else
  245.     {
  246.         glLightfv(GL_LIGHT1, GL_AMBIENT, light1_no);
  247.     }
  248.     if(t1)
  249.     {
  250.         glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_dif);
  251.     }
  252.     else
  253.     {
  254.         glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_no);
  255.     }
  256.     if(t1)
  257.     {
  258.         glLightfv(GL_LIGHT1, GL_SPECULAR, light1_spec);
  259.     }
  260.     else
  261.     {
  262.         glLightfv(GL_LIGHT1, GL_SPECULAR, light1_no);
  263.     }
  264.  
  265.     glLightfv(GL_LIGHT1, GL_POSITION, light1_pos);
  266.  
  267. }
  268.  
  269. void light2()
  270. {
  271.  
  272.     GLfloat light2_no[] = {0, 0, 0, 1.0};
  273.     GLfloat light2_amb[] = {0.1, 0.1, 0.1, 1.0};
  274.     GLfloat light2_dif[] = {1,1,1,1};
  275.     GLfloat light2_spec[] = {1,1,1,1};
  276.     GLfloat light2_pos[] = {light2_width,light2_height,light2_length,1.0};
  277.  
  278.     glEnable(GL_LIGHT2);
  279.  
  280.     if(t2)
  281.     {
  282.         glLightfv(GL_LIGHT2, GL_AMBIENT, light2_amb);
  283.     }
  284.     else
  285.     {
  286.         glLightfv(GL_LIGHT2, GL_AMBIENT, light2_no);
  287.     }
  288.     if(t2)
  289.     {
  290.         glLightfv(GL_LIGHT2, GL_DIFFUSE, light2_dif);
  291.     }
  292.     else
  293.     {
  294.         glLightfv(GL_LIGHT2, GL_DIFFUSE, light2_no);
  295.     }
  296.     if(t2)
  297.     {
  298.         glLightfv(GL_LIGHT2, GL_SPECULAR, light2_spec);
  299.     }
  300.     else
  301.     {
  302.         glLightfv(GL_LIGHT2, GL_SPECULAR, light2_no);
  303.     }
  304.  
  305.     glLightfv(GL_LIGHT2, GL_POSITION, light2_pos);
  306.  
  307.     GLfloat spt_dir[] = {1,0,-1,1};
  308.     GLfloat spt_ct[] = {spt_cutoff};
  309.     glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, spt_dir);
  310.     glLightfv(GL_LIGHT2, GL_SPOT_CUTOFF, spt_ct);
  311. }
  312.  
  313. void spot_light()
  314. {
  315.     float s_height = 2;
  316.     float s_width = 5;
  317.     float s_length = 5;
  318.  
  319.     glPushMatrix();
  320.     glTranslatef(-15,24,-15);
  321.  
  322.     glPushMatrix();
  323.     glScalef(s_width,s_height,s_length);
  324.     glTranslatef(-0.5,0,-0.5);
  325.     cube(1,1,1,true,t2);
  326.     glPopMatrix();
  327.  
  328.     glPushMatrix();
  329.     glTranslatef(0,0,s_length/2+0.1);
  330.     glScalef(4.5,1.5,0.1);
  331.     glTranslatef(-0.5,0.1,-0.5);
  332.     cube(0.7,0.7,0.8);
  333.     glPopMatrix();
  334.  
  335.     glPushMatrix();
  336.     glTranslatef(-1.8,1.3,s_length/2+0.2);
  337.     glScalef(0.5,0.2,0.2);
  338.     glTranslatef(-0.5,0,-0.5);
  339.     cube(0.1,0.1,0.1);
  340.     glPopMatrix();
  341.  
  342.     glPushMatrix();
  343.     glTranslatef(-1,1.3,s_length/2+0.2);
  344.     glScalef(0.5,0.2,0.2);
  345.     glTranslatef(-0.5,0,-0.5);
  346.     cube(0.1,0.1,0.1);
  347.     glPopMatrix();
  348.  
  349.     glPushMatrix();
  350.     glTranslatef(-1,0.8,s_length/2+0.2);
  351.     glScalef(0.5,0.2,0.2);
  352.     glTranslatef(-0.5,0,-0.5);
  353.     cube(0.1,0.1,0.1);
  354.     glPopMatrix();
  355.  
  356.     glPushMatrix();
  357.     glTranslatef(-1.8,0.8,s_length/2+0.2);
  358.     glScalef(0.5,0.2,0.2);
  359.     glTranslatef(-0.5,0,-0.5);
  360.     cube(0.1,0.1,0.1);
  361.     glPopMatrix();
  362.  
  363.     glPushMatrix();
  364.     glTranslatef(-0.3,0.8,s_length/2+0.2);
  365.     glScalef(0.2,0.2,0.2);
  366.     glTranslatef(-0.5,0,-0.5);
  367.     cube(1,0.1,0.1);
  368.     glPopMatrix();
  369.  
  370.     glPushMatrix();
  371.     glTranslatef(0.2,0.8,s_length/2+0.2);
  372.     glScalef(0.2,0.2,0.2);
  373.     glTranslatef(-0.5,0,-0.5);
  374.     cube(1,1,0.1);
  375.     glPopMatrix();
  376.  
  377.     glPushMatrix();
  378.     glTranslatef(-0.3,1.3,s_length/2+0.2);
  379.     glScalef(0.2,0.2,0.2);
  380.     glTranslatef(-0.5,0,-0.5);
  381.     cube(0,1,0.9);
  382.     glPopMatrix();
  383.  
  384.     glPushMatrix();
  385.     glTranslatef(0.2,1.3,s_length/2+0.2);
  386.     glScalef(0.2,0.2,0.2);
  387.     glTranslatef(-0.5,0,-0.5);
  388.     cube(0.7,0.7,0.7);
  389.     glPopMatrix();
  390.  
  391.     glPushMatrix();
  392.     glTranslatef(1.8,0.5,s_length/2+0.2);
  393.     glScalef(0.8,0.3,0.2);
  394.     glTranslatef(-0.5,0,-0.5);
  395.     cube(0.1,0.1,0.1);
  396.     glPopMatrix();
  397.  
  398.     glPushMatrix();
  399.     glTranslatef(0,s_height,0);
  400.     glScalef(0.7,4,0.7);
  401.     glTranslatef(-0.5,0,-0.5);
  402.     cube(0.8,0.8,0.8);
  403.     glPopMatrix();
  404.  
  405.     glPopMatrix();
  406.  
  407. }
  408.  
  409. void axes()
  410. {
  411.     float length = 10;
  412.     float width = 0.3;
  413.  
  414.     // X-axis
  415.     glPushMatrix();
  416.     glTranslatef(length/2,0,0);
  417.     glScalef(length,width,width);
  418.     glTranslatef(-0.5,-0.5,-0.5);
  419.     cube(0.8,0.1,0.1);
  420.     glPopMatrix();
  421.  
  422.     // Y-axis
  423.     glPushMatrix();
  424.     glTranslatef(0,length/2,0);
  425.     glScalef(width,length,width);
  426.     glTranslatef(-0.5,-0.5,-0.5);
  427.     cube(0.1,0.8,0.1);
  428.     glPopMatrix();
  429.  
  430.     // Z-axis
  431.     glPushMatrix();
  432.     glTranslatef(0,0,length/2);
  433.     glScalef(width,width,length);
  434.     glTranslatef(-0.5,-0.5,-0.5);
  435.     cube(0.1,0.1,0.8);
  436.     glPopMatrix();
  437. }
  438.  
  439. void walll()
  440. {
  441.     float length = 60;
  442.     float width = 1;
  443.     float height = 30;
  444.     //floor
  445.     glPushMatrix();
  446.     glScalef(length,width,length);
  447.     glTranslatef(-0.5,-1,-0.5);
  448.     cube(0.9,0.9,0.9);
  449.     glPopMatrix();
  450.  
  451.     glPushMatrix();
  452.     glTranslatef(length/2,-width,0);
  453.     glScalef(width,height,length);
  454.     glTranslatef(0,0,-0.5);
  455.     cube(0.741, 0.718, 0.420);
  456.     glPopMatrix();
  457.  
  458.     glPushMatrix();
  459.     glTranslatef(-length/2-1,-width,0);
  460.     glScalef(width,height,length);
  461.     glTranslatef(0,0,-0.5);
  462.     cube(0.741, 0.718, 0.420);
  463.     glPopMatrix();
  464.  
  465.     glPushMatrix();
  466.     glTranslatef(0,-width,-length/2-1);
  467.     glScalef(length,height,width);
  468.     glTranslatef(-0.5,0,0);
  469.     cube(0.741, 0.718, 0.420);
  470.     glPopMatrix();
  471.  
  472.     //blackboard
  473.     glPushMatrix();
  474.     glTranslatef(0,height/4,-length/2);
  475.     glScalef(length/2,height/3,width);
  476.     glTranslatef(-0.5,0,0);
  477.     cube(0.1,0.1,0.1);
  478.     glPopMatrix();
  479.     //top
  480.     glPushMatrix();
  481.     glTranslatef(0,height,0);
  482.     glScalef(length,width,length);
  483.     glTranslatef(-0.5,-1,-0.5);
  484.     cube(0.941, 0.902, 0.54);
  485.     glPopMatrix();
  486. }
  487.  
  488. void chair()
  489. {
  490.     float height=5;
  491.     float width=8;
  492.     float length=4;
  493.  
  494.     float base_height=0.8;
  495.     float leg_height=height-base_height;
  496.     float leg_width=0.7;
  497.  
  498.     glPushMatrix();
  499.     glTranslatef(0,leg_height,0);
  500.  
  501.     glPushMatrix();
  502.     glScalef(width,base_height,length);
  503.     glTranslatef(-0.5,0,-0.5);
  504.     cube(0.53,0.39,0.28);
  505.     glPopMatrix();
  506.  
  507.     //legs
  508.     glPushMatrix();
  509.     glTranslatef(width/2-leg_width/2,0,length/2-leg_width/2);
  510.     glScalef(leg_width,leg_height,leg_width);
  511.     glTranslatef(-0.5,-1,-0.5);
  512.     cube(1,0.8,0);
  513.     glPopMatrix();
  514.  
  515.     glPushMatrix();
  516.     glTranslatef(width/2-leg_width/2,0,-(length/2-leg_width/2));
  517.     glScalef(leg_width,leg_height,leg_width);
  518.     glTranslatef(-0.5,-1,-0.5);
  519.     cube(1,0.8,0);
  520.     glPopMatrix();
  521.  
  522.     glPushMatrix();
  523.     glTranslatef(-(width/2-leg_width/2),0,-(length/2-leg_width/2));
  524.     glScalef(leg_width,leg_height,leg_width);
  525.     glTranslatef(-0.5,-1,-0.5);
  526.     cube(1,0.8,0);
  527.     glPopMatrix();
  528.  
  529.     glPushMatrix();
  530.     glTranslatef(-(width/2-leg_width/2),0,(length/2-leg_width/2));
  531.     glScalef(leg_width,leg_height,leg_width);
  532.     glTranslatef(-0.5,-1,-0.5);
  533.     cube(1,0.8,0);
  534.     glPopMatrix();
  535.  
  536.     //chair
  537.     glPushMatrix();
  538.     glTranslatef(0,-leg_height/2,length);
  539.     glScalef(width/2,base_height,length/2);
  540.     glTranslatef(-0.5,0,-0.5);
  541.     cube(1.0,0,0);
  542.     glPopMatrix();
  543.     //legs
  544.     glPushMatrix();
  545.     glTranslatef(width/4-leg_width/4,-leg_height/2,length+(length/4-leg_width/4));
  546.     glScalef(leg_width/2,leg_height/2,leg_width/2);
  547.     glTranslatef(-0.5,-1,-0.5);
  548.     cube(1,0.8,0);
  549.     glPopMatrix();
  550.  
  551.     glPushMatrix();
  552.     glTranslatef(width/4-leg_width/4,-leg_height/2,length-(length/4-leg_width/4));
  553.     glScalef(leg_width/2,leg_height/2,leg_width/2);
  554.     glTranslatef(-0.5,-1,-0.5);
  555.     cube(1,0.8,0);
  556.     glPopMatrix();
  557.  
  558.     glPushMatrix();
  559.     glTranslatef(-(width/4-leg_width/4),-leg_height/2,length+(length/4-leg_width/4));
  560.     glScalef(leg_width/2,leg_height/2,leg_width/2);
  561.     glTranslatef(-0.5,-1,-0.5);
  562.     cube(1,0.8,0);
  563.     glPopMatrix();
  564.  
  565.     glPushMatrix();
  566.     glTranslatef(-(width/4-leg_width/4),-leg_height/2,length-(length/4-leg_width/4));
  567.     glScalef(leg_width/2,leg_height/2,leg_width/2);
  568.     glTranslatef(-0.5,-1,-0.5);
  569.     cube(1,0.8,0);
  570.     glPopMatrix();
  571.     //
  572.     glPushMatrix();
  573.     glTranslatef((width/4-leg_width/4)/2,-leg_height/2,length-(length/4-leg_width/4)+length/2.5);
  574.     glScalef(leg_width/2,leg_height/4,leg_width/2);
  575.     glTranslatef(-0.5,0.4,-0.5);
  576.     cube(0,0.2,0);
  577.     glPopMatrix();
  578.  
  579.     glPushMatrix();
  580.     glTranslatef(-(width/4-leg_width/4)/2,-leg_height/2,length-(length/4-leg_width/4)+length/2.5);
  581.     glScalef(leg_width/2,leg_height/4,leg_width/2);
  582.     glTranslatef(-0.5,0.4,-0.5);
  583.     cube(0,0.2,0);
  584.     glPopMatrix();
  585.     //
  586.     glPushMatrix();
  587.     glTranslatef(0,-leg_height/1.3,length-(length/4-leg_width/4)+length/2.5);
  588.     glScalef(width/2,leg_height/2.5,leg_width/2);
  589.     glTranslatef(-0.5,1.5,-0.5);
  590.     cube(1,1,0);
  591.     glPopMatrix();
  592.  
  593.     glPopMatrix();
  594. }
  595.  
  596. void chair_table()
  597. {
  598.     for (float i = -25 ; i<24 ; i = i + 12)
  599.     {
  600.         for (float j = 23 ; j>-5 ; j = j - 9)
  601.         {
  602.             glPushMatrix();
  603.             glTranslatef(i,0,j);
  604.             chair();
  605.             glPopMatrix();
  606.         }
  607.     }
  608.  
  609. }
  610.  
  611. void fan()
  612. {
  613.     float height = 30;
  614.  
  615.     float m_width = 4;
  616.     float m_height = 2;
  617.     float angle = 0;
  618.  
  619.     float s_width = 2.0;
  620.     float s_height = 20.0;
  621.  
  622.  
  623.     for(int i=0; i<=360 ; i=i+10)
  624.     {
  625.  
  626.         glPushMatrix();
  627.         glTranslatef(0,height-1.5,0);
  628.         glRotatef(i,0,1,0);
  629.         glScalef(m_width,m_height/8,m_height);
  630.         glTranslatef(-0.5,0,-0.5);
  631.         cube(0.753, 0.753, 0.753);
  632.         glPopMatrix();
  633.  
  634.     }
  635.  
  636.     glPushMatrix();
  637.     glTranslatef(0,height-m_width-m_height/8,0);
  638.     glScalef(1,m_width,1);
  639.     glTranslatef(-0.5,0,-0.5);
  640.     cube(1,0,0);
  641.     glPopMatrix();
  642.  
  643.     glPushMatrix();
  644.     glRotatef(f_spin,0,1,0);
  645.     for(int i=0; i<=360 ; i=i+10)
  646.     {
  647.  
  648.         glPushMatrix();
  649.         glTranslatef(0,height-m_width-m_height/8-m_height,0);
  650.         glRotatef(i,0,1,0);
  651.         glScalef(m_width,m_height,m_height);
  652.         glTranslatef(-0.5,0,-0.5);
  653.         cube(0.000, 0.749, 1.000);
  654.         glPopMatrix();
  655.  
  656.     }
  657.  
  658.     glPushMatrix();
  659.     glTranslatef(0,height-m_width-m_height/8-m_height+1,0);
  660.     glScalef(s_height,0.5,s_width);
  661.     glTranslatef(-0.5,0,-0.5);
  662.     cube(0.196, 0.804, 0.196);
  663.     glPopMatrix();
  664.  
  665.     glPushMatrix();
  666.     glTranslatef(0,height-m_width-m_height/8-m_height+1,0);
  667.     glScalef(s_width,0.5,s_height);
  668.     glTranslatef(-0.5,0,-0.5);
  669.     cube(0.196, 0.804, 0.196);
  670.     glPopMatrix();
  671.  
  672.     glPopMatrix();
  673.  
  674. }
  675.  
  676. void desk()
  677. {
  678.     float height=2;
  679.     float width=25;
  680.     float length=8;
  681.  
  682.     float base_height=0.8;
  683.     float leg_height=height-base_height;
  684.     float leg_width=0.7;
  685.  
  686.     glPushMatrix();
  687.     glTranslatef(0,0,-(30-length/2)+1);
  688.  
  689.     glPushMatrix();
  690.     glTranslatef(0,leg_height,0);
  691.  
  692.     glPushMatrix();
  693.     glScalef(width,base_height,length);
  694.     glTranslatef(-0.5,0,-0.5);
  695.     cube(0.53,0.39,0.28);
  696.     glPopMatrix();
  697.  
  698.     //legs
  699.     glPushMatrix();
  700.     glTranslatef(width/2-leg_width/2,0,length/2-leg_width/2);
  701.     glScalef(leg_width,leg_height,leg_width);
  702.     glTranslatef(-0.5,-1,-0.5);
  703.     cube(0.502, 0.502, 0.000);
  704.     glPopMatrix();
  705.  
  706.     glPushMatrix();
  707.     glTranslatef(width/2-leg_width/2,0,-(length/2-leg_width/2));
  708.     glScalef(leg_width,leg_height,leg_width);
  709.     glTranslatef(-0.5,-1,-0.5);
  710.     cube(0.502, 0.502, 0.000);
  711.     glPopMatrix();
  712.  
  713.     glPushMatrix();
  714.     glTranslatef(-(width/2-leg_width/2),0,-(length/2-leg_width/2));
  715.     glScalef(leg_width,leg_height,leg_width);
  716.     glTranslatef(-0.5,-1,-0.5);
  717.     cube(0.502, 0.502, 0.000);
  718.     glPopMatrix();
  719.  
  720.     glPushMatrix();
  721.     glTranslatef(-(width/2-leg_width/2),0,(length/2-leg_width/2));
  722.     glScalef(leg_width,leg_height,leg_width);
  723.     glTranslatef(-0.5,-1,-0.5);
  724.     cube(0.502, 0.502, 0.000);
  725.     glPopMatrix();
  726.     glPopMatrix();
  727.  
  728.     //
  729.     glPushMatrix();
  730.     glTranslatef(0,0,length);
  731.     glScalef(width/3,length*1.5,length/2);
  732.     glTranslatef(-0.5,0,-0.5);
  733.     cube(0.53,0.39,0.28);
  734.     glPopMatrix();
  735.  
  736.     glPopMatrix();
  737.  
  738. }
  739.  
  740. void wardrobe()
  741. {
  742.     float war_hieght = 15;
  743.     float war_width = 7;
  744.     float war_length = 10;
  745.  
  746.     glPushMatrix();
  747.     glTranslatef(30-war_width/2,0,-(30-war_length/2)+2);
  748.     glPushMatrix();
  749.     glScalef(war_width,war_hieght,war_length);
  750.     glTranslatef(-0.5,0,-0.5);
  751.     cube(0.824, 0.412, 0.118);
  752.     glPopMatrix();
  753.  
  754.     glPushMatrix();
  755.     glTranslatef(-war_width/2,0,war_length/2);
  756.     glScalef(war_width/25,war_hieght,war_length/25);
  757.     glTranslatef(-0.5,0,-0.5);
  758.     cube(0.545, 0.271, 0.075);
  759.     glPopMatrix();
  760.  
  761.     glPushMatrix();
  762.     glTranslatef(-war_width/2,0,-war_length/2);
  763.     glScalef(war_width/25,war_hieght,war_length/25);
  764.     glTranslatef(-0.5,0,-0.5);
  765.     cube(0.545, 0.271, 0.075);
  766.     glPopMatrix();
  767.  
  768.     glPushMatrix();
  769.     glTranslatef(-war_width/2,0,0);
  770.     glScalef(war_width/25,war_hieght,war_length/25);
  771.     glTranslatef(-0.5,0,-0.5);
  772.     cube(0.545, 0.271, 0.075);
  773.     glPopMatrix();
  774.  
  775.  
  776.     glPushMatrix();
  777.     glTranslatef(war_width/2,0,war_length/2);
  778.     glScalef(war_width/25,war_hieght,war_length/25);
  779.     glTranslatef(-0.5,0,-0.5);
  780.     cube(0.545, 0.271, 0.075);
  781.     glPopMatrix();
  782.  
  783.     glPushMatrix();
  784.     glTranslatef(-war_width/2,war_hieght/2,war_length/13);
  785.     glScalef(0.3,2.5,0.3);
  786.     glTranslatef(-0.5,0,-0.5);
  787.     cube(0.439, 0.502, 0.565);
  788.     glPopMatrix();
  789.  
  790.     glPushMatrix();
  791.     glTranslatef(-war_width/2,war_hieght/2,-war_length/13);
  792.     glScalef(0.3,2.5,0.3);
  793.     glTranslatef(-0.5,0,-0.5);
  794.     cube(0.439, 0.502, 0.565);
  795.     glPopMatrix();
  796.  
  797.     glPopMatrix();
  798. }
  799.  
  800. void door()
  801. {
  802.     float d_height = 15;
  803.     float d_length = 8;
  804.     float d_width = 0.8;
  805.  
  806.     glPushMatrix();
  807.     glTranslatef(-30+d_width/2+0.5,0,-25);
  808.  
  809.     glPushMatrix();
  810.     glRotatef(d_spin,0,1,0);
  811.     glPushMatrix();
  812.     glScalef(d_width,d_height,d_length);
  813.     glTranslatef(-0.5,0,0);
  814.     cube(0.737, 0.561, 0.561);
  815.     glPopMatrix();
  816.     glPopMatrix();
  817.  
  818.     glPushMatrix();
  819.     glTranslatef(-d_width/2,0,0);
  820.     glScalef(d_width,d_height,d_length);
  821.     glTranslatef(-0.5,0,0);
  822.     cube(1, 1, 1);
  823.     glPopMatrix();
  824.  
  825.     glPushMatrix();
  826.     glTranslatef(0,0,d_length);
  827.     glScalef(d_width+0.1,d_height,d_length/20);
  828.     glTranslatef(-0.5,0,0);
  829.     cube(0.824, 0.706, 0.549);
  830.     glPopMatrix();
  831.  
  832.     glPushMatrix();
  833.     glTranslatef(0,0,-0.3);
  834.     glScalef(d_width,d_height,d_length/20);
  835.     glTranslatef(-0.5,0,0);
  836.     cube(0.824, 0.706, 0.549);
  837.     glPopMatrix();
  838.  
  839.     glPushMatrix();
  840.     glTranslatef(0,15,-0.4);
  841.     glScalef(d_width,d_height/35,d_length+1);
  842.     glTranslatef(-0.5,0,0);
  843.     cube(0.824, 0.706, 0.549);
  844.     glPopMatrix();
  845.  
  846.     glPopMatrix();
  847. }
  848.  
  849. void clock()
  850. {
  851.     float c_length = 1;
  852.     float c_width = 7;
  853.     float c_height = 7;
  854.  
  855.     glPushMatrix();
  856.     glTranslatef(0,20,-30+c_length/2);
  857.  
  858.     glPushMatrix();
  859.     glScalef(c_width*1.5,c_height,c_length);
  860.     glTranslatef(-0.5,0,-0.5);
  861.     cube(1.000, 0.855, 0.725);
  862.     glPopMatrix();
  863.  
  864.     glPushMatrix();
  865.     glTranslatef(0,c_height/2,c_length/2);
  866.     glRotatef(c_spin1,0,0,1);
  867.     glScalef(c_width/2-0.2,0.3,c_length/4);
  868.     glTranslatef(0,-0.5,-0.5);
  869.     cube(0.1,0.1,0.1);
  870.     glPopMatrix();
  871.  
  872.     glPushMatrix();
  873.     glTranslatef(0,c_height/2,c_length/2);
  874.     glRotatef(c_spin2,0,0,1);
  875.     glScalef(c_width/3,0.3,c_length/4);
  876.     glTranslatef(0,-0.5,-0.5);
  877.     cube(1,0.1,0.1);
  878.     glPopMatrix();
  879.  
  880.     glPushMatrix();
  881.     glTranslatef(0,c_height-1.5,c_length/2);
  882.     glScalef(0.4,0.9,c_length/4);
  883.     glTranslatef(-0.5,0,-0.5);
  884.     cube(0.1,0.1,0.1);
  885.     glPopMatrix();
  886.  
  887.     glPushMatrix();
  888.     glTranslatef(c_width/2+1,c_height/2,c_length/2);
  889.     glScalef(0.9,0.4,c_length/4);
  890.     glTranslatef(-0.5,0,-0.5);
  891.     cube(0.1,0.1,0.1);
  892.     glPopMatrix();
  893.  
  894.     glPushMatrix();
  895.     glTranslatef(-c_width/2-1,c_height/2,c_length/2);
  896.     glScalef(0.9,0.4,c_length/4);
  897.     glTranslatef(-0.5,0,-0.5);
  898.     cube(0.1,0.1,0.1);
  899.     glPopMatrix();
  900.  
  901.     glPushMatrix();
  902.     glTranslatef(0,-c_height/2+4,c_length/2);
  903.     glScalef(0.4,0.9,c_length/4);
  904.     glTranslatef(-0.5,0,-0.5);
  905.     cube(0.1,0.1,0.1);
  906.     glPopMatrix();
  907.  
  908.     glPopMatrix();
  909. }
  910.  
  911. void grid()
  912. {
  913.     float grid_length = 60;
  914.     float grid_width = 0.06;
  915.     float floor_width = 24;
  916.  
  917.     for (int i=-floor_width; i<=floor_width; i+=8)
  918.     {
  919.         glPushMatrix();
  920.         glTranslatef(i,0,0);
  921.         glScalef(grid_width,grid_width,grid_length);
  922.         glTranslatef(-0.5,0,-0.5);
  923.         cube(0,0,0);
  924.         glPopMatrix();
  925.  
  926.         glPushMatrix();
  927.         glTranslatef(0,0,i);
  928.         glScalef(grid_length,grid_width,grid_width);
  929.         glTranslatef(-0.5,0,-0.5);
  930.         cube(0,0,0);
  931.         glPopMatrix();
  932.     }
  933.  
  934. }
  935.  
  936. void sphere()
  937. {
  938.     GLfloat m_amb[] = {1,1,0,1};
  939.     GLfloat m_diff[] = {1,1,0,1};
  940.     GLfloat m_spec[] = {1,1,1,1};
  941.     GLfloat m_sh[] = {30};
  942.  
  943.     GLfloat m_em[] = {1,1,1,1};
  944.  
  945.     glMaterialfv(GL_FRONT, GL_AMBIENT, m_amb);
  946.     glMaterialfv(GL_FRONT, GL_DIFFUSE, m_diff);
  947.     glMaterialfv(GL_FRONT, GL_SPECULAR, m_spec);
  948.     glMaterialfv(GL_FRONT, GL_SHININESS, m_sh);
  949.  
  950.     glPushMatrix();
  951.     glTranslatef(27,15,-23);
  952.  
  953.     glPushMatrix();
  954.     glTranslatef(0,5,0);
  955.     glutSolidSphere( 3, 30.0, 30.0);
  956.     glPopMatrix();
  957.  
  958.     glPushMatrix();
  959.     glScalef(0.5,2,0.5);
  960.     glTranslatef(-0.5,0,-0.5);
  961.     cube(0.1,0.1,0.1);
  962.     glPopMatrix();
  963.  
  964.     glPushMatrix();
  965.     glTranslatef(0,0,0);
  966.     glScalef(4,0.5,4);
  967.     glTranslatef(-0.5,0,-0.5);
  968.     cube(0.1,0.1,0.1);
  969.     glPopMatrix();
  970.  
  971.  
  972.  
  973.     glPopMatrix();
  974. }
  975.  
  976.  
  977. static void key(unsigned char key, int x, int y)
  978. {
  979.     switch (key)
  980.     {
  981.     case 27 :
  982.     case 'q':
  983.         exit(0);
  984.         break;
  985.  
  986.     case 't':
  987.         t=1-t;
  988.         break;
  989.  
  990.     case 'y':
  991.         t1=1-t1;
  992.         break;
  993.     case 'u':
  994.         t2=1-t2;
  995.         break;
  996.     case ',':
  997.         rot+=2;
  998.         break;
  999.     case '.':
  1000.         rot-=2;
  1001.         break;
  1002.     case 'a':
  1003.         eyeX--;
  1004.         lookX--;
  1005.         break;
  1006.     case 'd':
  1007.         eyeX++;
  1008.         lookX++;
  1009.         break;
  1010.     case 'w':
  1011.         eyeY--;
  1012.         lookY--;
  1013.         break;
  1014.     case 's':
  1015.         eyeY++;
  1016.         lookY++;
  1017.         break;
  1018.     case '+':
  1019.         eyeZ--;
  1020.         lookZ--;
  1021.         break;
  1022.     case '-':
  1023.         eyeZ++;
  1024.         lookZ++;
  1025.         break;
  1026.     case 'c':
  1027.         flagClock=true;
  1028.         break;
  1029.     case 'x':
  1030.         flagRot=true;
  1031.         break;
  1032.     case 'z':
  1033.         flagRot=false;
  1034.         flagClock=false;
  1035.         break;
  1036.     case 'k':
  1037.         if (flagDoor==true)
  1038.         {
  1039.             d_spin++;
  1040.             flagDoor = true;
  1041.             if(d_spin>90)
  1042.                 flagDoor=false;
  1043.         }
  1044.         break;
  1045.     case 'l':
  1046.         if (flagDoor==false)
  1047.         {
  1048.             d_spin--;
  1049.             flagDoor = false;
  1050.             if(d_spin<0)
  1051.                 flagDoor=true;
  1052.         }
  1053.     }
  1054.  
  1055.     glutPostRedisplay();
  1056. }
  1057.  
  1058. static void idle(void)
  1059. {
  1060.     if (flagRot == true)
  1061.     {
  1062.         f_spin = f_spin + 0.1;
  1063.         if(f_spin > 360)
  1064.             f_spin = 0;
  1065.     }
  1066.     if (flagClock == true)
  1067.     {
  1068.         c_spin1 = c_spin1 - 0.05;
  1069.         if(c_spin1 < 0)
  1070.             c_spin1 = 360;
  1071.     }
  1072.     if (flagClock == true)
  1073.     {
  1074.         c_spin2 = c_spin2 - 0.0008;
  1075.         if(c_spin2 < 0)
  1076.             c_spin2 = 360;
  1077.     }
  1078.  
  1079.     glutPostRedisplay();
  1080. }
  1081.  
  1082. static void resize(int width, int height)
  1083. {
  1084.     glViewport(width/2-height*rat/2,0,height*rat,height);
  1085.  
  1086. }
  1087.  
  1088. void display(void)
  1089. {
  1090.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1091.     glMatrixMode(GL_PROJECTION);
  1092.     glLoadIdentity();
  1093.     glFrustum(-3, 3, -3, 3, 3.0, 100.0);
  1094.  
  1095.     glMatrixMode(GL_MODELVIEW);
  1096.     glLoadIdentity();
  1097.     gluLookAt(eyeX,eyeY,eyeZ, lookX,lookY,lookZ, 0,1,0);
  1098.  
  1099.     glRotatef(rot, 0,1,0);
  1100.     axes();
  1101.     walll();
  1102.     desk();
  1103.     sphere();
  1104.     chair_table();
  1105.     fan();
  1106.     door();
  1107.     wardrobe();
  1108.     clock();
  1109.     grid();
  1110.     light();
  1111.     tube1();
  1112.     light1();
  1113.     tube2();
  1114.     light2();
  1115.     spot_light();
  1116.  
  1117.     glutSwapBuffers();
  1118. }
  1119.  
  1120. int main(int argc, char *argv[])
  1121. {
  1122.     glutInit(&argc, argv);
  1123.     glutInitWindowSize(width,height);
  1124.     glutInitWindowPosition(10,10);
  1125.     glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  1126.  
  1127.     glutCreateWindow("GLUT Shapes");
  1128.  
  1129.     glutDisplayFunc(display);
  1130.     glutKeyboardFunc(key);
  1131.     glutIdleFunc(idle);
  1132.     glutReshapeFunc(resize);
  1133.  
  1134.  
  1135.     glEnable(GL_DEPTH_TEST);
  1136.     glShadeModel( GL_SMOOTH );
  1137.     glEnable(GL_NORMALIZE);
  1138.     glEnable(GL_BLEND);
  1139.  
  1140.     glEnable(GL_LIGHTING);
  1141.  
  1142.     glutMainLoop();
  1143.  
  1144. }
  1145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement