Advertisement
FaisalAhemdBijoy

Light 44

Apr 25th, 2021
878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 19.79 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<GL/gl.h>
  3. #include <GL/glu.h>
  4. #include <GL/glut.h>
  5.  
  6. using namespace std;
  7.  
  8. const int window_width = 900;
  9. const int window_height = 550;
  10. const float rat = 1.0 * window_width / window_height;
  11.  
  12. GLfloat eyeX = 5;
  13. GLfloat eyeY = 40;
  14. GLfloat eyeZ = 50;
  15.  
  16. GLfloat lookX = 0;
  17. GLfloat lookY = 40;
  18. GLfloat lookZ = -100;
  19.  
  20. int up=0,down=0,r=0,l=0, sakib =20;
  21.  
  22. int light_1 = 0, light_2= 0, light_3 = 0;
  23.  
  24. float rot = 0, fan_rt = 0;
  25.  
  26.  
  27. static void getNormal3p(GLfloat x1, GLfloat y1, GLfloat z1, GLfloat x2, GLfloat y2, GLfloat z2, GLfloat x3, GLfloat y3, GLfloat z3)
  28. {
  29.     GLfloat Ux, Uy, Uz, Vx, Vy, Vz, Nx, Ny, Nz;
  30.  
  31.     Ux = x2-x1;
  32.     Uy = y2-y1;
  33.     Uz = z2-z1;
  34.  
  35.     Vx = x3-x1;
  36.     Vy = y3-y1;
  37.     Vz = z3-z1;
  38.  
  39.     Nx = Uy*Vz - Uz*Vy;
  40.     Ny = Uz*Vx - Ux*Vz;
  41.     Nz = Ux*Vy - Uy*Vx;
  42.  
  43.     glNormal3f(Nx,Ny,Nz);
  44. }
  45.  
  46.  
  47.  
  48. static GLfloat v_cube[8][3] =
  49. {
  50.     {0,0,0},
  51.     {0,0,1},
  52.     {0,1,0},
  53.     {0,1,1},
  54.  
  55.     {1,0,0},
  56.     {1,0,1},
  57.     {1,1,0},
  58.     {1,1,1}
  59. };
  60.  
  61. static GLubyte c_ind[6][4] =
  62. {
  63.     {0,2,6,4},
  64.     {5,7,3,1},
  65.     {0,4,5,1},
  66.     {3,7,6,2},
  67.     {0,1,3,2},
  68.     {6,7,5,4}
  69. };
  70.  
  71. static void resize(int width, int height)
  72. {
  73.     const float ar = (float) window_width / (float) window_height;
  74.  
  75.     glViewport(0, 0, window_width, window_height);
  76.     glMatrixMode(GL_PROJECTION);
  77.     glLoadIdentity();
  78.     glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
  79.  
  80.     glMatrixMode(GL_MODELVIEW);
  81.     glLoadIdentity() ;
  82. }
  83.  
  84. void cube(float colR=0.5, float colG=0.5, float colB=0.5)
  85. {
  86.     GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
  87.     GLfloat mat_ambient[] = { colR, colG, colB, 1.0 };
  88.     GLfloat mat_diffuse[] = { colR, colG, colB, 1.0 };
  89.     GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  90.     //GLfloat mat_emission[] = { 1.0, 1.0, 1.0, 1.0 };
  91.     GLfloat mat_shininess[] = {30};
  92.  
  93.     glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient);
  94.     glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse);
  95.     glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular);
  96.     glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess);
  97.  
  98.     //glMaterialfv( GL_FRONT, GL_EMISSION, mat_emission);
  99.  
  100.  
  101.  
  102.  
  103.     glBegin(GL_QUADS);
  104.     for (GLint i = 0; i <6; i++)
  105.     {
  106. //        glColor3f(colR,colG,colB);
  107. //
  108. //        colR += 0.05;
  109. //        colG += 0.05;
  110. //        colB += 0.05;
  111.                     getNormal3p(v_cube[c_ind[i][0]][0], v_cube[c_ind[i][0]][1], v_cube[c_ind[i][0]][2],
  112.                     v_cube[c_ind[i][1]][0], v_cube[c_ind[i][1]][1], v_cube[c_ind[i][1]][2],
  113.                     v_cube[c_ind[i][2]][0], v_cube[c_ind[i][2]][1], v_cube[c_ind[i][2]][2]);
  114.         for (GLint j=0; j<4; j++)
  115.         {
  116.             glVertex3fv(&v_cube[c_ind[i][j]][0]);
  117.         }
  118.     }
  119.     glEnd();
  120. }
  121.  
  122.  
  123. void fan_rotation()
  124. {
  125.     fan_rt = fan_rt+1;
  126.     if(fan_rt>360)
  127.         fan_rt =0;
  128.     glutPostRedisplay();
  129. }
  130.  
  131. void axes()
  132. {
  133.     float length = 10;
  134.     float width = 0.3;
  135.  
  136.     // X-axis
  137.     glPushMatrix();
  138.     glTranslatef(length/2,0,0);
  139.     glScalef(length,width,width);
  140.     glTranslatef(-0.5,-0.5,-0.5);
  141.     cube(1,0,0); //RED Line
  142.     glPopMatrix();
  143.  
  144.     // Y-axis
  145.     glPushMatrix();
  146.     glTranslatef(0,length/2,0);
  147.     glScalef(width,length,width);
  148.     glTranslatef(-0.5,-0.5,-0.5);
  149.     cube(0,1,0); //GREEN Line
  150.     glPopMatrix();
  151.  
  152.     // Z-axis
  153.     glPushMatrix();
  154.     glTranslatef(0,0,length/2);
  155.     glScalef(width,width,length);
  156.     glTranslatef(-0.5,-0.5,-0.5);
  157.     cube(0,0,1); //BLUE Line
  158.     glPopMatrix();
  159. }
  160.  
  161.  
  162. void desk()
  163. {
  164.     float height=6;
  165.     float width=10;
  166.     float length=5;
  167.  
  168.     float base_height=1;
  169.     float leg_height=height-base_height;
  170.     float leg_width=0.5;
  171.  
  172.     // whole table
  173.     glPushMatrix();
  174.     glTranslatef(0,leg_height,0);
  175.  
  176.     // base
  177.     glPushMatrix();
  178.     glScalef(width,base_height,length);
  179.     glTranslatef(-0.5,0,-0.5);
  180.     cube(0.53,0.39,0.28);
  181.     glPopMatrix();
  182.  
  183.     // legs
  184.     glPushMatrix();
  185.     glTranslatef((width/2-leg_width/2),0,(length/2-leg_width/2));
  186.     glScalef(leg_width,leg_height,leg_width);
  187.     glTranslatef(-0.5,-1,-0.5);
  188.     cube(0.53,0.39,0.28);
  189.     glPopMatrix();
  190.  
  191.     glPushMatrix();
  192.     glTranslatef((width/2-leg_width/2),0,-(length/2-leg_width/2));
  193.     glScalef(leg_width,leg_height,leg_width);
  194.     glTranslatef(-0.5,-1,-0.5);
  195.     cube(0.53,0.39,0.28);
  196.     glPopMatrix();
  197.  
  198.     glPushMatrix();
  199.     glTranslatef(-(width/2-leg_width/2),0,(length/2-leg_width/2));
  200.     glScalef(leg_width,leg_height,leg_width);
  201.     glTranslatef(-0.5,-1,-0.5);
  202.     cube(0.53,0.39,0.28);
  203.     glPopMatrix();
  204.  
  205.     glPushMatrix();
  206.     glTranslatef(-(width/2-leg_width/2),0,-(length/2-leg_width/2));
  207.     glScalef(leg_width,leg_height,leg_width);
  208.     glTranslatef(-0.5,-1,-0.5);
  209.     cube(0.53,0.39,0.28);
  210.     glPopMatrix();
  211.  
  212.     glPopMatrix();
  213. }
  214.  
  215. void table()
  216. {
  217.     float top_length = 20;
  218.     float top_width = 10;
  219.     float top_height = 0.3;
  220.  
  221.     //table-top
  222.     glPushMatrix();
  223.     glTranslatef(0,top_length/2,0);
  224.     glScalef(top_length,top_height,top_width);
  225.     glTranslatef(-0.5,0.0,-0.5);
  226.     cube(0.647, 0.165, 0.165);
  227.     glPopMatrix();
  228.  
  229.     //side bar
  230.     for(int i=-1; i<=1; i+=2)
  231.     {
  232.         glPushMatrix();
  233.         glTranslatef(i*(top_length/2-3*top_height/2),0,0);
  234.         glScalef(top_height,top_length,top_width);
  235.         glTranslatef(-0.5,-0.5,-0.5);
  236.         cube(0.647, 0.165, 0.165);
  237.         glPopMatrix();
  238.     }
  239.  
  240. }
  241.  
  242. void chair()
  243. {
  244.     float seat_length =12, seat_height =2, seat_width  =8;
  245.  
  246.     float leg_length  = 0.8, leg_height  = 12, leg_width  = 0.8;
  247.  
  248.     //seat
  249.     glPushMatrix();
  250.     glScalef(seat_length,seat_height,seat_width);
  251.     glTranslatef(-0.5,0,-0.5);
  252.     cube(0.000, 0.000, 0.000);
  253.     glPopMatrix();
  254.  
  255.     //upper-leg(left)
  256.     glPushMatrix();
  257.     glTranslatef(-(seat_length/2-leg_length/2),0,-(seat_width/2-leg_width/2));
  258.     glScalef(leg_length,leg_height,leg_width);
  259.     glTranslatef(-0.5,0,-0.5);
  260.     cube(0.45,0.49,0.28);
  261.     glPopMatrix();
  262.  
  263.     //upper-leg(right)
  264.     glPushMatrix();
  265.     glTranslatef((seat_length/2-leg_length/2),0,-(seat_width/2-leg_width/2));
  266.     glScalef(leg_length,leg_height,leg_width);
  267.     glTranslatef(-0.5,0,-0.5);
  268.     cube(0.45,0.49,0.28);
  269.     glPopMatrix();
  270.  
  271.     //lower-leg(left)-Rear
  272.     glPushMatrix();
  273.     glTranslatef(-(seat_length/2-leg_length/2),0,-(seat_width/2-leg_width/2));
  274.     glScalef(leg_length,leg_height,leg_width);
  275.     glTranslatef(-0.5,-1,-0.5);
  276.     cube(0.45,0.49,0.28);
  277.     glPopMatrix();
  278.  
  279.     //lower-leg(left)-Front
  280.     glPushMatrix();
  281.     glTranslatef(-(seat_length/2-leg_length/2),0,(seat_width/2-leg_width/2));
  282.     glScalef(leg_length,leg_height,leg_width);
  283.     glTranslatef(-0.5,-1,-0.5);
  284.     cube(0.45,0.49,0.28);
  285.     glPopMatrix();
  286.  
  287.     //lower-leg(right)-Rear
  288.     glPushMatrix();
  289.     glTranslatef((seat_length/2-leg_length/2),0,-(seat_width/2-leg_width/2));
  290.     glScalef(leg_length,leg_height,leg_width);
  291.     glTranslatef(-0.5,-1,-0.5);
  292.     cube(0.45,0.49,0.28);
  293.     glPopMatrix();
  294.  
  295.     //lower-leg(right)-Front
  296.     glPushMatrix();
  297.     glTranslatef((seat_length/2-leg_length/2),0,(seat_width/2-leg_width/2));
  298.     glScalef(leg_length,leg_height,leg_width);
  299.     glTranslatef(-0.5,-1,-0.5);
  300.     cube(0.45,0.49,0.28);
  301.     glPopMatrix();
  302.  
  303.     //Rail-upper
  304.     glPushMatrix();
  305.     glTranslatef(0,0,-(seat_width/2-leg_width/2));
  306.     glScalef(seat_length,seat_height,leg_width);
  307.     glTranslatef(-0.5,-1,-0.5);
  308.     cube(0.45,0.49,0.28);
  309.     glPopMatrix();
  310.  
  311.     //Rail-upper
  312.     glPushMatrix();
  313.     glTranslatef(0,8,-(seat_width/2-leg_width/2));
  314.     glScalef(seat_length,seat_height,leg_width);
  315.     glTranslatef(-0.5,-1,-0.5);
  316.     cube(0.45,0.49,0.28);
  317.     glPopMatrix();
  318.  
  319.     //Rail-upper
  320.     glPushMatrix();
  321.     glTranslatef(0,10,-(seat_width/2-leg_width/2));
  322.     glScalef(seat_length,seat_height,leg_width);
  323.     glTranslatef(-0.5,-1,-0.5);
  324.     cube(0.45,0.49,0.28);
  325.     glPopMatrix();
  326.  
  327.     //Rail-upper
  328.     glPushMatrix();
  329.     glTranslatef(0,12,-(seat_width/2-leg_width/2));
  330.     glScalef(seat_length,seat_height,leg_width);
  331.     glTranslatef(-0.5,-1,-0.5);
  332.     cube(0.45,0.49,0.28);
  333.     glPopMatrix();
  334. }
  335.  
  336. void fan()
  337. {
  338.     float base = 5;
  339.  
  340.     glPushMatrix();
  341.     glRotatef(fan_rt,0,1,0);
  342.  
  343.     //fan-cap
  344.     int cap_rot = 0;
  345.     for(int i=0; i<100; i++)
  346.     {
  347.         glPushMatrix();
  348.         glTranslatef(0,base/4,0);
  349.         glRotatef(cap_rot,0,1,0);
  350.         glScalef(base/4,base*2,base/4);
  351.         glTranslatef(-0.5,0.0,-0.5);
  352.         cube(1.000, 0.627, 0.478);
  353.         glPopMatrix();
  354.         cap_rot+=5;
  355.     }
  356.  
  357.     //round-base
  358.     int base_rot = 0;
  359.     for (int i=0; i<100; i++)
  360.     {
  361.         glPushMatrix();
  362.         //glTranslatef(0,top_width-(6*top_height),0);
  363.         glRotatef(base_rot,0,1,0);
  364.         glScalef(base,base/4,base);
  365.         glTranslatef(-0.5,0.0,-0.5);
  366.         cube(0.184, 0.310, 0.310);
  367.         glPopMatrix();
  368.         base_rot+=5;
  369.     }
  370.     //fan-leg
  371.     for(int i=0; i<=2; i++)
  372.     {
  373.         glPushMatrix();
  374.         glRotatef(120*i,0,1,0);
  375.         glTranslatef((2*base)/2+base/2,base/8,0);
  376.         glScalef(2*base,0.002*base,base/2);
  377.         glTranslatef(-0.5,0.0,-0.5);
  378.         cube(0.000, 0.000, 0.545);
  379.         glPopMatrix();
  380.     }
  381.  
  382.     fan_rotation();
  383.     glPopMatrix();
  384.  
  385. }
  386.  
  387. void light_matter_1(float x, float y, float z)
  388. {
  389.     GLfloat no_light[] = { 0.0, 0.0, 0.0, 1.0 };
  390.     GLfloat light_ambient[]  = {0.1, 0.1, 0.1, 1.0};
  391.     GLfloat light_diffuse[]  = { 1.0, 1.0, 1.0, 1.0 };
  392.     GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  393.     GLfloat light_pos[] = { x,y,z,1};
  394.     glEnable(GL_LIGHT0);
  395.     if(light_1)
  396.     {
  397.  
  398.             glLightfv( GL_LIGHT0, GL_AMBIENT, light_ambient);
  399.             glLightfv( GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  400.             glLightfv( GL_LIGHT0, GL_SPECULAR, light_specular);
  401.     }
  402.     else
  403.     {
  404.             glLightfv( GL_LIGHT0, GL_AMBIENT, no_light);
  405.             glLightfv( GL_LIGHT0, GL_DIFFUSE, no_light);
  406.             glLightfv( GL_LIGHT0, GL_SPECULAR, no_light);
  407.     }
  408.  
  409.  
  410.             glLightfv( GL_LIGHT0, GL_POSITION, light_pos);
  411.  
  412. }
  413.  
  414. void light_matter_2(float x, float y, float z)
  415. {
  416.     GLfloat no_light[] = { 0.0, 0.0, 0.0, 1.0 };
  417.     GLfloat light_ambient[]  = {0.1, 0.1, 0.1, 1.0};
  418.     GLfloat light_diffuse[]  = { 1.0, 1.0, 1.0, 1.0 };
  419.     GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  420.     GLfloat light_pos[] = { x,y,z,1};
  421.     glEnable(GL_LIGHT1);
  422.     if(light_2)
  423.     {
  424.  
  425.             glLightfv( GL_LIGHT1, GL_AMBIENT, light_ambient);
  426.             glLightfv( GL_LIGHT1, GL_DIFFUSE, light_diffuse);
  427.             glLightfv( GL_LIGHT1, GL_SPECULAR, light_specular);
  428.     }
  429.     else
  430.     {
  431.             glLightfv( GL_LIGHT1, GL_AMBIENT, no_light);
  432.             glLightfv( GL_LIGHT1, GL_DIFFUSE, no_light);
  433.             glLightfv( GL_LIGHT1, GL_SPECULAR, no_light);
  434.     }
  435.  
  436.  
  437.             glLightfv( GL_LIGHT1, GL_POSITION, light_pos);
  438.  
  439. }
  440.  
  441. void spot_light_matter(float x, float y, float z)
  442. {
  443.     GLfloat no_light[] = { 0.0, 0.0, 0.0, 1.0 };
  444.     GLfloat light_ambient[]  = {0.5, 0, 0, 1.0};
  445.     GLfloat light_diffuse[]  = { 1, 0, 0, 1.0 };
  446.     GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  447.     GLfloat light_pos[] = { x,y,z,1};
  448.     glEnable(GL_LIGHT7);
  449.     if(light_3)
  450.     {
  451.  
  452.             glLightfv( GL_LIGHT7, GL_AMBIENT, light_ambient);
  453.             glLightfv( GL_LIGHT7, GL_DIFFUSE, light_diffuse);
  454.             glLightfv( GL_LIGHT7, GL_SPECULAR, light_specular);
  455.     }
  456.     else
  457.     {
  458.             glLightfv( GL_LIGHT7, GL_AMBIENT, no_light);
  459.             glLightfv( GL_LIGHT7, GL_DIFFUSE, no_light);
  460.             glLightfv( GL_LIGHT7, GL_SPECULAR, no_light);
  461.     }
  462.  
  463.  
  464.             glLightfv( GL_LIGHT7, GL_POSITION, light_pos);
  465.  
  466.             GLfloat direction[] = {0,-1,0,1};
  467.             GLfloat cut_off = 25.0;
  468.             glLightfv(GL_LIGHT7, GL_SPOT_DIRECTION, direction );
  469.             glLightf(GL_LIGHT7, GL_SPOT_CUTOFF, 25 );
  470. }
  471.  
  472. void light()
  473. {
  474.     float light_length = 20, light_width = 1, light_height = 2;
  475.     float bar_length = 2, bar_height = light_height+1, bar_width = 2;
  476.  
  477.     //light-holder
  478.     glPushMatrix();
  479.     glScalef(light_length-2,light_height+1,light_width);
  480.     glTranslatef(-0.5,0,-0.5);
  481.     cube(1.000, 1.000, 1.000);
  482.     glPopMatrix();
  483.  
  484.     //light bar
  485.     for(int i=-1; i<=1; i+=2)
  486.     {
  487.         glPushMatrix();
  488.         glTranslatef(i*(light_length/2-bar_length/2),0,0);
  489.         glScalef(bar_length,bar_height,bar_width);
  490.         glTranslatef(-0.5,0,-0.5);
  491.         cube(0, 0.941, 0.902);
  492.         glPopMatrix();
  493.     }
  494.  
  495. }
  496.  
  497. void door()
  498. {
  499.     float window_length = 10, window_height = 15, window_width = 0.5;
  500.     float bar_dense = 0.3;
  501.     //window blue glass
  502.     glPushMatrix();
  503.     glScalef(window_length-2,window_height,window_width);
  504.     glTranslatef(-0.5,0.0,-0.5);
  505.     cube(0.275, 0.510, 0.706);
  506.     glPopMatrix();
  507.  
  508.  
  509.     //right-middle-left bar
  510.     for(int i=-1; i<=1; i+=1)
  511.     {
  512.         glPushMatrix();
  513.         glTranslatef(i*(window_length/2-(4*bar_dense)/2),0,bar_dense/2);
  514.         glScalef(4*bar_dense,window_height,bar_dense);
  515.         glTranslatef(-0.5,0.0,-0.5);
  516.         cube(0.65,0.4,0.3);
  517.         glPopMatrix();
  518.     }
  519.  
  520.     // handle
  521.     int c=0;
  522.     for(float i=-0.3; i<=0.3; i+=0.6)
  523.     {
  524.         glPushMatrix();
  525.         glTranslatef(i,(window_height/2),bar_dense);
  526.         glScalef(bar_dense,10*bar_dense,bar_dense);
  527.         glTranslatef(-0.5,0.0,-0.5);
  528.         cube(1, 1, 1);
  529.         glPopMatrix();
  530.     }
  531. }
  532.  
  533. void st_desk()
  534. {
  535.     glPushMatrix();
  536.     glTranslatef(0,-8,0);
  537.     glScalef(1,2,1);
  538.     table();
  539.     glPopMatrix();
  540.  
  541.     glPushMatrix();
  542.     glTranslatef(-2,2.5,15);
  543.     glRotatef(180,0,1,0);
  544.     glScalef(1,2,0.5);
  545.     chair();
  546.     glPopMatrix();
  547. }
  548.  
  549. void classroom()
  550. {
  551.     float room_length = 90, room_height = 60, room_width = 100, flr_dense = 0.3;
  552.  
  553.     //floor
  554.     glPushMatrix();
  555.     glTranslatef(0,0,0);
  556.     glScalef(room_length,flr_dense,room_width);
  557.     glTranslatef(-0.5,-1,-0.5);
  558.     //cube(0.467, 0.533, 0.60);
  559.     cube(0.502, 0.502, 0.502);
  560.     glPopMatrix();
  561.  
  562. //    //roof
  563.     glPushMatrix();
  564.     glTranslatef(0,1*room_height,0);
  565.     glScalef(room_length,flr_dense,room_width);
  566.     glTranslatef(-0.5,-1,-0.5);
  567.     //cube(0.7,0.7,0.7);
  568.     cube(0.741, 0.718, 0.420);
  569.     glPopMatrix();
  570. //
  571. //
  572.     for(int i=-(room_width/2); i<=(room_width)/2; i+=5)
  573.     {
  574.         glPushMatrix();
  575.         glTranslatef(0,0.1,i);
  576.         glScalef(room_length,flr_dense,flr_dense/4);
  577.         glTranslatef(-0.5,-1,-0.5);
  578.         cube(0.000, 0.000, 0.0);
  579.         glPopMatrix();
  580.     }
  581. //
  582. //
  583. //    //side-wall
  584.     for(int i=-1; i<=1; i+=2)
  585.     {
  586.         glPushMatrix();
  587.         glTranslatef(i*(room_length/2-flr_dense/2),0,0);
  588.         glScalef(flr_dense,room_height,room_width);
  589.         glTranslatef(-0.5,0,-0.5);
  590.         //cube(1.000, 0.871, 0.678);
  591.         cube(0.502, 0.502, 0.000);
  592.         glPopMatrix();
  593.     }
  594. //
  595. //    //front wall
  596.     glPushMatrix();
  597.     glTranslatef(0,0,-(room_width/2-flr_dense/2));
  598.     glScalef(room_length,room_height,flr_dense);
  599.     glTranslatef(-0.5,0,-0.5);
  600.     //cube(0.741, 0.718, 0.420);
  601.     cube(0.373, 0.620, 0.627);
  602.     glPopMatrix();
  603.  
  604. //    //back wall
  605.     glPushMatrix();
  606.     glTranslatef(0,0,(room_width/2-flr_dense/2));
  607.     glScalef(room_length,room_height,flr_dense);
  608.     glTranslatef(-0.5,0,-0.5);
  609.     //cube(0.741, 0.718, 0.420);
  610.     cube(0.741, 0.718, 0.420);
  611.     glPopMatrix();
  612.  
  613. //
  614. //    //board
  615.     glPushMatrix();
  616.     glTranslatef(0,room_height/2-room_height/4+4,-(room_width/2-flr_dense/2-3));
  617.     glScalef(room_length/1.5,room_height/2,flr_dense);
  618.     glTranslatef(-0.5,0,-0.5);
  619.     cube(1,1,1);
  620.     glPopMatrix();
  621. //
  622. //
  623. //
  624. //    //side-light
  625.     for(int i=-1; i<=1; i+=2)
  626.     {
  627.         glPushMatrix();
  628.         glTranslatef(i*(room_length/2-3.5),room_height/1.3,20);
  629.         glRotatef(-90,0,1,0);
  630.         glScalef(0.5,1,1);
  631.         light();
  632.         glPopMatrix();
  633.     }
  634.     glPushMatrix();
  635.     light_matter_1(-(room_length/2-3.5),room_height/1.3,20);
  636.     glPopMatrix();
  637.  
  638.     glPushMatrix();
  639.     //glRotatef(90,0,0,1);
  640.     light_matter_2((room_length/2-3.5),room_height/1.3,20);
  641.     glPopMatrix();
  642.  
  643.     //spot_light
  644.     glPushMatrix();
  645.     glTranslatef(0,room_height/1.5,0);
  646.     glScalef(5,5,5);
  647.     glTranslatef(-0.5,-0.5,-0.5);
  648.     cube(0.5,0,0);
  649.     glPopMatrix();
  650.  
  651.     glPushMatrix();
  652.     spot_light_matter(0,room_height/1.5,0);
  653.     glPopMatrix();
  654. //
  655. //
  656. //    //teacher-platform
  657.     glPushMatrix();
  658.     glTranslatef(0,0,-(room_width/2-flr_dense/2-7));
  659.     glScalef(room_length-12,room_height/7,room_width/9);
  660.     glTranslatef(-0.5,0,-0.5);
  661.     cube(0.529, 0.808, 0.922);
  662.     glPopMatrix();
  663. //
  664.     glPushMatrix();
  665.     glTranslatef(0,room_height-5,0);
  666.     glScalef(1,1,1);
  667.     glTranslatef(-0.5,-1,-0.5);
  668.     fan();
  669.     glPopMatrix();
  670. //
  671. //
  672. //    //door
  673.     glPushMatrix();
  674.     glTranslatef(-(room_length/2),room_height/2-30,-25);
  675.     glRotatef(90,0,1,0);
  676.     glScalef(1,3,2);
  677.     door();
  678.     glPopMatrix();
  679.  
  680. //    //chair-table
  681.     for(int i=5; i<=40; i+=15)
  682.     {
  683.         for(int j=-(room_length/2-20); j<=room_length/2; j+=25)
  684.         {
  685.             glPushMatrix();
  686.             glTranslatef(j,10,i);
  687.             glScalef(0.5,0.5,0.5);
  688.             st_desk();
  689.             glPopMatrix();
  690.         }
  691.     }
  692.  
  693.  
  694. }
  695.  
  696. static void res(int width, int height)
  697. {
  698.     glViewport(0, 0, window_width, window_width/rat);
  699. }
  700.  
  701. static void display(void)
  702. {
  703.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  704.     glMatrixMode(GL_PROJECTION);
  705.     glLoadIdentity();
  706.     int lim = 8;
  707.     glFrustum(-lim, lim, -lim, lim, 4, 100);
  708.  
  709.     glMatrixMode(GL_MODELVIEW);
  710.     glLoadIdentity();
  711.  
  712.  
  713.  
  714.     glMatrixMode(GL_MODELVIEW);
  715.     glLoadIdentity() ;
  716.  
  717.     //gluLookAt(eyeX,eyeY,eyeZ, lookX,lookY,lookZ, 0,1,0);
  718.     //gluLookAt(eye[0],eye[1],eye[2], look[0],look[1],look[2], 0,1,0);
  719.     //glViewport(0, 0, window_width, window_height);
  720.  
  721.     gluLookAt(eyeX,eyeY,eyeZ, lookX,lookY,lookZ, 0,1,0);
  722.     //glViewport(0, 0, window_width, window_height);
  723.  
  724.  
  725.     glRotatef(rot, 0,1,0);
  726.  
  727.     classroom();
  728.  
  729.     glutSwapBuffers();
  730. }
  731.  
  732.  
  733. static void key(unsigned char key, int x, int y)
  734. {
  735.     switch (key)
  736.     {
  737. //case 'm':
  738. //    sakib ++;
  739. //    break;
  740. //case 'M':
  741. //    sakib --;
  742. //    break;
  743.     case 'q':
  744.         exit(0);
  745.         break;
  746.  
  747.     case 'w':
  748.  
  749.         if(up<=11)
  750.         {
  751.             up++;
  752.             down--;
  753.             eyeY++;
  754.             lookY++;
  755.         }
  756.  
  757.         break;
  758.     case 's':
  759.  
  760.         if(down<=30)
  761.         {
  762.             down++;
  763.             up--;
  764.             eyeY--;
  765.             lookY--;
  766.  
  767.         }
  768.         break;
  769.     case 'a':
  770.         rot--;
  771.         break;
  772.     case 'd':
  773.         rot++;
  774.         break;
  775.     case 'l':
  776.         if(r<=36)
  777.         {
  778.             r++;
  779.             l--;
  780.             eyeX++;
  781.             lookX++;
  782.         }
  783.         break;
  784.     case 'j':
  785.         if(l<=36)
  786.         {
  787.             r--;
  788.             l++;
  789.             eyeX--;
  790.             lookX--;
  791.         }
  792.  
  793.         break;
  794.     case '+':
  795.         eyeZ--;
  796.         break;
  797.     case 'i':
  798.         eyeZ--;
  799.         break;
  800.     case '-':
  801.         eyeZ++;
  802.         break;
  803.     case 'k':
  804.         eyeZ++;
  805.         break;
  806.     case '1':
  807.         light_1 = 1-light_1;
  808.         break;
  809.     case '2':
  810.         light_2 = 1-light_2;
  811.         break;
  812.     case '3':
  813.         light_3 = 1-light_3;
  814.         break;
  815.     }
  816.  
  817.     glutPostRedisplay();
  818. }
  819.  
  820.  
  821. int main(int argc, char *argv[])
  822. {
  823.     glutInit(&argc, argv);
  824.     glutInitWindowSize(window_width,window_height);
  825.     glutInitWindowPosition(300,10);
  826.     glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  827.  
  828.     glutCreateWindow("Class Room");
  829.  
  830.     glutDisplayFunc(display);
  831.     glutKeyboardFunc(key);
  832.     //glutReshapeFunc(resize);
  833.  
  834.     glEnable(GL_DEPTH_TEST);
  835.     glShadeModel( GL_SMOOTH );
  836.     glEnable(GL_NORMALIZE);
  837.     glEnable(GL_BLEND);
  838.     glEnable(GL_LIGHTING);
  839.  
  840.     glutMainLoop();
  841.     return EXIT_SUCCESS;
  842. }
  843.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement