Advertisement
sajid006

Before Final Project

Jun 13th, 2021
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 60.81 KB | None | 0 0
  1.  
  2. #include<GL/gl.h>
  3. #include <GL/glu.h>
  4. #include <GL/glut.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <windows.h>
  8. #include<math.h>
  9. #include <vector>
  10. #include <iostream>
  11. #include "BmpLoader.h"
  12. using namespace std;
  13.  
  14.  
  15. const double PI = 3.14159265389;
  16.  
  17.  
  18. /* GLUT callback Handlers */
  19.  
  20. bool rooftop=0;
  21. int anglex= 0, angley = 0, anglez = 0; //rotation angles
  22. int window;
  23. int wired=0;
  24. int shcpt=1;
  25. int animat = 0;
  26. const int L=20;
  27. const int dgre=3;
  28. int ncpt=L+1;
  29. int clikd=0;
  30. const int nt = 40; //number of slices along x-direction
  31. const int ntheta = 20;
  32.  
  33.  
  34. GLfloat ctrlpoints[33][3] =
  35. {
  36. { 0.0, 0.0, 0.0}, { -0.3, 0.5, 0.0},
  37. { 0.1, 1.7, 0.0},{ 0.5, 1.5, 0.0},
  38. {2.5, 1.2, 0.0},
  39. { 3.0, 0.0, 0.0}, { 2.7, 0.5, 0.0},
  40. { 3.1, 1.7, 0.0},{ 3.5, 1.5, 0.0},
  41. {5.5, 1.2, 0.0},{5.5, 2.2, 0.0},{5.5, 3.2, 0.0},{5.5, 3.2, 0.0},{6.5, 0.2, 0.0},
  42. {4.5, 0.2, 0.0},{7.5, 1.2, 0.0},{ 3.0, 0.0, 0.0}, { 2.7, 0.5, 0.0},
  43. { 10.1, 1.7, 0.0},{ 10.5, 1.5, 0.0},
  44. {12.5, 1.2, 0.0},{12.5, 2.2, 0.0},{12.5, 3.2, 0.0},{12.5, 3.2, 0.0},{13.5, 0.2, 0.0},
  45. {11.5, 0.2, 0.0},{14.5, 1.2, 0.0}
  46. };
  47.  
  48. /*
  49. , {1.4, 1.4, 0.0},
  50. {1.8, 0.4, 0.0},{2.2, 0.4, 0.0},
  51. {2.6, 1.5, 0.0}, {3.0, 1.4, 0.0},
  52. {3.4, 1.4, 0.0},{3.8, 1.4, 0.0},
  53. {4.2, 1.0, 0.0},{4.6, 1.0, 0.0},
  54. {5.0, 1.0, 0.0},{5.4, 1.0, 0.0},
  55. {5.8, 0.5, 0.0},{6.2, 0.5, 0.0},
  56. {6.6, 0.5, 0.0},{7.2, 0.2, 0.0},
  57. {6.8, 0.52, 0.0}
  58.  
  59. */
  60. double ex=0, ey=0, ez=15, lx=0,ly=0,lz=0, hx=0,hy=1,hz=0;
  61.  
  62. float wcsClkDn[3],wcsClkUp[3];
  63. ///////////////////////////////
  64. class point1
  65. {
  66. public:
  67. point1()
  68. {
  69. x=0;
  70. y=0;
  71. }
  72. int x;
  73. int y;
  74. } clkpt[2];
  75. int flag=0;
  76. GLint viewport[4]; //var to hold the viewport info
  77. GLdouble modelview[16]; //var to hold the modelview info
  78. GLdouble projection[16]; //var to hold the projection matrix info
  79.  
  80. //////////////////////////
  81. void scsToWcs(float sx,float sy, float wcsv[3] );
  82. void processMouse(int button, int state, int x, int y);
  83. void matColor(float kdr, float kdg, float kdb, float shiny, int frnt_Back=0, float ambFactor=1.0, float specFactor=1.0);
  84. ///////////////////////////
  85.  
  86. void scsToWcs(float sx,float sy, float wcsv[3] )
  87. {
  88.  
  89. GLfloat winX, winY, winZ; //variables to hold screen x,y,z coordinates
  90. GLdouble worldX, worldY, worldZ; //variables to hold world x,y,z coordinates
  91.  
  92. //glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); //get the modelview info
  93. glGetDoublev( GL_PROJECTION_MATRIX, projection ); //get the projection matrix info
  94. glGetIntegerv( GL_VIEWPORT, viewport ); //get the viewport info
  95.  
  96. winX = sx;
  97. winY = (float)viewport[3] - (float)sy;
  98. winZ = 0;
  99.  
  100. //get the world coordinates from the screen coordinates
  101. gluUnProject( winX, winY, winZ, modelview, projection, viewport, &worldX, &worldY, &worldZ);
  102. wcsv[0]=worldX;
  103. wcsv[1]=worldY;
  104. wcsv[2]=worldZ;
  105.  
  106.  
  107. }
  108. void processMouse(int button, int state, int x, int y)
  109. {
  110. if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
  111. {
  112. if(flag!=1)
  113. {
  114. flag=1;
  115. clkpt[0].x=x;
  116. clkpt[0].y=y;
  117. }
  118.  
  119.  
  120. scsToWcs(clkpt[0].x,clkpt[0].y,wcsClkDn);
  121. cout<<"\nD: "<<x<<" "<<y<<" wcs: "<<wcsClkDn[0]<<" "<<wcsClkDn[1];
  122. }
  123. else if(button==GLUT_LEFT_BUTTON && state==GLUT_UP)
  124. {
  125. if (flag==1)
  126. {
  127. clkpt[1].x=x;
  128. clkpt[1].y=y;
  129. flag=0;
  130. }
  131. float wcs[3];
  132. scsToWcs(clkpt[1].x,clkpt[1].y,wcsClkUp);
  133. cout<<"\nU: "<<x<<" "<<y<<" wcs: "<<wcsClkUp[0]<<" "<<wcsClkUp[1];
  134.  
  135. clikd=!clikd;
  136. }
  137. }
  138.  
  139. //control points
  140. long long nCr(int n, int r)
  141. {
  142. if(r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
  143. long long ans = 1;
  144. int i;
  145.  
  146. for(i = 1; i <= r; i++)
  147. {
  148. ans *= n - r + i;
  149. ans /= i;
  150. }
  151.  
  152. return ans;
  153. }
  154.  
  155. //polynomial interpretation for N points
  156. void BezierCurve ( double t, float xy[2])
  157. {
  158. double y=0;
  159. double x=0;
  160. t=t>1.0?1.0:t;
  161. for(int i=0; i<=L; i++)
  162. {
  163. int ncr=nCr(L,i);
  164. double oneMinusTpow=pow(1-t,double(L-i));
  165. double tPow=pow(t,double(i));
  166. double coef=oneMinusTpow*tPow*ncr;
  167. x+=coef*ctrlpoints[i][0];
  168. y+=coef*ctrlpoints[i][1];
  169.  
  170. }
  171. xy[0] = float(x);
  172. xy[1] = float(y);
  173.  
  174. //return y;
  175. }
  176.  
  177. ///////////////////////
  178. void setNormal(GLfloat x1, GLfloat y1,GLfloat z1, GLfloat x2, GLfloat y2,GLfloat z2, GLfloat x3, GLfloat y3,GLfloat z3)
  179. {
  180. GLfloat Ux, Uy, Uz, Vx, Vy, Vz, Nx, Ny, Nz;
  181.  
  182. Ux = x2-x1;
  183. Uy = y2-y1;
  184. Uz = z2-z1;
  185.  
  186. Vx = x3-x1;
  187. Vy = y3-y1;
  188. Vz = z3-z1;
  189.  
  190. Nx = Uy*Vz - Uz*Vy;
  191. Ny = Uz*Vx - Ux*Vz;
  192. Nz = Ux*Vy - Uy*Vx;
  193.  
  194. glNormal3f(-Nx,-Ny,-Nz);
  195. }
  196.  
  197. void bottleBezier()
  198. {
  199. int i, j;
  200. float x, y, z, r; //current coordinates
  201. float x1, y1, z1, r1; //next coordinates
  202. float theta;
  203.  
  204. const float startx = 0, endx = ctrlpoints[L][0];
  205. //number of angular slices
  206. const float dx = (endx - startx) / nt; //x step size
  207. const float dtheta = 2*PI / ntheta; //angular step size
  208.  
  209. float t=0;
  210. float dt=1.0/nt;
  211. float xy[2];
  212. BezierCurve( t, xy);
  213. x = xy[0];
  214. r = xy[1];
  215. //rotate about z-axis
  216. float p1x,p1y,p1z,p2x,p2y,p2z;
  217. for ( i = 0; i < nt; ++i ) //step through x
  218. {
  219. theta = 0;
  220. t+=dt;
  221. BezierCurve( t, xy);
  222. x1 = xy[0];
  223. r1 = xy[1];
  224.  
  225. //draw the surface composed of quadrilaterals by sweeping theta
  226. glBegin( GL_QUAD_STRIP );
  227. for ( j = 0; j <= ntheta; ++j )
  228. {
  229. theta += dtheta;
  230. double cosa = cos( theta );
  231. double sina = sin ( theta );
  232. y = r * cosa;
  233. y1 = r1 * cosa; //current and next y
  234. z = r * sina;
  235. z1 = r1 * sina; //current and next z
  236.  
  237. //edge from point at x to point at next x
  238. glVertex3f (x, y, z);
  239.  
  240. if(j>0)
  241. {
  242. setNormal(p1x,p1y,p1z,p2x,p2y,p2z,x, y, z);
  243. }
  244. else
  245. {
  246. p1x=x;
  247. p1y=y;
  248. p1z=z;
  249. p2x=x1;
  250. p2y=y1;
  251. p2z=z1;
  252.  
  253. }
  254. glVertex3f (x1, y1, z1);
  255.  
  256. //forms quad with next pair of points with incremented theta value
  257. }
  258. glEnd();
  259. x = x1;
  260. r = r1;
  261. } //for i
  262.  
  263. }
  264.  
  265.  
  266. static void resize(int width, int height)
  267. {
  268. const float ar = (float) width / (float) height;
  269.  
  270. glViewport(0, 0, width, height);
  271. glMatrixMode(GL_PROJECTION);
  272. glLoadIdentity();
  273. //glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
  274. // gluPerspective(60,ar, 2.0, 100.0);
  275.  
  276. glOrtho(-8.0, 8.0, -8.0*(GLfloat)height/(GLfloat)width, 8.0*(GLfloat)height/(GLfloat)width, 2.0, 25.0);
  277. glMatrixMode(GL_MODELVIEW);
  278. glLoadIdentity() ;
  279. gluLookAt(ex,ey,ez,lx,ly,lz,hx,hy,hz);
  280.  
  281. }
  282.  
  283.  
  284. void showControlPoints()
  285. {
  286. glPointSize(5.0);
  287. glColor3f(1.0, 0.0, 1.0);
  288. glBegin(GL_POINTS);
  289. for (int i = 0; i <=L; i++)
  290. glVertex3fv(&ctrlpoints[i][0]);
  291. glEnd();
  292. }
  293. const int width = 1000;
  294. const int height = 1000;
  295.  
  296. GLfloat eyeX = 0;
  297. GLfloat eyeY = 6;
  298. GLfloat eyeZ = -13;
  299.  
  300. GLfloat lookX = 0;
  301. GLfloat lookY = 5;
  302. GLfloat lookZ = 0;
  303.  
  304. GLfloat hookX = 0;
  305. GLfloat hookY = 1;
  306. GLfloat hookZ = 0;
  307.  
  308. GLfloat alpha = 0.0, theta = 0.0, axis_x=0.0, axis_y=0.0, f_spin=0.0;
  309. GLboolean bRotate = false, uRotate = false;
  310.  
  311. float da[8]= {0,0,0,0,0,1,1,1};
  312. bool l_on=true;
  313. bool press1 = false;
  314. bool press2 = false;
  315. bool press4 = false;
  316. bool flagRot = false;
  317. float rot = 0;
  318. unsigned int ID;
  319.  
  320. double spin=1.0;
  321. bool isrot=1;
  322.  
  323. float px=0,py=30,pz=30,spot_cutoff = 30;
  324.  
  325. static GLfloat v_cube[8][3] =
  326. {
  327. {0,0,0},
  328. {0,0,1},
  329. {0,1,0},
  330. {0,1,1},
  331.  
  332. {1,0,0},
  333. {1,0,1},
  334. {1,1,0},
  335. {1,1,1}
  336. };
  337.  
  338. static GLubyte c_ind[6][4] =
  339. {
  340. {3,1,5,7}, //front
  341. {6,4,0,2}, //back
  342. {2,3,7,6}, //top
  343. {1,0,4,5}, //bottom
  344. {7,5,4,6}, //right
  345. {2,0,1,3} //left
  346. };
  347.  
  348.  
  349.  
  350.  
  351. static void getNormal3p(GLfloat x1, GLfloat y1, GLfloat z1, GLfloat x2, GLfloat y2, GLfloat z2, GLfloat x3, GLfloat y3, GLfloat z3)
  352. {
  353. GLfloat Ux, Uy, Uz, Vx, Vy, Vz, Nx, Ny, Nz;
  354.  
  355. Ux = x2-x1;
  356. Uy = y2-y1;
  357. Uz = z2-z1;
  358.  
  359. Vx = x3-x1;
  360. Vy = y3-y1;
  361. Vz = z3-z1;
  362.  
  363. Nx = Uy*Vz - Uz*Vy;
  364. Ny = Uz*Vx - Ux*Vz;
  365. Nz = Ux*Vy - Uy*Vx;
  366.  
  367. glNormal3f(Nx,Ny,Nz);
  368. }
  369.  
  370. void set_material(float R=0.5, float G=0.5, float B=0.5, bool e=false, bool l = false)
  371. {
  372. GLfloat mat_no[] = {0,0,0, 1.0};
  373. GLfloat mat_amb[] = {R,G,B,1};
  374. GLfloat mat_diff[] = {R,G,B,1};
  375. GLfloat mat_spec[] = {1,1,1,1};
  376. GLfloat mat_sh[] = {30};
  377.  
  378. GLfloat mat_em[] = {1,1,1,1};
  379.  
  380. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_amb);
  381. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diff);
  382. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_spec);
  383. glMaterialfv(GL_FRONT, GL_SHININESS, mat_sh);
  384.  
  385. if(e && l)
  386. {
  387. glMaterialfv(GL_FRONT, GL_EMISSION, mat_em);
  388. }
  389. else
  390. {
  391. glMaterialfv(GL_FRONT, GL_EMISSION, mat_no);
  392. }
  393. }
  394.  
  395.  
  396. void cube2(float R=0.5, float G=0.5, float B=0.5, bool e=false, float alpha=1)
  397. {
  398.  
  399. GLfloat m_no[] = {0, 0, 0, 1.0};
  400. GLfloat m_amb[] = {R,G,B,1};
  401. GLfloat m_diff[] = {R,G,B,1};
  402. GLfloat m_spec[] = {1,1,1,1};
  403. GLfloat m_sh[] = {30};
  404.  
  405. GLfloat m_em[] = {1,1,1,1};
  406.  
  407. glMaterialfv(GL_FRONT, GL_AMBIENT, m_amb);
  408. glMaterialfv(GL_FRONT, GL_DIFFUSE, m_diff);
  409. glMaterialfv(GL_FRONT, GL_SPECULAR, m_spec);
  410. glMaterialfv(GL_FRONT, GL_SHININESS, m_sh);
  411.  
  412. if(e & l_on)
  413. glMaterialfv(GL_FRONT, GL_EMISSION, m_em);
  414. else
  415. glMaterialfv(GL_FRONT, GL_EMISSION, m_no);
  416.  
  417. glBegin(GL_QUADS);
  418. for (GLint i = 0; i <6; i++)
  419. {
  420. getNormal3p(v_cube[c_ind[i][0]][0], v_cube[c_ind[i][0]][1], v_cube[c_ind[i][0]][2],
  421. v_cube[c_ind[i][1]][0], v_cube[c_ind[i][1]][1], v_cube[c_ind[i][1]][2],
  422. v_cube[c_ind[i][2]][0], v_cube[c_ind[i][2]][1], v_cube[c_ind[i][2]][2]);
  423.  
  424. for (GLint j=0; j<4; j++)
  425. {
  426. glVertex3fv(&v_cube[c_ind[i][j]][0]);
  427. }
  428. }
  429. glEnd();
  430. }
  431.  
  432. void cube(float R=0.5, float G=0.5, float B=0.5, bool e=false, bool l = false)
  433. {
  434.  
  435. set_material(R,G,B,l);
  436.  
  437. glBegin(GL_QUADS);
  438. for (GLint i = 0; i <6; i++)
  439. {
  440. getNormal3p(v_cube[c_ind[i][0]][0], v_cube[c_ind[i][0]][1], v_cube[c_ind[i][0]][2],
  441. v_cube[c_ind[i][1]][0], v_cube[c_ind[i][1]][1], v_cube[c_ind[i][1]][2],
  442. v_cube[c_ind[i][2]][0], v_cube[c_ind[i][2]][1], v_cube[c_ind[i][2]][2]);
  443.  
  444. glTexCoord2f(0,1);
  445. glVertex3fv(&v_cube[c_ind[i][0]][0]);
  446. glTexCoord2f(0,0);
  447. glVertex3fv(&v_cube[c_ind[i][1]][0]);
  448. glTexCoord2f(1,0);
  449. glVertex3fv(&v_cube[c_ind[i][2]][0]);
  450. glTexCoord2f(1,1);
  451. glVertex3fv(&v_cube[c_ind[i][3]][0]);
  452. }
  453. glEnd();
  454. }
  455.  
  456. void axes()
  457. {
  458. float length = 10;
  459. float width = 0.3;
  460.  
  461. // X-axis
  462. glPushMatrix();
  463. glTranslatef(length/2,0,0);
  464. glScalef(length,width,width);
  465. glTranslatef(-0.5,-0.5,-0.5);
  466. cube(0.8,0.1,0.1);
  467. glPopMatrix();
  468.  
  469. // Y-axis
  470. glPushMatrix();
  471. glTranslatef(0,length/2,0);
  472. glScalef(width,length,width);
  473. glTranslatef(-0.5,-0.5,-0.5);
  474. cube(0.1,0.8,0.1);
  475. glPopMatrix();
  476.  
  477. // Z-axis
  478. glPushMatrix();
  479. glTranslatef(0,0,length/2);
  480. glScalef(width,width,length);
  481. glTranslatef(-0.5,-0.5,-0.5);
  482. cube(0.1,0.1,0.8);
  483. glPopMatrix();
  484. }
  485.  
  486. void rodshape1(float x,float y,float z)
  487. {
  488. float t_length = 6;
  489. float t_width = 0.5;
  490.  
  491. glPushMatrix();
  492. //glTranslatef(-14.5,7,0);
  493. glTranslatef(x,y,z);
  494.  
  495. glPushMatrix();
  496. glScalef(t_width,t_width,t_length);
  497. glTranslatef(-0.5,0,-0.5);
  498. cube(1,1,1,true,press1);
  499. glPopMatrix();
  500.  
  501. glPushMatrix();
  502. glTranslatef(0,0,t_length/2+t_width/2);
  503. glScalef(t_width,t_width,t_width);
  504. glTranslatef(-0.5,0,-0.5);
  505. cube(0.2,0.2,0.2);
  506. glPopMatrix();
  507.  
  508. glPushMatrix();
  509. glTranslatef(0,0,-t_length/2-t_width/2);
  510. glScalef(t_width,t_width,t_width);
  511. glTranslatef(-0.5,0,-0.5);
  512. cube(0.2,0.2,0.2);
  513. glPopMatrix();
  514.  
  515. glPopMatrix();
  516.  
  517. }
  518.  
  519. void rodshape2(float x, float y, float z)
  520. {
  521. float t_length = 6;
  522. float t_width = 0.5;
  523.  
  524. glPushMatrix();
  525. //glTranslatef(-14.5,7,0);
  526. glTranslatef(x,y,z);
  527.  
  528. glPushMatrix();
  529. glScalef(t_width,t_width,t_length);
  530. glTranslatef(-0.5,0,-0.5);
  531. cube(1,1,1,true,press2);
  532. glPopMatrix();
  533.  
  534. glPushMatrix();
  535. glTranslatef(0,0,t_length/2+t_width/2);
  536. glScalef(t_width,t_width,t_width);
  537. glTranslatef(-0.5,0,-0.5);
  538. cube(0.2,0.2,0.2);
  539. glPopMatrix();
  540.  
  541. glPushMatrix();
  542. glTranslatef(0,0,-t_length/2-t_width/2);
  543. glScalef(t_width,t_width,t_width);
  544. glTranslatef(-0.5,0,-0.5);
  545. cube(0.2,0.2,0.2);
  546. glPopMatrix();
  547.  
  548. glPopMatrix();
  549.  
  550. }
  551.  
  552. void spotlightshape(float x,float y, float z)
  553. {
  554. float s_height = 0.25;
  555. float s_width = 2;
  556. float s_length = 2;
  557.  
  558. glPushMatrix();
  559. glTranslatef(x,y,z);
  560. /*
  561. glPushMatrix();
  562. glScalef(s_width,s_height,s_length);
  563. glTranslatef(-0.5,0,-0.5);
  564. cube(1,1,1);
  565. glPopMatrix();
  566. */
  567. glPushMatrix();
  568. glScalef(s_width,s_height,s_length);
  569. glTranslatef(-0.5,0,-0.5);
  570. cube(1,1,1,true,press4);
  571. glPopMatrix();
  572.  
  573. glPopMatrix();
  574.  
  575. }
  576.  
  577.  
  578. void door(float x,float y,float z,int id,float sx=5,float sy=10)
  579. {
  580. glEnable(GL_TEXTURE_2D);
  581. glBindTexture(GL_TEXTURE_2D,19);
  582. glPushMatrix();
  583.  
  584. if(da[id]==0)
  585. {
  586. glTranslatef(x,y,z);
  587. //glRotatef(da[id],0,1,0);
  588. glScalef(sx,sy,0.2);
  589. }
  590. else
  591. {
  592.  
  593. glTranslatef(x+(sx/2.0),y,z+(sx/2.0));
  594. glScalef(0.2,sy,sx);
  595. }
  596. glTranslatef(-0.5,-0.5,-0.5);
  597. cube(1,1,1);
  598. glPopMatrix();
  599. glDisable(GL_TEXTURE_2D);
  600. }
  601.  
  602.  
  603. void light1(float x,float y,float z)
  604. {
  605. //light
  606. GLfloat l1_no[] = {0, 0, 0, 1.0};
  607. GLfloat l1_amb[] = {0,0,0, 1.0};
  608. GLfloat l1_dif[] = {1,0,0,1};
  609. GLfloat l1_spec[] = {0,0,0,1};
  610. GLfloat l1_pos[] = {x,y,z,1.0};
  611. //GLfloat l_pos[] = {-14.5,-7,10,1.0};
  612. // glPushMatrix();
  613. // glTranslatef(x,y,z);
  614. // glScalef(10,10,10);
  615. // cube();
  616. // glPopMatrix();
  617.  
  618.  
  619.  
  620. glEnable(GL_LIGHT0);
  621.  
  622. if(press1)
  623. {
  624. glLightfv(GL_LIGHT0, GL_AMBIENT, l1_amb);
  625. }
  626. else
  627. {
  628. glLightfv(GL_LIGHT0, GL_AMBIENT, l1_no);
  629. }
  630. if(press1)
  631. {
  632. glLightfv(GL_LIGHT0, GL_DIFFUSE, l1_dif);
  633. }
  634. else
  635. {
  636. glLightfv(GL_LIGHT0, GL_DIFFUSE, l1_no);
  637. }
  638. if(press1)
  639. {
  640. glLightfv(GL_LIGHT0, GL_SPECULAR, l1_spec);
  641. }
  642. else
  643. {
  644. glLightfv(GL_LIGHT0, GL_SPECULAR, l1_no);
  645. }
  646.  
  647.  
  648. glLightfv(GL_LIGHT0, GL_POSITION, l1_pos);
  649. }
  650.  
  651. void light2(float x,float y, float z)
  652. {
  653. //light
  654. GLfloat l2_no[] = {0, 0, 0, 1.0};
  655. GLfloat l2_amb[] = {0.1, 0.1, 0.1, 1.0};
  656. GLfloat l2_dif[] = {1,1,1,1};
  657. GLfloat l2_spec[] = {1,1,1,1};
  658. //GLfloat l_pos[] = {-14.5,7,0,1.0};
  659. GLfloat l2_pos[] = {x,y,z,1.0};
  660.  
  661. glEnable(GL_LIGHT1);
  662.  
  663. if(press2)
  664. {
  665. glLightfv(GL_LIGHT1, GL_AMBIENT, l2_amb);
  666. }
  667. else
  668. {
  669. glLightfv(GL_LIGHT1, GL_AMBIENT, l2_no);
  670. }
  671. if(press2)
  672. {
  673. glLightfv(GL_LIGHT1, GL_DIFFUSE, l2_dif);
  674. }
  675. else
  676. {
  677. glLightfv(GL_LIGHT1, GL_DIFFUSE, l2_no);
  678. }
  679. if(press2)
  680. {
  681. glLightfv(GL_LIGHT1, GL_SPECULAR, l2_spec);
  682. }
  683. else
  684. {
  685. glLightfv(GL_LIGHT1, GL_SPECULAR, l2_no);
  686. }
  687.  
  688. glLightfv(GL_LIGHT1, GL_POSITION, l2_pos);
  689. }
  690.  
  691. void light3(float x,float y, float z)
  692. {
  693. //light
  694. GLfloat l3_no[] = {0, 0, 0, 1.0};
  695. GLfloat l3_amb[] = {0.5, 0.5, 0.5, 1.0};
  696. GLfloat l3_dif[] = {1,0,1,1};
  697. GLfloat l3_spec[] = {1,0,1,1};
  698. GLfloat l3_pos[] = {x,y,z,1.0};
  699. //GLfloat l_pos[] = {14,-7,10,1.0};
  700.  
  701. glEnable(GL_LIGHT2);
  702.  
  703. if(press4)
  704. {
  705. glLightfv(GL_LIGHT2, GL_AMBIENT, l3_amb);
  706. }
  707. else
  708. {
  709. glLightfv(GL_LIGHT2, GL_AMBIENT, l3_no);
  710. }
  711. if(press4)
  712. {
  713. glLightfv(GL_LIGHT2, GL_DIFFUSE, l3_dif);
  714. }
  715. else
  716. {
  717. glLightfv(GL_LIGHT2, GL_DIFFUSE, l3_no);
  718. }
  719. if(press4)
  720. {
  721. glLightfv(GL_LIGHT2, GL_SPECULAR, l3_spec);
  722. }
  723. else
  724. {
  725. glLightfv(GL_LIGHT2, GL_SPECULAR, l3_no);
  726. }
  727.  
  728. glLightfv(GL_LIGHT2, GL_POSITION, l3_pos);
  729.  
  730. // spot light extra
  731. GLfloat l3_spt[] = {0,0,-1,1};
  732. GLfloat spt_ct[] = {60};
  733. glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, l3_spt);
  734. glLightfv(GL_LIGHT2, GL_SPOT_CUTOFF, spt_ct);
  735.  
  736. }
  737. void DrawCircle(float cx, float cy, float r, int num_segments)
  738. {
  739. glBegin(GL_TRIANGLE_FAN);
  740. for(int ii = 0; ii < num_segments; ii++)
  741. {
  742. float theta = 2.0f * 3.1415926f * float(ii) / float(num_segments);//get the current angle
  743.  
  744. float x = r * cosf(theta);//calculate the x component
  745. float y = r * sinf(theta);//calculate the y component
  746.  
  747. glVertex2f(x + cx, y + cy);//output vertex
  748.  
  749. }
  750. glEnd();
  751. }
  752.  
  753.  
  754. static GLfloat v_pyramid[5][3] =
  755. {
  756. {0.0, 0.0, 0.0},
  757. {0.0, 0.0, 2.0},
  758. {2.0, 0.0, 2.0},
  759. {2.0, 0.0, 0.0},
  760. {1.0, 4.0, 1.0}
  761. };
  762.  
  763. static GLubyte p_Indices[4][3] =
  764. {
  765. {4, 1, 2},
  766. {4, 2, 3},
  767. {4, 3, 0},
  768. {4, 0, 1}
  769. };
  770.  
  771. static GLubyte quadIndices[1][4] =
  772. {
  773. {0, 3, 2, 1}
  774. };
  775.  
  776. static GLfloat colors[5][3] =
  777. {
  778. {0.0, 0.0, 1.0},
  779. {0.5, 0.0, 1.0},
  780. {0.0, 1.0, 0.0},
  781. {0.0, 1.0, 1.0},
  782. {0.8, 0.0, 0.0}
  783. };
  784.  
  785. void drawpyramid()
  786. {
  787. //glDisable(GL_LIGHTING);
  788. //glColor3f(1,0,0);
  789. glBegin(GL_TRIANGLES);
  790. for (GLint i = 0; i <4; i++)
  791. {
  792. //glColor3f(colors[i][0],colors[i][1],colors[i][2]);
  793. getNormal3p(v_pyramid[p_Indices[i][0]][0], v_pyramid[p_Indices[i][0]][1], v_pyramid[p_Indices[i][0]][2],
  794. v_pyramid[p_Indices[i][1]][0], v_pyramid[p_Indices[i][1]][1], v_pyramid[p_Indices[i][1]][2],
  795. v_pyramid[p_Indices[i][2]][0], v_pyramid[p_Indices[i][2]][1], v_pyramid[p_Indices[i][2]][2]);
  796.  
  797. glVertex3fv(&v_pyramid[p_Indices[i][0]][0]);
  798. glVertex3fv(&v_pyramid[p_Indices[i][1]][0]);
  799. glVertex3fv(&v_pyramid[p_Indices[i][2]][0]);
  800. }
  801. glEnd();
  802.  
  803. glBegin(GL_QUADS);
  804. for (GLint i = 0; i <1; i++)
  805. {
  806. //glColor3f(colors[4][0],colors[4][1],colors[4][2]);
  807. getNormal3p(v_pyramid[quadIndices[i][0]][0], v_pyramid[quadIndices[i][0]][1], v_pyramid[quadIndices[i][0]][2],
  808. v_pyramid[quadIndices[i][1]][0], v_pyramid[quadIndices[i][1]][1], v_pyramid[quadIndices[i][1]][2],
  809. v_pyramid[quadIndices[i][2]][0], v_pyramid[quadIndices[i][2]][1], v_pyramid[quadIndices[i][2]][2]);
  810.  
  811. glVertex3fv(&v_pyramid[quadIndices[i][0]][0]);
  812. glVertex3fv(&v_pyramid[quadIndices[i][1]][0]);
  813. glVertex3fv(&v_pyramid[quadIndices[i][2]][0]);
  814. glVertex3fv(&v_pyramid[quadIndices[i][3]][0]);
  815. }
  816. glEnd();
  817.  
  818.  
  819. }
  820.  
  821.  
  822. void building()
  823. {
  824. ///Building Front Right
  825. glEnable(GL_TEXTURE_2D);
  826. glBindTexture(GL_TEXTURE_2D,4);
  827. glPushMatrix();
  828. glTranslatef(-25,0,35);
  829. glScalef(40,40,0.1);
  830. glTranslatef(-0.5,-0.5,-0.5);
  831. cube(1,1,1);
  832. glPopMatrix();
  833. glDisable(GL_TEXTURE_2D);
  834. glEnable(GL_TEXTURE_2D);
  835. glBindTexture(GL_TEXTURE_2D,5);
  836. glPushMatrix();
  837. glTranslatef(-25,0,35.1);
  838. glScalef(40,40,0.1);
  839. glTranslatef(-0.5,-0.5,-0.5);
  840. cube(1,1,1);
  841. glPopMatrix();
  842. glDisable(GL_TEXTURE_2D);
  843.  
  844. ///Building Front Left
  845. glEnable(GL_TEXTURE_2D);
  846. glBindTexture(GL_TEXTURE_2D,4);
  847. glPushMatrix();
  848. glTranslatef(25,0,35);
  849. glScalef(40,40,0.1);
  850. glTranslatef(-0.5,-0.5,-0.5);
  851. cube(1,1,1);
  852. glPopMatrix();
  853. glDisable(GL_TEXTURE_2D);
  854. glEnable(GL_TEXTURE_2D);
  855. glBindTexture(GL_TEXTURE_2D,5);
  856. glPushMatrix();
  857. glTranslatef(25,0,35.1);
  858. glScalef(40,40,0.1);
  859. glTranslatef(-0.5,-0.5,-0.5);
  860. cube(1,1,1);
  861. glPopMatrix();
  862. glDisable(GL_TEXTURE_2D);
  863.  
  864. ///Building Right
  865. glEnable(GL_TEXTURE_2D);
  866. glBindTexture(GL_TEXTURE_2D,4);
  867. glPushMatrix();
  868. glTranslatef(-45,0,75);
  869. glScalef(0.1,40,80);
  870. glTranslatef(-0.5,-0.5,-0.5);
  871. cube(1,1,1);
  872. glPopMatrix();
  873. glDisable(GL_TEXTURE_2D);
  874. glEnable(GL_TEXTURE_2D);
  875. glBindTexture(GL_TEXTURE_2D,5);
  876. glPushMatrix();
  877. glTranslatef(-44.9,0,75);
  878. glScalef(0.1,40,80);
  879. glTranslatef(-0.5,-0.5,-0.5);
  880. cube(1,1,1);
  881. glPopMatrix();
  882. glDisable(GL_TEXTURE_2D);
  883.  
  884. ///Building Left
  885. glEnable(GL_TEXTURE_2D);
  886. glBindTexture(GL_TEXTURE_2D,4);
  887. glPushMatrix();
  888. glTranslatef(45,0,75);
  889. glScalef(0.1,40,80);
  890. glTranslatef(-0.5,-0.5,-0.5);
  891. cube(1,1,1);
  892. glPopMatrix();
  893. glDisable(GL_TEXTURE_2D);
  894. glEnable(GL_TEXTURE_2D);
  895. glBindTexture(GL_TEXTURE_2D,5);
  896. glPushMatrix();
  897. glTranslatef(44.9,0,75);
  898. glScalef(0.1,40,80);
  899. glTranslatef(-0.5,-0.5,-0.5);
  900. cube(1,1,1);
  901. glPopMatrix();
  902. glDisable(GL_TEXTURE_2D);
  903.  
  904. ///Building Back Left
  905. glEnable(GL_TEXTURE_2D);
  906. glBindTexture(GL_TEXTURE_2D,4);
  907. glPushMatrix();
  908. glTranslatef(25,0,115);
  909. glScalef(40,40,0.1);
  910. glTranslatef(-0.5,-0.5,-0.5);
  911. cube(1,1,1);
  912. glPopMatrix();
  913. glDisable(GL_TEXTURE_2D);
  914. glEnable(GL_TEXTURE_2D);
  915. glBindTexture(GL_TEXTURE_2D,5);
  916. glPushMatrix();
  917. glTranslatef(25,0,114.9);
  918. glScalef(40,40,0.1);
  919. glTranslatef(-0.5,-0.5,-0.5);
  920. cube(1,1,1);
  921. glPopMatrix();
  922. glDisable(GL_TEXTURE_2D);
  923.  
  924. ///Building Back Right
  925. glEnable(GL_TEXTURE_2D);
  926. glBindTexture(GL_TEXTURE_2D,4);
  927. glPushMatrix();
  928. glTranslatef(-25,0,115);
  929. glScalef(40,40,0.1);
  930. glTranslatef(-0.5,-0.5,-0.5);
  931. cube(1,1,1);
  932. glPopMatrix();
  933. glDisable(GL_TEXTURE_2D);
  934. glEnable(GL_TEXTURE_2D);
  935. glBindTexture(GL_TEXTURE_2D,5);
  936. glPushMatrix();
  937. glTranslatef(-25,0,114.9);
  938. glScalef(40,40,0.1);
  939. glTranslatef(-0.5,-0.5,-0.5);
  940. cube(1,1,1);
  941. glPopMatrix();
  942. glDisable(GL_TEXTURE_2D);
  943.  
  944. ///Inside Front Left
  945. glEnable(GL_TEXTURE_2D);
  946. glBindTexture(GL_TEXTURE_2D,5);
  947. glPushMatrix();
  948. glTranslatef(5,0,45);
  949. glScalef(0.1,40,20);
  950. glTranslatef(-0.5,-0.5,-0.5);
  951. cube(1,1,1);
  952. glPopMatrix();
  953. glDisable(GL_TEXTURE_2D);
  954.  
  955. ///Inside Front Right
  956. glEnable(GL_TEXTURE_2D);
  957. glBindTexture(GL_TEXTURE_2D,5);
  958. glPushMatrix();
  959. glTranslatef(-5,0,45);
  960. glScalef(0.1,40,20);
  961. glTranslatef(-0.5,-0.5,-0.5);
  962. cube(1,1,1);
  963. glPopMatrix();
  964. glDisable(GL_TEXTURE_2D);
  965.  
  966. ///Inside Back Left
  967. glEnable(GL_TEXTURE_2D);
  968. glBindTexture(GL_TEXTURE_2D,5);
  969. glPushMatrix();
  970. glTranslatef(5,0,105);
  971. glScalef(0.1,40,20);
  972. glTranslatef(-0.5,-0.5,-0.5);
  973. cube(1,1,1);
  974. glPopMatrix();
  975. glDisable(GL_TEXTURE_2D);
  976.  
  977. ///Inside Back Right
  978. glEnable(GL_TEXTURE_2D);
  979. glBindTexture(GL_TEXTURE_2D,5);
  980. glPushMatrix();
  981. glTranslatef(-5,0,105);
  982. glScalef(0.1,40,20);
  983. glTranslatef(-0.5,-0.5,-0.5);
  984. cube(1,1,1);
  985. glPopMatrix();
  986. glDisable(GL_TEXTURE_2D);
  987.  
  988. ///Inside Front Left2
  989. glEnable(GL_TEXTURE_2D);
  990. glBindTexture(GL_TEXTURE_2D,5);
  991. glPushMatrix();
  992. glTranslatef(-27.5,0,55);
  993. glScalef(35,40,0.1);
  994. glTranslatef(-0.5,-0.5,-0.5);
  995. cube(1,1,1);
  996. glPopMatrix();
  997. glDisable(GL_TEXTURE_2D);
  998. door(-7.5,7.5,55,1,5,25);
  999.  
  1000.  
  1001. ///Inside Front Right2
  1002. glEnable(GL_TEXTURE_2D);
  1003. glBindTexture(GL_TEXTURE_2D,5);
  1004. glPushMatrix();
  1005. glTranslatef(27.5,0,55);
  1006. glScalef(35,40,0.1);
  1007. glTranslatef(-0.5,-0.5,-0.5);
  1008. cube(1,1,1);
  1009. glPopMatrix();
  1010. glDisable(GL_TEXTURE_2D);
  1011. door(7.5,7.5,55,2,5,25);
  1012.  
  1013. ///Inside Back Left2
  1014. glEnable(GL_TEXTURE_2D);
  1015. glBindTexture(GL_TEXTURE_2D,5);
  1016. glPushMatrix();
  1017. glTranslatef(-27.5,0,95);
  1018. glScalef(35,40,0.1);
  1019. glTranslatef(-0.5,-0.5,-0.5);
  1020. cube(1,1,1);
  1021. glPopMatrix();
  1022. glDisable(GL_TEXTURE_2D);
  1023. door(-7.5,7.5,95,3,5,25);
  1024.  
  1025. ///Inside Back Right2
  1026. glEnable(GL_TEXTURE_2D);
  1027. glBindTexture(GL_TEXTURE_2D,5);
  1028. glPushMatrix();
  1029. glTranslatef(27.5,0,95);
  1030. glScalef(35,40,0.1);
  1031. glTranslatef(-0.5,-0.5,-0.5);
  1032. cube(1,1,1);
  1033. glPopMatrix();
  1034. glDisable(GL_TEXTURE_2D);
  1035. door(7.5,7.5,95,4,5,25);
  1036.  
  1037. ///Inside Right
  1038. glEnable(GL_TEXTURE_2D);
  1039. glBindTexture(GL_TEXTURE_2D,5);
  1040. glPushMatrix();
  1041. glTranslatef(-25,0,72.5);
  1042. glScalef(0.1,40,35);
  1043. glTranslatef(-0.5,-0.5,-0.5);
  1044. cube(1,1,1);
  1045. glPopMatrix();
  1046. glDisable(GL_TEXTURE_2D);
  1047.  
  1048. glPushMatrix();
  1049. door(-27.5,7.5,90,5,5,25);
  1050. glPopMatrix();
  1051.  
  1052. ///Inside Left
  1053. glEnable(GL_TEXTURE_2D);
  1054. glBindTexture(GL_TEXTURE_2D,5);
  1055. glPushMatrix();
  1056. glTranslatef(25,0,72.5);
  1057. glScalef(0.1,40,35);
  1058. glTranslatef(-0.5,-0.5,-0.5);
  1059. cube(1,1,1);
  1060. glPopMatrix();
  1061. glDisable(GL_TEXTURE_2D);
  1062.  
  1063. glPushMatrix();
  1064. door(22.5,7.5,90,6,5,25);
  1065. glPopMatrix();
  1066.  
  1067. }
  1068. void car()
  1069. {
  1070.  
  1071. glEnable(GL_LIGHTING);
  1072. //whole car
  1073. glPushMatrix();
  1074. //glRotatef(90,0,1,0);
  1075. glTranslatef(5,0.5,20);
  1076. //body
  1077.  
  1078. glPushMatrix();
  1079. glTranslatef(0,1.5,0);
  1080. glScalef(8,2,3);
  1081. glTranslatef(-0.5,-0.5,-0.5);
  1082. //cube();
  1083. cube(0.9,0.9,0.9);
  1084. //cube(0.5804,0.5451,0.5568);
  1085. glPopMatrix();
  1086.  
  1087.  
  1088. //top
  1089. glPushMatrix();
  1090. glTranslatef(0,3.5,0);
  1091. glScalef(4,2,3);
  1092. glTranslatef(-0.5,-0.5,-0.5);
  1093. //cube();
  1094. cube(0.7569,0.7569,0.847);
  1095. //cube(0.5804,0.5451,0.5568);
  1096. glPopMatrix();
  1097.  
  1098. //glass
  1099. glPushMatrix();
  1100. glTranslatef(0.95,3.45,1.5);
  1101. glScalef(1.8,1.8,0.1);
  1102. glTranslatef(-0.5,-0.5,-0.5);
  1103. //cube();
  1104. cube(0,0,0);
  1105. //cube(0.5804,0.5451,0.5568);
  1106. glPopMatrix();
  1107.  
  1108. glPushMatrix();
  1109. glTranslatef(-0.95,3.45,1.5);
  1110. glScalef(1.8,1.8,0.1);
  1111. glTranslatef(-0.5,-0.5,-0.5);
  1112. //cube();
  1113. cube(0,0,0);
  1114. //cube(0.5804,0.5451,0.5568);
  1115. glPopMatrix();
  1116.  
  1117. glPushMatrix();
  1118. glTranslatef(0.95,3.45,-1.5);
  1119. glScalef(1.8,1.8,0.1);
  1120. glTranslatef(-0.5,-0.5,-0.5);
  1121. //cube();
  1122. cube(0,0,0);
  1123. //cube(0.5804,0.5451,0.5568);
  1124. glPopMatrix();
  1125.  
  1126. glPushMatrix();
  1127. glTranslatef(-0.95,3.45,-1.5);
  1128. glScalef(1.8,1.8,0.1);
  1129. glTranslatef(-0.5,-0.5,-0.5);
  1130. //cube();
  1131. cube(0,0,0);
  1132. //cube(0.5804,0.5451,0.5568);
  1133. glPopMatrix();
  1134.  
  1135. //front glass
  1136.  
  1137. glPushMatrix();
  1138. glTranslatef(2,3.45,0);
  1139. glScalef(0.1,1.8,3);
  1140. glTranslatef(-0.5,-0.5,-0.5);
  1141. //cube();
  1142. cube(0,0,0);
  1143. //cube(0.5804,0.5451,0.5568);
  1144. glPopMatrix();
  1145.  
  1146. glPushMatrix();
  1147. glTranslatef(-2,3.45,0);
  1148. glScalef(0.1,1.8,3);
  1149. glTranslatef(-0.5,-0.5,-0.5);
  1150. //cube();
  1151. cube(0,0,0);
  1152. //cube(0.5804,0.5451,0.5568);
  1153. glPopMatrix();
  1154.  
  1155.  
  1156. //frontlight
  1157. glEnable(GL_TEXTURE_2D);
  1158. glBindTexture(GL_TEXTURE_2D,8);
  1159. glPushMatrix();
  1160. glTranslatef(-4,1.45,0);
  1161. glScalef(0.1,1.8,3);
  1162. glTranslatef(-0.5,-0.5,-0.5);
  1163. //cube();
  1164. cube();
  1165. //cube(0.5804,0.5451,0.5568);
  1166. glPopMatrix();
  1167. glDisable(GL_TEXTURE_2D);
  1168.  
  1169. //backlight
  1170. glEnable(GL_TEXTURE_2D);
  1171. glBindTexture(GL_TEXTURE_2D,8);
  1172. glPushMatrix();
  1173. glTranslatef(4,1.45,0);
  1174. glScalef(0.1,1.8,3);
  1175. glTranslatef(-0.5,-0.5,-0.5);
  1176. //cube();
  1177. set_material(0.5,0.5,0.5,true,press4);
  1178. cube();
  1179. //cube(0.5804,0.5451,0.5568);
  1180. glPopMatrix();
  1181. glDisable(GL_TEXTURE_2D);
  1182. glPopMatrix();
  1183.  
  1184. glDisable(GL_LIGHTING);
  1185.  
  1186. }
  1187.  
  1188. void LoadTexture(const char*filename)
  1189. {
  1190. glGenTextures(1, &ID);
  1191. glBindTexture(GL_TEXTURE_2D, ID);
  1192. glPixelStorei(GL_UNPACK_ALIGNMENT, ID);
  1193. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
  1194. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  1195. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
  1196. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  1197. BmpLoader bl(filename);
  1198. gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, bl.iWidth, bl.iHeight, GL_RGB, GL_UNSIGNED_BYTE, bl.textureData );
  1199. }
  1200.  
  1201. void cover()
  1202. {
  1203.  
  1204. ///Front
  1205. glEnable(GL_TEXTURE_2D);
  1206. glBindTexture(GL_TEXTURE_2D,9);
  1207. glPushMatrix();
  1208. glTranslatef(0,20,45);
  1209. glScalef(90,0.1,20);
  1210. glTranslatef(-0.5,-0.5,-0.5);
  1211. cube(1,1,1);
  1212. glPopMatrix();
  1213. glDisable(GL_TEXTURE_2D);
  1214.  
  1215. ///Back
  1216. glEnable(GL_TEXTURE_2D);
  1217. glBindTexture(GL_TEXTURE_2D,9);
  1218. glPushMatrix();
  1219. glTranslatef(0,20,105);
  1220. glScalef(90,0.1,20);
  1221. glTranslatef(-0.5,-0.5,-0.5);
  1222. cube(1,1,1);
  1223. glPopMatrix();
  1224. glDisable(GL_TEXTURE_2D);
  1225.  
  1226. ///Left
  1227. glEnable(GL_TEXTURE_2D);
  1228. glBindTexture(GL_TEXTURE_2D,9);
  1229. glPushMatrix();
  1230. glTranslatef(35,20,75);
  1231. glScalef(20,0.1,40);
  1232. glTranslatef(-0.5,-0.5,-0.5);
  1233. cube(1,1,1);
  1234. glPopMatrix();
  1235. glDisable(GL_TEXTURE_2D);
  1236.  
  1237. ///Right
  1238. glEnable(GL_TEXTURE_2D);
  1239. glBindTexture(GL_TEXTURE_2D,9);
  1240. glPushMatrix();
  1241. glTranslatef(-35,20,75);
  1242. glScalef(20,0.1,40);
  1243. glTranslatef(-0.5,-0.5,-0.5);
  1244. cube(1,1,1);
  1245. glPopMatrix();
  1246. glDisable(GL_TEXTURE_2D);
  1247. }
  1248. void goalpost()
  1249. {
  1250. ///Left Post
  1251. glEnable(GL_TEXTURE_2D);
  1252. glBindTexture(GL_TEXTURE_2D,10);
  1253. glPushMatrix();
  1254. glTranslatef(17.5,0,78);
  1255. glScalef(0.3,15,0.3);
  1256. glTranslatef(-0.5,-0.5,-0.5);
  1257. cube(1,1,1);
  1258. glPopMatrix();
  1259. glDisable(GL_TEXTURE_2D);
  1260.  
  1261. glEnable(GL_TEXTURE_2D);
  1262. glBindTexture(GL_TEXTURE_2D,10);
  1263. glPushMatrix();
  1264. glTranslatef(17.5,0,72);
  1265. glScalef(0.3,15,0.3);
  1266. glTranslatef(-0.5,-0.5,-0.5);
  1267. cube(1,1,1);
  1268. glPopMatrix();
  1269. glDisable(GL_TEXTURE_2D);
  1270.  
  1271. glEnable(GL_TEXTURE_2D);
  1272. glBindTexture(GL_TEXTURE_2D,10);
  1273. glPushMatrix();
  1274. glTranslatef(17.5,7.5,75);
  1275. glRotatef(90,1,0,0);
  1276. glScalef(0.3,6,0.3);
  1277. glTranslatef(-0.5,-0.5,-0.5);
  1278. cube(1,1,1);
  1279. glPopMatrix();
  1280. glDisable(GL_TEXTURE_2D);
  1281.  
  1282.  
  1283. ///Right Post
  1284. glEnable(GL_TEXTURE_2D);
  1285. glBindTexture(GL_TEXTURE_2D,10);
  1286. glPushMatrix();
  1287. glTranslatef(-17.5,0,78);
  1288. glScalef(0.3,15,0.3);
  1289. glTranslatef(-0.5,-0.5,-0.5);
  1290. cube(1,1,1);
  1291. glPopMatrix();
  1292. glDisable(GL_TEXTURE_2D);
  1293.  
  1294. glEnable(GL_TEXTURE_2D);
  1295. glBindTexture(GL_TEXTURE_2D,10);
  1296. glPushMatrix();
  1297. glTranslatef(-17.5,0,72);
  1298. glScalef(0.3,15,0.3);
  1299. glTranslatef(-0.5,-0.5,-0.5);
  1300. cube(1,1,1);
  1301. glPopMatrix();
  1302. glDisable(GL_TEXTURE_2D);
  1303.  
  1304. glEnable(GL_TEXTURE_2D);
  1305. glBindTexture(GL_TEXTURE_2D,10);
  1306. glPushMatrix();
  1307. glTranslatef(-17.5,7.5,75);
  1308. glRotatef(90,1,0,0);
  1309. glScalef(0.3,6,0.3);
  1310. glTranslatef(-0.5,-0.5,-0.5);
  1311. cube(1,1,1);
  1312. glPopMatrix();
  1313. glDisable(GL_TEXTURE_2D);
  1314. }
  1315. void fence()
  1316. {
  1317. ///Fence Left
  1318. glEnable(GL_TEXTURE_2D);
  1319. glBindTexture(GL_TEXTURE_2D,3);
  1320. glPushMatrix();
  1321. glTranslatef(30,0,25);
  1322. glScalef(50,10,0.5);
  1323. glTranslatef(-0.5,-0.5,-0.5);
  1324. cube(1,1,1);
  1325. glPopMatrix();
  1326. glDisable(GL_TEXTURE_2D);
  1327.  
  1328. glEnable(GL_TEXTURE_2D);
  1329. glBindTexture(GL_TEXTURE_2D,3);
  1330. glPushMatrix();
  1331. glTranslatef(55,0,75);
  1332. glScalef(0.5,10,100);
  1333. glTranslatef(-0.5,-0.5,-0.5);
  1334. cube(1,1,1);
  1335. glPopMatrix();
  1336. glDisable(GL_TEXTURE_2D);
  1337.  
  1338. ///Fence Right
  1339. glEnable(GL_TEXTURE_2D);
  1340. glBindTexture(GL_TEXTURE_2D,3);
  1341. glPushMatrix();
  1342. glTranslatef(-30,0,25);
  1343. glScalef(50,10,0.5);
  1344. glTranslatef(-0.5,-0.5,-0.5);
  1345. cube(1,1,1);
  1346. glPopMatrix();
  1347. glDisable(GL_TEXTURE_2D);
  1348.  
  1349. glEnable(GL_TEXTURE_2D);
  1350. glBindTexture(GL_TEXTURE_2D,3);
  1351. glPushMatrix();
  1352. glTranslatef(-55,0,75);
  1353. glScalef(0.5,10,100);
  1354. glTranslatef(-0.5,-0.5,-0.5);
  1355. cube(1,1,1);
  1356. glPopMatrix();
  1357. glDisable(GL_TEXTURE_2D);
  1358. }
  1359. void wardrobe(float x,float y,float z)
  1360. {
  1361.  
  1362. ///wardrobe body
  1363. glEnable(GL_TEXTURE_2D);
  1364. glBindTexture(GL_TEXTURE_2D,11);
  1365. glPushMatrix();
  1366. glTranslatef(x,y,z);
  1367. glScalef(10,20,5);
  1368. glTranslatef(-0.5,-0.5,-0.5);
  1369. cube(1,1,1);
  1370. glPopMatrix();
  1371. glDisable(GL_TEXTURE_2D);
  1372.  
  1373. ///wardrobe front
  1374. glEnable(GL_TEXTURE_2D);
  1375. glBindTexture(GL_TEXTURE_2D,12);
  1376. glPushMatrix();
  1377. glTranslatef(x+5,y,z);
  1378. glScalef(0.1,20,5);
  1379. glTranslatef(-0.5,-0.5,-0.5);
  1380. cube(1,1,1);
  1381. glPopMatrix();
  1382. glDisable(GL_TEXTURE_2D);
  1383. }
  1384. void board()
  1385. {
  1386.  
  1387. glPushMatrix();
  1388. // glColorMaterial ( GL_FRONT_AND_BACK, GL_EMISSION ) ;
  1389. // glEnable ( GL_COLOR_MATERIAL ) ;
  1390. // glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,0);
  1391. glEnable(GL_LIGHTING);
  1392. glTranslatef(5.1,15,48);
  1393. glScalef(0.1,5,10);
  1394. glTranslatef(-0.5,-0.5,-0.5);
  1395. cube(0,0,0,1,1);
  1396. glDisable(GL_LIGHTING);
  1397. glPopMatrix();
  1398.  
  1399. }
  1400. void clock()
  1401. {
  1402. glEnable(GL_TEXTURE_2D);
  1403. glBindTexture(GL_TEXTURE_2D,14);
  1404. glPushMatrix();
  1405. glTranslatef(15,4,44);
  1406. ///Clock
  1407. glPushMatrix();
  1408. glTranslatef(5.3,10.5,9.6);
  1409. glScalef(4,4,0.1);
  1410. cube(1,1,1);
  1411. glPopMatrix();
  1412.  
  1413. ///Circle
  1414. glPushMatrix();
  1415. glTranslatef(0,5,10);
  1416. glScalef(15,15,15);
  1417. DrawCircle(0.5, 0.5, 0.2, 100);
  1418. glPopMatrix();
  1419. glPopMatrix();
  1420. glDisable(GL_TEXTURE_2D);
  1421. }
  1422. void fan()
  1423. {
  1424. float height = 10;
  1425.  
  1426. glPushMatrix();
  1427. glEnable(GL_LIGHTING);
  1428. glTranslatef(25,10,45);
  1429. //glScalef(10,5,10);
  1430. // for(int i=0; i<=360 ; i=i+10)
  1431. // {
  1432. //
  1433. // glPushMatrix();
  1434. // glTranslatef(0,height,0);
  1435. // glRotatef(i,0,1,0);
  1436. // glScalef(5,2.5/8,2.5);
  1437. // glTranslatef(-0.5,0,-0.5);
  1438. // cube(0.502, 0.000, 0.502);
  1439. // glPopMatrix();
  1440. //
  1441. // }
  1442.  
  1443. glPushMatrix();
  1444. glTranslatef(0,height-5-2.5/8,0);
  1445. glScalef(1,4,1);
  1446. glTranslatef(-0.5,0,-0.5);
  1447. cube(0,0,0);
  1448. glPopMatrix();
  1449.  
  1450. glPushMatrix();
  1451. glRotatef(spin,0,1,0);
  1452. for(int i=0; i<=360 ; i=i+10)
  1453. {
  1454.  
  1455. glPushMatrix();
  1456. glTranslatef(0,height-5-2.5/8-2.5,0);
  1457. glRotatef(i,0,1,0);
  1458. glScalef(5,2.5,2.5);
  1459. glTranslatef(-0.5,0,-0.5);
  1460. cube(1.000, 1.000, 0.000);
  1461. glPopMatrix();
  1462.  
  1463. }
  1464.  
  1465. glPushMatrix();
  1466. glTranslatef(0,height-5-2.5/8-2.5+1,0);
  1467. glScalef(15,0.5,2.5);
  1468. glTranslatef(-0.5,0,-0.5);
  1469. cube(0, 0.000, 0.502);
  1470. glPopMatrix();
  1471.  
  1472. glPushMatrix();
  1473. glTranslatef(0,height-5-2.5/8-2.5+1,0);
  1474. glScalef(2.5,0.5,15);
  1475. glTranslatef(-0.5,0,-0.5);
  1476. cube(0, 0.000, 0.502);
  1477.  
  1478. glPopMatrix();
  1479.  
  1480. glPopMatrix();
  1481. glDisable(GL_LIGHTING);
  1482. glPopMatrix();
  1483. }
  1484.  
  1485. void table(float x,float y,float z, unsigned int id=11)
  1486. {
  1487. float height=6;
  1488. float width=5;
  1489. float length=5;
  1490.  
  1491. float base_height=1;
  1492. float leg_height=height-base_height;
  1493. float leg_width=0.5;
  1494.  
  1495. // whole table
  1496. glEnable(GL_TEXTURE_2D);
  1497. glBindTexture(GL_TEXTURE_2D,id);
  1498. glPushMatrix();
  1499. glTranslatef(x,y,z);
  1500.  
  1501. // base
  1502. glPushMatrix();
  1503. glScalef(width,base_height,length);
  1504. glTranslatef(-0.5,0,-0.5);
  1505. cube(0.53,0.39,0.28);
  1506. glPopMatrix();
  1507.  
  1508. // legs
  1509. glPushMatrix();
  1510. glTranslatef((width/2-leg_width/2),0,(length/2-leg_width/2));
  1511. glScalef(leg_width,leg_height,leg_width);
  1512. glTranslatef(-0.5,-1,-0.5);
  1513. cube(0.53,0.39,0.28);
  1514. glPopMatrix();
  1515.  
  1516. glPushMatrix();
  1517. glTranslatef((width/2-leg_width/2),0,-(length/2-leg_width/2));
  1518. glScalef(leg_width,leg_height,leg_width);
  1519. glTranslatef(-0.5,-1,-0.5);
  1520. cube(0.53,0.39,0.28);
  1521. glPopMatrix();
  1522.  
  1523. glPushMatrix();
  1524. glTranslatef(-(width/2-leg_width/2),0,(length/2-leg_width/2));
  1525. glScalef(leg_width,leg_height,leg_width);
  1526. glTranslatef(-0.5,-1,-0.5);
  1527. cube(0.53,0.39,0.28);
  1528. glPopMatrix();
  1529.  
  1530. glPushMatrix();
  1531. glTranslatef(-(width/2-leg_width/2),0,-(length/2-leg_width/2));
  1532. glScalef(leg_width,leg_height,leg_width);
  1533. glTranslatef(-0.5,-1,-0.5);
  1534. cube(0.53,0.39,0.28);
  1535. glPopMatrix();
  1536.  
  1537. glPopMatrix();
  1538. glDisable(GL_TEXTURE_2D);
  1539.  
  1540. }
  1541.  
  1542.  
  1543. void chair(float x,float y,float z,int turned=0)
  1544. {
  1545. float height=3;
  1546. float width=3;
  1547. float length=3;
  1548.  
  1549. float base_height=1;
  1550. float leg_height=height-base_height;
  1551. float leg_width=0.5;
  1552.  
  1553. // whole chair
  1554. glEnable(GL_TEXTURE_2D);
  1555. glBindTexture(GL_TEXTURE_2D,13);
  1556. glPushMatrix();
  1557. glTranslatef(x,y,z);
  1558. if(!turned)
  1559. glRotatef(180,0,1,0);
  1560. else if(turned==3)
  1561. glRotatef(90,0,1,0);
  1562. else if(turned==2)
  1563. glRotatef(270,0,1,0);
  1564.  
  1565. // base
  1566. glPushMatrix();
  1567. glScalef(width,base_height-0.5,length);
  1568. glTranslatef(-0.5,0,-0.5);
  1569. cube(0.53,0.39,0.28);
  1570. glPopMatrix();
  1571.  
  1572. //back
  1573. glPushMatrix();
  1574. glTranslatef(-(width/2-leg_width/2),0,0);
  1575. glScalef(0.5,height,length);
  1576. glTranslatef(-0.5,0,-0.5);
  1577. cube(0.53,0.39,0.28);
  1578. glPopMatrix();
  1579.  
  1580. // legs
  1581. glPushMatrix();
  1582. glTranslatef((width/2-leg_width/2),0,(length/2-leg_width/2));
  1583. glScalef(leg_width,leg_height,leg_width);
  1584. glTranslatef(-0.5,-1,-0.5);
  1585. cube(0.53,0.39,0.28);
  1586. glPopMatrix();
  1587.  
  1588. glPushMatrix();
  1589. glTranslatef((width/2-leg_width/2),0,-(length/2-leg_width/2));
  1590. glScalef(leg_width,leg_height,leg_width);
  1591. glTranslatef(-0.5,-1,-0.5);
  1592. cube(0.53,0.39,0.28);
  1593. glPopMatrix();
  1594.  
  1595. glPushMatrix();
  1596. glTranslatef(-(width/2-leg_width/2),0,(length/2-leg_width/2));
  1597. glScalef(leg_width,leg_height,leg_width);
  1598. glTranslatef(-0.5,-1,-0.5);
  1599. cube(0.53,0.39,0.28);
  1600. glPopMatrix();
  1601.  
  1602. glPushMatrix();
  1603. glTranslatef(-(width/2-leg_width/2),0,-(length/2-leg_width/2));
  1604. glScalef(leg_width,leg_height,leg_width);
  1605. glTranslatef(-0.5,-1,-0.5);
  1606. cube(0.53,0.39,0.28);
  1607. glPopMatrix();
  1608.  
  1609. glPopMatrix();
  1610. glDisable(GL_TEXTURE_2D);
  1611.  
  1612. }
  1613.  
  1614. void tv()
  1615. {
  1616.  
  1617. glEnable(GL_TEXTURE_2D);
  1618. glBindTexture(GL_TEXTURE_2D,10);
  1619. glPushMatrix();
  1620. glTranslatef(-26,13,70);
  1621. glScalef(1,5,5);
  1622. cube(1,1,1);
  1623. glPopMatrix();
  1624. glDisable(GL_TEXTURE_2D);
  1625.  
  1626. glEnable(GL_LIGHTING);
  1627. glPushMatrix();
  1628. glTranslatef(-26,13,69);
  1629. glScalef(1,5,1);
  1630. cube(0,0,0);
  1631. glPopMatrix();
  1632.  
  1633. glPushMatrix();
  1634. glTranslatef(-26,13,75);
  1635. glScalef(1,5,1);
  1636. cube(0,0,0);
  1637. glPopMatrix();
  1638.  
  1639. glPushMatrix();
  1640. glTranslatef(-26,12,70);
  1641. glScalef(1,1,6);
  1642. cube(0,0,0);
  1643. glPopMatrix();
  1644. glPushMatrix();
  1645. glTranslatef(-26,18,70);
  1646. glScalef(1,1,6);
  1647. cube(0,0,0);
  1648. glPopMatrix();
  1649. glDisable(GL_LIGHTING);
  1650. }
  1651. void carrom()
  1652. {
  1653. glEnable(GL_TEXTURE_2D);
  1654. glBindTexture(GL_TEXTURE_2D,15);
  1655. glPushMatrix();
  1656. glTranslatef(30,7,65);
  1657. glScalef(5,1,5);
  1658. glTranslatef(-0.5,-0.5,-0.5);
  1659. cube(1,1,1);
  1660. glPopMatrix();
  1661. glDisable(GL_TEXTURE_2D);
  1662.  
  1663.  
  1664. glPushMatrix();
  1665. glTranslatef(1,0,0);
  1666. glEnable(GL_LIGHTING);
  1667. glPushMatrix();
  1668. glTranslatef(31.5,7.1,65);
  1669. glScalef(0.5,1,5);
  1670. glTranslatef(-0.5,-0.5,-0.5);
  1671. cube(0,0,0);
  1672. glPopMatrix();
  1673. glDisable(GL_LIGHTING);
  1674.  
  1675. glEnable(GL_LIGHTING);
  1676. glPushMatrix();
  1677. glTranslatef(26.5,7.1,65);
  1678. glScalef(0.5,1,5);
  1679. glTranslatef(-0.5,-0.5,-0.5);
  1680. cube(0,0,0);
  1681. glPopMatrix();
  1682. glDisable(GL_LIGHTING);
  1683.  
  1684. glEnable(GL_LIGHTING);
  1685. glPushMatrix();
  1686. glTranslatef(29,7.1,67.5);
  1687. glRotatef(90,0,1,0);
  1688. glScalef(0.5,1,5);
  1689. glTranslatef(-0.5,-0.5,-0.5);
  1690. cube(0,0,0);
  1691. glPopMatrix();
  1692. glDisable(GL_LIGHTING);
  1693.  
  1694. glEnable(GL_LIGHTING);
  1695. glPushMatrix();
  1696. glTranslatef(29,7.1,62.5);
  1697. glRotatef(90,0,1,0);
  1698. glScalef(0.5,1,5);
  1699. glTranslatef(-0.5,-0.5,-0.5);
  1700. cube(0,0,0);
  1701. glPopMatrix();
  1702. glDisable(GL_LIGHTING);
  1703.  
  1704. glPopMatrix();
  1705. ///Carrom balls
  1706. glEnable(GL_LIGHTING);
  1707. glPushMatrix();
  1708. glTranslatef(30,7.2,64);
  1709. glRotatef(90,1,1,0);
  1710. glScalef(1,1,1);
  1711. DrawCircle(0.5, 0.5, 0.2, 100);
  1712. glPopMatrix();
  1713. glDisable(GL_LIGHTING);
  1714.  
  1715. glEnable(GL_LIGHTING);
  1716. glPushMatrix();
  1717. glTranslatef(29,7.2,64.5);
  1718. glRotatef(90,1,1,0);
  1719. glScalef(1,1,1);
  1720. DrawCircle(0.5, 0.5, 0.2, 100);
  1721. glPopMatrix();
  1722. glDisable(GL_LIGHTING);
  1723.  
  1724. glEnable(GL_LIGHTING);
  1725. glPushMatrix();
  1726. glTranslatef(28,7.2,65);
  1727. glRotatef(90,1,1,0);
  1728. glScalef(1,1,1);
  1729. DrawCircle(0.5, 0.5, 0.2, 100);
  1730. glPopMatrix();
  1731. glDisable(GL_LIGHTING);
  1732.  
  1733. glEnable(GL_LIGHTING);
  1734. glPushMatrix();
  1735. glTranslatef(27.5,7.2,65.5);
  1736. glRotatef(90,1,1,0);
  1737. glScalef(1,1,1);
  1738. DrawCircle(0.5, 0.5, 0.2, 100);
  1739. glPopMatrix();
  1740. glDisable(GL_LIGHTING);
  1741.  
  1742.  
  1743. glPushMatrix();
  1744. glTranslatef(30,7.2,66);
  1745. glRotatef(90,1,1,0);
  1746. glScalef(1,1,1);
  1747. DrawCircle(0.5, 0.5, 0.2, 100);
  1748. glPopMatrix();
  1749.  
  1750. glPushMatrix();
  1751. glTranslatef(29,7.2,66.5);
  1752. glRotatef(90,1,1,0);
  1753. glScalef(1,1,1);
  1754. DrawCircle(0.5, 0.5, 0.2, 100);
  1755. glPopMatrix();
  1756.  
  1757. glPushMatrix();
  1758. glTranslatef(28,7.2,63);
  1759. glRotatef(90,1,1,0);
  1760. glScalef(1,1,1);
  1761. DrawCircle(0.5, 0.5, 0.2, 100);
  1762. glPopMatrix();
  1763.  
  1764.  
  1765.  
  1766. glPushMatrix();
  1767. glTranslatef(28,7.2,63.5);
  1768. glRotatef(90,1,1,0);
  1769. glScalef(1,1,1);
  1770. DrawCircle(0.5, 0.5, 0.2, 100);
  1771. glPopMatrix();
  1772.  
  1773.  
  1774. table(30,6,65);
  1775. }
  1776.  
  1777. void pingpong()
  1778. {
  1779. glEnable(GL_TEXTURE_2D);
  1780. glBindTexture(GL_TEXTURE_2D,13);
  1781. glPushMatrix();
  1782. glTranslatef(38,7,65);
  1783. glScalef(5,1,5);
  1784. glTranslatef(-0.5,-0.5,-0.5);
  1785. cube(1,1,1);
  1786. glPopMatrix();
  1787. glDisable(GL_TEXTURE_2D);
  1788.  
  1789.  
  1790.  
  1791. glPushMatrix();
  1792. glTranslatef(40.5,8,65);
  1793. glScalef(0.3,1.5,0.3);
  1794. glTranslatef(-0.5,-0.5,-0.5);
  1795. cube(1,1,1);
  1796. glPopMatrix();
  1797.  
  1798.  
  1799.  
  1800. glPushMatrix();
  1801. glTranslatef(35.5,8,65);
  1802. glScalef(0.3,1.5,0.3);
  1803. glTranslatef(-0.5,-0.5,-0.5);
  1804. cube(1,1,1);
  1805. glPopMatrix();
  1806.  
  1807. glEnable(GL_TEXTURE_2D);
  1808. glBindTexture(GL_TEXTURE_2D,18);
  1809. glPushMatrix();
  1810. glTranslatef(38,8,65);
  1811. glScalef(4.5,1.5,0.1);
  1812. glTranslatef(-0.5,-0.5,-0.5);
  1813. cube(1,1,1);
  1814. glPopMatrix();
  1815. glDisable(GL_TEXTURE_2D);
  1816.  
  1817. table(38,6,65);
  1818. }
  1819.  
  1820.  
  1821. void dart()
  1822. {
  1823. glEnable(GL_TEXTURE_2D);
  1824. glBindTexture(GL_TEXTURE_2D,17);
  1825. glPushMatrix();
  1826. glTranslatef(35,15,94);
  1827. glScalef(6,6,0.1);
  1828. glTranslatef(-0.5,-0.5,-0.5);
  1829. cube(1,1,1);
  1830. glPopMatrix();
  1831. glDisable(GL_TEXTURE_2D);
  1832.  
  1833. }
  1834. void chess()
  1835. {
  1836. table(38,6,75);
  1837.  
  1838. glEnable(GL_TEXTURE_2D);
  1839. glBindTexture(GL_TEXTURE_2D,16);
  1840. glPushMatrix();
  1841. glTranslatef(38,7,75);
  1842. glScalef(4,1,4);
  1843. glTranslatef(-0.5,-0.5,-0.5);
  1844. cube(1,1,1);
  1845. glPopMatrix();
  1846. glDisable(GL_TEXTURE_2D);
  1847.  
  1848. glPushMatrix();
  1849. //glRotatef(90,0,1,0);
  1850. chair(36,6,75,1);
  1851. chair(40,6,75);
  1852. glPopMatrix();
  1853. }
  1854.  
  1855.  
  1856.  
  1857. void classroom1(int id)
  1858. {
  1859.  
  1860. if(id==2)
  1861. {
  1862. wardrobe(11,7.5,48);
  1863. //chairtable();
  1864. table(12,6,39);
  1865. chair(10,6,39,1);
  1866. }
  1867. else
  1868. {
  1869. wardrobe(11,7.5,39);
  1870. //chairtable();
  1871. table(12,6,48);
  1872. chair(10,6,48,1);
  1873. }
  1874.  
  1875. board();
  1876. clock();
  1877. fan();
  1878.  
  1879.  
  1880.  
  1881. table(20,6,38);
  1882. chair(22,6,38);
  1883. table(20,6,45);
  1884. chair(22,6,45);
  1885. table(20,6,52);
  1886. chair(22,6,52);
  1887.  
  1888. table(30,6,38);
  1889. chair(32,6,38);
  1890. table(30,6,45);
  1891. chair(32,6,45);
  1892. table(30,6,52);
  1893. chair(32,6,52);
  1894.  
  1895. table(40,6,38);
  1896. chair(42,6,38);
  1897. table(40,6,45);
  1898. chair(42,6,45);
  1899. table(40,6,52);
  1900. chair(42,6,52);
  1901.  
  1902. }
  1903.  
  1904. void lab()
  1905. {
  1906.  
  1907. glEnable(GL_LIGHTING);
  1908. glPushMatrix();
  1909. glTranslatef(-40,7,38);
  1910. glScalef(0.2,2,2);
  1911. cube(0,0,0);
  1912. glPopMatrix();
  1913. glPushMatrix();
  1914. glTranslatef(-42,7,38);
  1915. glScalef(2,0.2,2);
  1916. cube(0,0,0);
  1917. glPopMatrix();
  1918.  
  1919. glPushMatrix();
  1920. glTranslatef(-40,7,45);
  1921. glScalef(0.2,2,2);
  1922. cube(0,0,0);
  1923. glPopMatrix();
  1924. glPushMatrix();
  1925. glTranslatef(-42,7,45);
  1926. glScalef(2,0.2,2);
  1927. cube(0,0,0);
  1928. glPopMatrix();
  1929.  
  1930. glPushMatrix();
  1931. glTranslatef(-40,7,52);
  1932. glScalef(0.2,2,2);
  1933. cube(0,0,0);
  1934. glPopMatrix();
  1935. glPushMatrix();
  1936. glTranslatef(-42,7,52);
  1937. glScalef(2,0.2,2);
  1938. cube(0,0,0);
  1939. glPopMatrix();
  1940.  
  1941. glPushMatrix();
  1942. glTranslatef(-30,7,38);
  1943. glScalef(0.2,2,2);
  1944. cube(0,0,0);
  1945. glPopMatrix();
  1946. glPushMatrix();
  1947. glTranslatef(-32,7,38);
  1948. glScalef(2,0.2,2);
  1949. cube(0,0,0);
  1950. glPopMatrix();
  1951.  
  1952. glPushMatrix();
  1953. glTranslatef(-30,7,45);
  1954. glScalef(0.2,2,2);
  1955. cube(0,0,0);
  1956. glPopMatrix();
  1957. glPushMatrix();
  1958. glTranslatef(-32,7,45);
  1959. glScalef(2,0.2,2);
  1960. cube(0,0,0);
  1961. glPopMatrix();
  1962.  
  1963. glPushMatrix();
  1964. glTranslatef(-30,7,52);
  1965. glScalef(0.2,2,2);
  1966. cube(0,0,0);
  1967. glPopMatrix();
  1968. glPushMatrix();
  1969. glTranslatef(-32,7,52);
  1970. glScalef(2,0.2,2);
  1971. cube(0,0,0);
  1972. glPopMatrix();
  1973.  
  1974. glPushMatrix();
  1975. glTranslatef(-20,7,38);
  1976. glScalef(0.2,2,2);
  1977. cube(0,0,0);
  1978. glPopMatrix();
  1979. glPushMatrix();
  1980. glTranslatef(-22,7,38);
  1981. glScalef(2,0.2,2);
  1982. cube(0,0,0);
  1983. glPopMatrix();
  1984.  
  1985. glPushMatrix();
  1986. glTranslatef(-20,7,45);
  1987. glScalef(0.2,2,2);
  1988. cube(0,0,0);
  1989. glPopMatrix();
  1990. glPushMatrix();
  1991. glTranslatef(-22,7,45);
  1992. glScalef(2,0.2,2);
  1993. cube(0,0,0);
  1994. glPopMatrix();
  1995.  
  1996. glPushMatrix();
  1997. glTranslatef(-20,7,52);
  1998. glScalef(0.2,2,2);
  1999. cube(0,0,0);
  2000. glPopMatrix();
  2001. glPushMatrix();
  2002. glTranslatef(-22,7,52);
  2003. glScalef(2,0.2,2);
  2004. cube(0,0,0);
  2005. glPopMatrix();
  2006.  
  2007.  
  2008.  
  2009. glPushMatrix();
  2010. glTranslatef(-10,7,38);
  2011. glScalef(0.2,2,2);
  2012. cube(0,0,0);
  2013. glPopMatrix();
  2014. glPushMatrix();
  2015. glTranslatef(-10,7,38);
  2016. glScalef(2,0.2,2);
  2017. cube(0,0,0);
  2018. glPopMatrix();
  2019.  
  2020. glDisable(GL_LIGHTING);
  2021.  
  2022. table(-40,6,38);
  2023. chair(-42,6,38,1);
  2024. table(-40,6,45);
  2025. chair(-42,6,45,1);
  2026. table(-40,6,52);
  2027. chair(-42,6,52,1);
  2028.  
  2029. table(-30,6,38);
  2030. chair(-32,6,38,1);
  2031. table(-30,6,45);
  2032. chair(-32,6,45,1);
  2033. table(-30,6,52);
  2034. chair(-32,6,52,1);
  2035.  
  2036. table(-20,6,38);
  2037. chair(-22,6,38,1);
  2038. table(-20,6,45);
  2039. chair(-22,6,45,1);
  2040. table(-20,6,52);
  2041. chair(-22,6,52,1);
  2042.  
  2043. table(-10,6,38);
  2044. chair(-7,6,38);
  2045.  
  2046. ///projector
  2047. glEnable(GL_TEXTURE_2D);
  2048. glBindTexture(GL_TEXTURE_2D,10);
  2049. glPushMatrix();
  2050. glTranslatef(-6,18,38);
  2051. glScalef(1,0.5,15);
  2052. cube();
  2053. glPopMatrix();
  2054. glDisable(GL_TEXTURE_2D);
  2055.  
  2056. glPushMatrix();
  2057. glTranslatef(-6,10,38);
  2058. glScalef(1,8,15);
  2059. cube();
  2060. glPopMatrix();
  2061.  
  2062. glEnable(GL_TEXTURE_2D);
  2063. glBindTexture(GL_TEXTURE_2D,10);
  2064. glPushMatrix();
  2065. glTranslatef(-15,15,45);
  2066. glScalef(1,0.5,10);
  2067. cube();
  2068. glPopMatrix();
  2069. glDisable(GL_TEXTURE_2D);
  2070.  
  2071. glPushMatrix();
  2072. glTranslatef(-14,15,47.5);
  2073. glScalef(3,1,3);
  2074. cube();
  2075. glPopMatrix();
  2076. }
  2077. void sports()
  2078. {
  2079. carrom();
  2080. pingpong();
  2081. chess();
  2082. dart();
  2083.  
  2084. }
  2085.  
  2086. void trees()
  2087. {
  2088.  
  2089.  
  2090. glEnable(GL_TEXTURE_2D);
  2091. glBindTexture(GL_TEXTURE_2D,2);
  2092. glPushMatrix();
  2093. glTranslatef(10,5,10);
  2094. glScalef(2,2,2);
  2095. drawpyramid();
  2096. glPopMatrix();
  2097. glDisable(GL_TEXTURE_2D);
  2098.  
  2099. glEnable(GL_TEXTURE_2D);
  2100. glBindTexture(GL_TEXTURE_2D,2);
  2101. glPushMatrix();
  2102. glTranslatef(10,5,20);
  2103. glScalef(2,2,2);
  2104. drawpyramid();
  2105. glPopMatrix();
  2106. glDisable(GL_TEXTURE_2D);
  2107.  
  2108.  
  2109. glEnable(GL_TEXTURE_2D);
  2110. glBindTexture(GL_TEXTURE_2D,2);
  2111. glPushMatrix();
  2112. glTranslatef(10,5,-10);
  2113. glScalef(2,2,2);
  2114. drawpyramid();
  2115. glPopMatrix();
  2116. glDisable(GL_TEXTURE_2D);
  2117.  
  2118. glEnable(GL_TEXTURE_2D);
  2119. glBindTexture(GL_TEXTURE_2D,2);
  2120. glPushMatrix();
  2121. glTranslatef(-12,5,10);
  2122. glScalef(2,2,2);
  2123. drawpyramid();
  2124. glPopMatrix();
  2125. glDisable(GL_TEXTURE_2D);
  2126.  
  2127. glEnable(GL_TEXTURE_2D);
  2128. glBindTexture(GL_TEXTURE_2D,2);
  2129. glPushMatrix();
  2130. glTranslatef(-12,5,20);
  2131. glScalef(2,2,2);
  2132. drawpyramid();
  2133. glPopMatrix();
  2134. glDisable(GL_TEXTURE_2D);
  2135.  
  2136.  
  2137. glEnable(GL_TEXTURE_2D);
  2138. glBindTexture(GL_TEXTURE_2D,2);
  2139. glPushMatrix();
  2140. glTranslatef(-12,5,-10);
  2141. glScalef(2,2,2);
  2142. drawpyramid();
  2143. glPopMatrix();
  2144. glDisable(GL_TEXTURE_2D);
  2145.  
  2146.  
  2147. glEnable(GL_LIGHTING);
  2148.  
  2149. glPushMatrix();
  2150. glTranslatef(10,0,20);
  2151. glScalef(1,5,1);
  2152. cube(0,0,0);
  2153. glPopMatrix();
  2154.  
  2155. glPushMatrix();
  2156. glTranslatef(10,0,10);
  2157. glScalef(1,5,1);
  2158. cube(0,0,0);
  2159. glPopMatrix();
  2160.  
  2161. glPushMatrix();
  2162. glTranslatef(10,0,-10);
  2163. glScalef(1,5,1);
  2164. cube(0,0,0);
  2165. glPopMatrix();
  2166.  
  2167. glPushMatrix();
  2168. glTranslatef(-10,0,20);
  2169. glScalef(1,5,1);
  2170. cube(0,0,0);
  2171. glPopMatrix();
  2172.  
  2173. glPushMatrix();
  2174. glTranslatef(-10,0,10);
  2175. glScalef(1,5,1);
  2176. cube(0,0,0);
  2177. glPopMatrix();
  2178.  
  2179. glPushMatrix();
  2180. glTranslatef(-10,0,-10);
  2181. glScalef(1,5,1);
  2182. cube(0,0,0);
  2183. glPopMatrix();
  2184.  
  2185. glDisable(GL_LIGHTING);
  2186. }
  2187.  
  2188. void teachers()
  2189. {
  2190. glEnable(GL_TEXTURE_2D);
  2191. glBindTexture(GL_TEXTURE_2D,3);
  2192. glPushMatrix();
  2193. glTranslatef(-40,6,66);
  2194. glScalef(10,1,26);
  2195. cube(1,1,1);
  2196. glPopMatrix();
  2197. glDisable(GL_TEXTURE_2D);
  2198. glPushMatrix();
  2199. glScalef(2,1,5);
  2200. table(-17.5,5,15.8);
  2201. glPopMatrix();
  2202.  
  2203. chair(-28,5,70);
  2204. chair(-28,5,75);
  2205. chair(-28,5,80);
  2206. chair(-28,5,85);
  2207. chair(-28,5,90);
  2208. chair(-43,5,70,1);
  2209. chair(-43,5,75,1);
  2210. chair(-43,5,80,1);
  2211. chair(-43,5,85,1);
  2212. chair(-43,5,90,1);
  2213.  
  2214.  
  2215. //glRotatef(90,0,1,0);
  2216. chair(-35,5,65,2);
  2217. chair(-35,5,92,3);
  2218. wardrobe(-35,7.5,60);
  2219. tv();
  2220.  
  2221. }
  2222.  
  2223. void curved_trees(float x,float y,float z)
  2224. {
  2225. glEnable(GL_TEXTURE_2D);
  2226. glBindTexture(GL_TEXTURE_2D,2);
  2227. glPushMatrix();
  2228. glDisable(GL_LIGHTING);
  2229. glTranslatef(x,y,z);
  2230. glScalef(2,2,2);
  2231. //if(animat)
  2232. //glRotated(a,0,0,1);
  2233. //else
  2234. //glRotated(135,0,0,1);
  2235.  
  2236. glRotatef( anglex, 1.0, 0.0, 0.0);
  2237. glRotatef( angley, 0.0, 1.0, 0.0); //rotate about y-axis
  2238. glRotatef( anglez, 0.0, 0.0, 1.0);
  2239. glScaled(0.5,0.5,0.5);
  2240. glRotatef( 270, 0.0, 0.0, 1.0);
  2241. glTranslated(-3.5,0,0);
  2242. glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); //get the modelview info
  2243.  
  2244. //matColor(0.9,0.5,0.1,20); // front face color
  2245. //matColor(0.0,0.5,0.8,20,1); // back face color
  2246.  
  2247.  
  2248. bottleBezier();
  2249.  
  2250.  
  2251. if(shcpt)
  2252. {
  2253. //matColor(0.0,0.0,0.9,20);
  2254. //showControlPoints();
  2255. }
  2256.  
  2257. glPopMatrix();
  2258. //axes();
  2259. glDisable(GL_TEXTURE_2D);
  2260. }
  2261. static void display(void)
  2262. {
  2263. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  2264. glMatrixMode(GL_PROJECTION);
  2265. glLoadIdentity();
  2266. glFrustum(-3, 3, -3, 3, 2.0, 100.0);
  2267.  
  2268. const double t = glutGet(GLUT_ELAPSED_TIME) / 5000.0;
  2269. const double a = t*90.0;
  2270.  
  2271. glMatrixMode(GL_MODELVIEW);
  2272. glLoadIdentity();
  2273. gluLookAt(eyeX,eyeY,eyeZ, lookX,lookY,lookZ, hookX,hookY,hookZ);
  2274. //glViewport(0, 0, width, height);
  2275.  
  2276. glRotatef(rot, 0,1,0);
  2277.  
  2278. if(wired)
  2279. {
  2280. glPolygonMode( GL_FRONT, GL_LINE ) ;
  2281. glPolygonMode( GL_BACK, GL_LINE ) ;
  2282.  
  2283. }
  2284. else
  2285. {
  2286. glPolygonMode( GL_FRONT,GL_FILL ) ;
  2287. glPolygonMode( GL_BACK, GL_FILL ) ;
  2288. }
  2289.  
  2290. curved_trees(10,8,0);
  2291. curved_trees(-10,8,0);
  2292.  
  2293. glEnable(GL_LIGHTING);
  2294. glPushMatrix();
  2295. glTranslatef(8,0,10);
  2296. glScalef(0.5,10,0.5);
  2297. cube(0,0,0);
  2298. glPopMatrix();
  2299. glDisable(GL_LIGHTING);
  2300.  
  2301. //cube(0.5,0.5,0.5,1,1);
  2302. ///classrooms
  2303. classroom1(0);
  2304. glPushMatrix();
  2305. glTranslatef(0,0,60);
  2306.  
  2307. classroom1(2);
  2308. glRotatef(180,0,1,0);
  2309. glPopMatrix();
  2310.  
  2311. ///Main Door
  2312. glPushMatrix();
  2313. //glScalef(10,20,1);
  2314. door(0,5,35,0,10,20);
  2315. glPopMatrix();
  2316.  
  2317. rodshape1(44,15,45);
  2318. rodshape2(44,15,105);
  2319. //spotlightshape(-44,15,45);
  2320. glEnable(GL_LIGHTING);
  2321. glPushMatrix();
  2322. light1(40,15,45);
  2323. //light1(8,0,10);
  2324. glPopMatrix();
  2325. glDisable(GL_LIGHTING);
  2326. glEnable(GL_LIGHTING);
  2327. glPushMatrix();
  2328. light2(40,15,105);
  2329. glPopMatrix();
  2330. glDisable(GL_LIGHTING);
  2331. glEnable(GL_LIGHTING);
  2332. glPushMatrix();
  2333. light3(-15,15,45);
  2334. glPopMatrix();
  2335. glDisable(GL_LIGHTING);
  2336. //light3();
  2337.  
  2338. ///Labs
  2339. lab();
  2340. glPushMatrix();
  2341. glTranslatef(0,0,60);
  2342. lab();
  2343. glPopMatrix();
  2344.  
  2345. ///Sports Room
  2346. sports();
  2347. ///Cars
  2348. glPushMatrix();
  2349. glTranslatef(15,0,12);
  2350. car();
  2351. glPopMatrix();
  2352. glPushMatrix();
  2353. glTranslatef(15,0,7);
  2354. car();
  2355. glPopMatrix();
  2356.  
  2357. ///Main Road
  2358. glEnable(GL_TEXTURE_2D);
  2359. glBindTexture(GL_TEXTURE_2D,1);
  2360. glPushMatrix();
  2361. glScalef(10,0.2,70);
  2362. glTranslatef(-0.5,-0.5,-0.5);
  2363. cube(1,1,1);
  2364. glPopMatrix();
  2365. glDisable(GL_TEXTURE_2D);
  2366.  
  2367. ///Grass
  2368. glEnable(GL_TEXTURE_2D);
  2369. glBindTexture(GL_TEXTURE_2D,2);
  2370. glPushMatrix();
  2371. glScalef(200,0.1,250);
  2372. glTranslatef(-0.5,-0.5,-0.5);
  2373. cube(1,1,1);
  2374. glPopMatrix();
  2375. glDisable(GL_TEXTURE_2D);
  2376.  
  2377. fence();
  2378.  
  2379. building();
  2380.  
  2381. ///Name plate
  2382. glEnable(GL_TEXTURE_2D);
  2383. glBindTexture(GL_TEXTURE_2D,20);
  2384. glPushMatrix();
  2385. glTranslatef(0,17.5,35);
  2386. glScalef(10,5,1);
  2387. glTranslatef(-0.5,-0.5,-0.5);
  2388. cube(1,1,1);
  2389. glPopMatrix();
  2390. glDisable(GL_TEXTURE_2D);
  2391.  
  2392.  
  2393. ///Football Field
  2394. glEnable(GL_TEXTURE_2D);
  2395. glBindTexture(GL_TEXTURE_2D,6);
  2396. glPushMatrix();
  2397. glTranslatef(0,0,75);
  2398. glScalef(40,0.3,30);
  2399. glTranslatef(-0.5,-0.5,-0.5);
  2400. cube(1,1,1);
  2401. glPopMatrix();
  2402. glDisable(GL_TEXTURE_2D);
  2403.  
  2404. ///Floor
  2405. glEnable(GL_TEXTURE_2D);
  2406. glBindTexture(GL_TEXTURE_2D,7);
  2407. glPushMatrix();
  2408. glTranslatef(0,0,75);
  2409. glScalef(90,0.2,80);
  2410. glTranslatef(-0.5,-0.5,-0.5);
  2411. cube(1,1,1);
  2412. glPopMatrix();
  2413. glDisable(GL_TEXTURE_2D);
  2414.  
  2415. ///Rooves
  2416. //cover();
  2417. switch(rooftop)
  2418. {
  2419. case 1:
  2420. cover();
  2421. break;
  2422.  
  2423. }
  2424.  
  2425. ///GoalPosts
  2426. goalpost();
  2427.  
  2428.  
  2429. trees();
  2430.  
  2431. teachers();
  2432.  
  2433. glutSwapBuffers();
  2434.  
  2435.  
  2436.  
  2437. }
  2438.  
  2439. void animate()
  2440. {
  2441.  
  2442.  
  2443. glutPostRedisplay();
  2444. }
  2445.  
  2446.  
  2447. static void key(unsigned char key, int x, int y)
  2448. {
  2449. switch (key)
  2450. {
  2451. case 27 :
  2452. case '/':
  2453. lookX=0;
  2454. lookY=5;
  2455. lookZ=0;
  2456. eyeX=0;
  2457. eyeY=6;
  2458. eyeZ=-13;
  2459. rot=0;
  2460. break;
  2461. case 'q':
  2462. exit(0);
  2463. break;
  2464. case 'f':
  2465. isrot^=1;
  2466. break;
  2467. case 'w':
  2468. eyeZ++;
  2469. lookZ++;
  2470. break;
  2471. case 's':
  2472. eyeZ--;
  2473. lookZ--;
  2474. break;
  2475. case 'a':
  2476. eyeX++;
  2477. lookX++;
  2478. break;
  2479. case 'd':
  2480. eyeX--;
  2481. lookX--;
  2482. break;
  2483. case 'u':
  2484. eyeY++;
  2485. lookY++;
  2486. break;
  2487. case 'j':
  2488. eyeY--;
  2489. lookY--;
  2490. break;
  2491. case '.':
  2492. rot--;
  2493. break;
  2494. case ',':
  2495. rot++;
  2496. break;
  2497. case 'i':
  2498. eyeY++;
  2499. break;
  2500. case 'k':
  2501. eyeY--;
  2502. break;
  2503. case 'r':
  2504. rot=rot+90;
  2505. break;
  2506. case 'z':
  2507. press1^=1;
  2508. break;
  2509. case 'x':
  2510. press2^=1;
  2511. break;
  2512. case 'c':
  2513. press4^=1;
  2514. break;
  2515. case 'v':
  2516. lookX++;
  2517. break;
  2518. case 'b':
  2519. lookX--;
  2520. break;
  2521. case 'n':
  2522. eyeX++;
  2523. break;
  2524. case 'm':
  2525. eyeX--;
  2526. break;
  2527. case '0':
  2528. if(da[0]==0)
  2529. da[0]=1;
  2530. else
  2531. da[0]=0;
  2532. break;
  2533. case '1':
  2534. if(da[1]==0)
  2535. da[1]=1;
  2536. else
  2537. da[1]=0;
  2538. break;
  2539. case '2':
  2540. if(da[2]==0)
  2541. da[2]=1;
  2542. else
  2543. da[2]=0;
  2544. break;
  2545. case '3':
  2546. if(da[3]==0)
  2547. da[3]=1;
  2548. else
  2549. da[3]=0;
  2550. break;
  2551. case '4':
  2552. if(da[4]==0)
  2553. da[4]=1;
  2554. else
  2555. da[4]=0;
  2556. break;
  2557. case '5':
  2558. if(da[5]==0)
  2559. da[5]=1;
  2560. else
  2561. da[5]=0;
  2562. break;
  2563. case '6':
  2564. if(da[6]==0)
  2565. da[6]=1;
  2566. else
  2567. da[6]=0;
  2568. break;
  2569. case 'h':
  2570. rooftop^=1;
  2571. break;
  2572. // case 'g':
  2573. // glDisable(GL_LIGHTING);
  2574. // break;
  2575.  
  2576. }
  2577.  
  2578. glutPostRedisplay();
  2579. }
  2580.  
  2581. static void idle(void)
  2582. {
  2583.  
  2584. if (isrot)
  2585. {
  2586. spin=spin+1.0;
  2587.  
  2588. if(spin > 360)
  2589. spin = 0;
  2590. }
  2591. //if(rooftop)cover();
  2592. glutPostRedisplay();
  2593. }
  2594.  
  2595.  
  2596. const GLfloat light_ambient[] = { 0.5f, 0.5f, 0.5f, 1.0f };
  2597. const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  2598. const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  2599. const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 1.0f };
  2600.  
  2601. void matColor(float kdr, float kdg, float kdb, float shiny, int frnt_Back, float ambFactor, float specFactor)
  2602. {
  2603.  
  2604. const GLfloat mat_ambient[] = { kdr*ambFactor, kdg*ambFactor, kdb*ambFactor, 1.0f };
  2605. const GLfloat mat_diffuse[] = { kdr, kdg, kdb, 1.0f };
  2606. const GLfloat mat_specular[] = { 1.0f*specFactor, 1.0f*specFactor, 1.0f*specFactor, 1.0f };
  2607. const GLfloat high_shininess[] = { shiny };
  2608. if(frnt_Back==0)
  2609. {
  2610. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  2611. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  2612. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  2613. glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
  2614. }
  2615. else if(frnt_Back==1)
  2616. {
  2617. glMaterialfv(GL_BACK, GL_AMBIENT, mat_ambient);
  2618. glMaterialfv(GL_BACK, GL_DIFFUSE, mat_diffuse);
  2619. glMaterialfv(GL_BACK, GL_SPECULAR, mat_specular);
  2620. glMaterialfv(GL_BACK, GL_SHININESS, high_shininess);
  2621. }
  2622. else if(frnt_Back==2)
  2623. {
  2624. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
  2625. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
  2626. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
  2627. glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, high_shininess);
  2628. }
  2629.  
  2630. }
  2631.  
  2632. /* Program entry point */
  2633. void myInit()
  2634. {
  2635. glClearColor(.1,.1,.1,1);
  2636.  
  2637. glEnable(GL_LIGHT0);
  2638. glEnable(GL_NORMALIZE);
  2639. glEnable(GL_COLOR_MATERIAL);
  2640. glEnable(GL_LIGHTING);
  2641.  
  2642. glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
  2643. glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  2644. glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
  2645. glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  2646. }
  2647.  
  2648.  
  2649. int main(int argc, char *argv[])
  2650. {
  2651. glutInit(&argc, argv);
  2652. glutInitWindowSize(width,height);
  2653. glutInitWindowPosition(10,10);
  2654. glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  2655.  
  2656.  
  2657.  
  2658. glutCreateWindow("1607006");
  2659. //glDisable(GL_LIGHTING);
  2660. glutDisplayFunc(display);
  2661. glutKeyboardFunc(key);
  2662.  
  2663. //glutIdleFunc(animate);
  2664. //glutSpecialFunc(collision);
  2665. glutIdleFunc(idle);
  2666.  
  2667. //glutReshapeFunc(res);
  2668.  
  2669. // glClearColor(1,1,1,1);
  2670.  
  2671. glEnable(GL_DEPTH_TEST);
  2672.  
  2673. glShadeModel( GL_SMOOTH );
  2674. glEnable(GL_NORMALIZE);
  2675. glEnable(GL_BLEND);
  2676. //glEnable(GL_LIGHTING);
  2677.  
  2678. printf("ROLL: 1607006 \n PROJECT TITLE: 3D CLASSROOM/SCHOOL PROJECT");
  2679. printf(" 'w' to look forward \n 's' to look backward \n 'd' to look right \n 'a' to look left.\n");
  2680. printf(" 'u' to look up \n 'j' to look down \n 'f' to turn on/off fan \n '/' to reset view.\n");
  2681. printf(" '.' to rotate left \n ',' to rotate right \n 'i' eye up \n 'k' eye down\n");
  2682. printf(" 'r' rotate 90 degree \n 'z' light1 on/of \n 'x' light2 on/off \n 'c' light3 on/off\n");
  2683. printf(" 'v' look left \n 'b' look right \n 'n' eye right \n 'm' eye left\n");
  2684. printf(" '0' main door on/off \n '1' lab1 door on/off \n '2' class1 door on/off \n");
  2685. printf(" '3' lab2 door on/off \n '4' class2 door on/off \n '5' teachers' room on/off \n '6' sports room on/off\n");
  2686.  
  2687.  
  2688. LoadTexture("C:\\Users\\road.bmp");//1
  2689. LoadTexture("C:\\Users\\grass.bmp");//2
  2690. LoadTexture("C:\\Users\\fence.bmp");//3
  2691. LoadTexture("C:\\Users\\window.bmp");//4
  2692. LoadTexture("C:\\Users\\brick.bmp");//5
  2693. LoadTexture("C:\\Users\\football.bmp");//6
  2694. LoadTexture("C:\\Users\\floor.bmp");//7
  2695. LoadTexture("C:\\Users\\carlight.bmp");//8
  2696. LoadTexture("C:\\Users\\topview.bmp");//9
  2697. LoadTexture("C:\\Users\\pipe.bmp");//10
  2698. LoadTexture("C:\\Users\\wardrobebody.bmp");//11
  2699. LoadTexture("C:\\Users\\wardrobefront.bmp");//12
  2700. LoadTexture("C:\\Users\\chair.bmp");//13
  2701. LoadTexture("C:\\Users\\clock.bmp");//14
  2702. LoadTexture("C:\\Users\\carrom.bmp");//15
  2703. LoadTexture("C:\\Users\\chess.bmp");//16
  2704. LoadTexture("C:\\Users\\dart.bmp");//17
  2705. LoadTexture("C:\\Users\\net.bmp");//18
  2706. LoadTexture("C:\\Users\\door.bmp");//19
  2707. LoadTexture("C:\\Users\\name.bmp");//20
  2708. LoadTexture("C:\\Users\\tree.bmp");//21
  2709.  
  2710. glutMainLoop();
  2711.  
  2712. return EXIT_SUCCESS;
  2713. }
  2714.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement