├── .gitattributes ├── .gitignore ├── README.md ├── Vishnu.bmp ├── field.bmp └── source_code.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Campus Traverse 2 | A project using OpenGL to show a walk-in simulation through the campus of my college 3 | 4 | A project implemented using c++ and OpenGL in VisualStudio, aims at simulating the campus of my college. 5 | The campus is visualized in a 3D perspective view with keyboard and mouse inputs for navigating through the campus. The campus portrayed is a sample of how the real campus looks however details such as paint color and building dimensions couldn't be accounted for. 6 | With help of textures I have shown the football field and also the idol in the temple. The interiors of the Mechanical block is also done with an indoor badminton court. 7 | 8 | Input keys for the application: 9 | - w -Move forward 10 | - s -Move Backward 11 | - u -Move vertically up 12 | - j -Move vertically down 13 | - Mouse left click and drag right -Rotate view towards right 14 | - Mouse left click and drag left -Rotate view towards left 15 | -------------------------------------------------------------------------------- /Vishnu.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sujayj78/OpenGL-project/382eac34bdc0848abb2489c9fe5781c7abab3476/Vishnu.bmp -------------------------------------------------------------------------------- /field.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sujayj78/OpenGL-project/382eac34bdc0848abb2489c9fe5781c7abab3476/field.bmp -------------------------------------------------------------------------------- /source_code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | float y = 1, x = -30, z = 100; // initially 5 units south of origin 13 | float deltaMove = 0.0; // initially camera doesn't move 14 | // Camera direction 15 | float lx = 0.0, lz = -1; // camera points initially along y-axis 16 | //float angle = 0.0; // angle of rotation for the camera direction 17 | //float deltaAngle = 0.0; // additional angle change when dragging 18 | float angle = 0.0; // angle of rotation for the camera direction 19 | float deltaAngle = 0.0; // additional angle change when dragging 20 | 21 | // Mouse drag control 22 | int isDragging = 0; // true when dragging 23 | int xDragStart = 0; // records the x-coordinate when dragging starts 24 | int move=0; 25 | int vertmove=0; 26 | 27 | unsigned char header[54]; // Each BMP file begins by a 54-bytes header 28 | unsigned int dataPos; // Position in the file where the actual data begins 29 | unsigned int width, height; 30 | unsigned int imageSize; // = width*height*3 31 | unsigned char * data=NULL; // Actual RGB data 32 | 33 | 34 | void draw_board() 35 | { 36 | glColor3f(0.177,0.564,1); 37 | glBegin(GL_QUADS); 38 | glVertex3f(0,0,0); 39 | glVertex3f(1,0,0); 40 | glVertex3f(1,2,0); 41 | glVertex3f(0,2,0); 42 | glVertex3f(9,0,0); 43 | glVertex3f(10,0,0); 44 | glVertex3f(10,2,0); 45 | glVertex3f(9,2,0); 46 | glEnd(); 47 | glColor3f(0.690,0.878,0.901); 48 | glBegin(GL_QUADS); 49 | glVertex3f(0,2,0); 50 | glVertex3f(10,2,0); 51 | glVertex3f(10,4,0); 52 | glVertex3f(0,4,0); 53 | glEnd(); 54 | } 55 | 56 | GLuint loadBMP_custom(const char * imagepath) 57 | { 58 | // Open the file 59 | FILE * file = fopen(imagepath,"rb"); 60 | if (!file) 61 | { 62 | printf("Image could not be opened\n"); 63 | printf("Error %d \n", errno); 64 | return 0; 65 | } 66 | if ( fread(header, 1, 54, file)!=54 ) 67 | { // If not 54 bytes read : problem 68 | printf("Not a correct BMP file\n"); 69 | return false; 70 | } 71 | if ( header[0]!='B' || header[1]!='M' ) 72 | { 73 | printf("Not a correct BMP file\n"); 74 | return 0; 75 | } 76 | dataPos = *(int*)&(header[0x0A]); 77 | imageSize = *(int*)&(header[0x22]); 78 | width = *(int*)&(header[0x12]); 79 | height = *(int*)&(header[0x16]); 80 | // Some BMP files are misformatted, guess missing information 81 | if (imageSize==0) 82 | imageSize=width*height*3; // 3 : one byte for each Red, Green and Blue component 83 | if (dataPos==0) 84 | dataPos=54; // The BMP header is done that way 85 | // Create a buffer 86 | data = new unsigned char [imageSize]; 87 | // Read the actual data from the file into the buffer 88 | fread(data,1,imageSize,file); 89 | //Everything is in memory now, the file can be closed 90 | fclose(file); 91 | } 92 | 93 | void draw_map() 94 | { 95 | GLuint Texture = loadBMP_custom("field.bmp"); 96 | glEnable(GL_TEXTURE_2D); 97 | GLuint textureID; 98 | glGenTextures(1, &textureID); 99 | glBindTexture(GL_TEXTURE_2D, textureID); 100 | // Set the texture wrapping parameters 101 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 102 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 103 | // Set texture filtering parameters 104 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 105 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 106 | // Load image, create texture and generate mipmaps 107 | glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); 108 | 109 | glColor3f(1.0f,1.0f,1.0f); 110 | glBegin(GL_QUADS); 111 | glTexCoord2f(0.0f, 0.0f); glVertex3f(-15.0f, -3.0f, 20.0f); 112 | glTexCoord2f(10.0f, 0.0f); glVertex3f(30.0f, -3.0f, 20.0f); 113 | glTexCoord2f(10.0f, 10.0f); glVertex3f( 30.0f, -3.0f, -20.0f); 114 | glTexCoord2f(0.0f, 10.0f); glVertex3f( -15.0f, -3.0f, -20.0f); 115 | glEnd(); 116 | 117 | glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture when done, so we won't accidentily mess up our texture. 118 | delete []data; 119 | glDeleteTextures(1, &textureID); 120 | glDisable(GL_TEXTURE_2D); 121 | } 122 | 123 | void draw_idol() 124 | { 125 | GLuint Texture = loadBMP_custom("Vishnu.bmp"); 126 | glEnable(GL_TEXTURE_2D); 127 | GLuint textureID; 128 | glGenTextures(1, &textureID); 129 | glBindTexture(GL_TEXTURE_2D, textureID); 130 | // Set the texture wrapping parameters 131 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 132 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 133 | // Set texture filtering parameters 134 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 135 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 136 | // Load image, create texture and generate mipmaps 137 | glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); 138 | 139 | 140 | glColor3f(1.0f,1.0f,1.0f); 141 | glBegin(GL_QUADS); 142 | glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, .0f, 0.0f); 143 | glTexCoord2f(1.0f, 0.0f); glVertex3f(4.0f, 0.0f, 0.0f); 144 | glTexCoord2f(1.0f, 1.0f); glVertex3f( 4.0f, 5.0f, 0.0f); 145 | glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 5.0f, 0.0f); 146 | glEnd(); 147 | 148 | glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture when done, so we won't accidentily mess up our texture. 149 | delete []data; 150 | glDeleteTextures(1, &textureID); 151 | glDisable(GL_TEXTURE_2D); 152 | } 153 | 154 | void restrict() //restrict movement within boundaries 155 | { 156 | if(x>100) x=100; 157 | else if(x<-100) x=-100; 158 | if(y>60) y=60; 159 | else if(y<0.5) y=0.5; 160 | if(z>100) z=100; 161 | else if(z<-100) z=-100; 162 | } 163 | 164 | void mech_court() //badminton court 165 | { 166 | int k; 167 | glPushMatrix(); 168 | glTranslatef(-70,0.1,20); 169 | glColor3f(0.5,0.5,0.5); 170 | glBegin(GL_QUADS); 171 | glVertex3f(0,0,0); 172 | glVertex3f(20,0,0); 173 | glVertex3f(20,0,-40); 174 | glVertex3f(0,0,-40); 175 | glEnd(); 176 | glColor3f(0,0,0); 177 | for(k=2;k<18;k+=4) 178 | { 179 | glBegin(GL_QUADS); 180 | glVertex3f(k,0,-0.1); 181 | glVertex3f(k,4,-0.1); 182 | glVertex3f(k+2,4,-0.1); 183 | glVertex3f(k+2,0,-0.1); 184 | glEnd(); 185 | } 186 | for(k=-2;k>-38;k-=6) 187 | { 188 | glBegin(GL_QUADS); 189 | glVertex3f(0.1,0,k); 190 | glVertex3f(0.1,4,k); 191 | glVertex3f(0.1,4,k-2); 192 | glVertex3f(0.1,0,k-2); 193 | glEnd(); 194 | } 195 | glPopMatrix(); 196 | glPushMatrix(); 197 | glTranslatef(-50,0.1,20); 198 | for(k=-2;k>-38;k-=6) 199 | { 200 | glBegin(GL_QUADS); 201 | glVertex3f(-0.1,0,k); 202 | glVertex3f(-0.1,4,k); 203 | glVertex3f(-0.1,4,k-2); 204 | glVertex3f(-0.1,0,k-2); 205 | glEnd(); 206 | } 207 | glPopMatrix(); 208 | glPushMatrix(); 209 | glTranslatef(-50,0.1,-20); 210 | for(k=-2;k>-18;k-=4) 211 | { 212 | glBegin(GL_QUADS); 213 | glVertex3f(k,0,0.1); 214 | glVertex3f(k,4,0.1); 215 | glVertex3f(k-2,4,0.1); 216 | glVertex3f(k-2,0,0.1); 217 | glEnd(); 218 | } 219 | glPopMatrix(); 220 | glPushMatrix(); 221 | glTranslatef(-65,0.1,15); 222 | glColor3f(0,0,1); 223 | glBegin(GL_QUADS); 224 | glVertex3f(0,0.2,0); 225 | glVertex3f(10,0.2,0); 226 | glVertex3f(10,0.2,-30); 227 | glVertex3f(0,0.2,-30); 228 | glEnd(); 229 | glColor3f(1,1,1); 230 | glBegin(GL_LINE_LOOP); 231 | glVertex3f(1,0.3,-1); 232 | glVertex3f(9,0.3,-1); 233 | glVertex3f(9,0.3,-13); 234 | glVertex3f(1,0.3,-13); 235 | glEnd(); 236 | glBegin(GL_LINE_LOOP); 237 | glVertex3f(1,0.3,-15); 238 | glVertex3f(9,0.3,-15); 239 | glVertex3f(9,0.3,-29); 240 | glVertex3f(1,0.3,-29); 241 | glEnd(); 242 | glPopMatrix(); 243 | glPushMatrix(); 244 | glTranslatef(-65,0,8); 245 | glColor3f(1,1,1); 246 | for(float i=0;i<0.8;i+=0.2) 247 | for(float j=0;j<9.8;j+=0.2) 248 | { 249 | glBegin(GL_LINE_LOOP); 250 | glVertex3f(j,i,0); 251 | glVertex3f(j+0.2,i,0); 252 | glVertex3f(j+0.2,i+0.2,0); 253 | glVertex3f(j,i+0.2,0); 254 | glEnd(); 255 | } 256 | glPopMatrix(); 257 | glPushMatrix(); 258 | glTranslatef(-65,0,-8); 259 | glColor3f(1,1,1); 260 | for(float i=0;i<0.8;i+=0.2) 261 | for(float j=0;j<9.8;j+=0.2) 262 | { 263 | glBegin(GL_LINE_LOOP); 264 | glVertex3f(j,i,0); 265 | glVertex3f(j+0.2,i,0); 266 | glVertex3f(j+0.2,i+0.2,0); 267 | glVertex3f(j,i+0.2,0); 268 | glEnd(); 269 | } 270 | glPopMatrix(); 271 | for(int i=0;i<15;i+=5) 272 | { 273 | glPushMatrix(); 274 | glTranslatef(-70,6+i,20); 275 | glColor3f(1,0.894,0.709); 276 | glBegin(GL_QUADS); 277 | glVertex3f(0,0,0); 278 | glVertex3f(20,0,0); 279 | glVertex3f(20,0,-4); 280 | glVertex3f(0,0,-4); 281 | glEnd(); 282 | glColor3f(1,0.972,0.862); 283 | glBegin(GL_QUADS); 284 | glVertex3f(4,0,-4); 285 | glVertex3f(16,0,-4); 286 | glVertex3f(16,2,-4); 287 | glVertex3f(4,2,-4); 288 | glEnd(); 289 | glColor3f(0,0,0); 290 | for(k=2;k<18;k+=4) 291 | { 292 | glBegin(GL_QUADS); 293 | glVertex3f(k,0,-0.1); 294 | glVertex3f(k,4,-0.1); 295 | glVertex3f(k+2,4,-0.1); 296 | glVertex3f(k+2,0,-0.1); 297 | glEnd(); 298 | } 299 | glPushMatrix(); 300 | glTranslatef(20,0,0); 301 | glColor3f(1,0.894,0.709); 302 | glBegin(GL_QUADS); 303 | glVertex3f(0,0,0); 304 | glVertex3f(0,0,-40); 305 | glVertex3f(-4,0,-40); 306 | glVertex3f(-4,0,0); 307 | glEnd(); 308 | glColor3f(1,0.972,0.862); 309 | glBegin(GL_QUADS); 310 | glVertex3f(-4,0,-4); 311 | glVertex3f(-4,0,-36); 312 | glVertex3f(-4,2,-36); 313 | glVertex3f(-4,2,-4); 314 | glEnd(); 315 | glColor3f(0,0,0); 316 | for(k=-2;k>-38;k-=6) 317 | { 318 | glBegin(GL_QUADS); 319 | glVertex3f(-0.1,0,k); 320 | glVertex3f(-0.1,4,k); 321 | glVertex3f(-0.1,4,k-2); 322 | glVertex3f(-0.1,0,k-2); 323 | glEnd(); 324 | } 325 | glTranslatef(0,0,-40); 326 | glColor3f(1,0.894,0.709); 327 | glBegin(GL_QUADS); 328 | glVertex3f(0,0,0); 329 | glVertex3f(-20,0,0); 330 | glVertex3f(-20,0,4); 331 | glVertex3f(0,0,4); 332 | glEnd(); 333 | glColor3f(1,0.972,0.862); 334 | glBegin(GL_QUADS); 335 | glVertex3f(-4,0,4); 336 | glVertex3f(-16,0,4); 337 | glVertex3f(-16,2,4); 338 | glVertex3f(-4,2,4); 339 | glEnd(); 340 | glColor3f(0,0,0); 341 | for(k=-2;k>-18;k-=4) 342 | { 343 | glBegin(GL_QUADS); 344 | glVertex3f(k,0,0.1); 345 | glVertex3f(k,4,0.1); 346 | glVertex3f(k-2,4,0.1); 347 | glVertex3f(k-2,0,0.1); 348 | glEnd(); 349 | } 350 | glPopMatrix(); 351 | glColor3f(1,0.894,0.709); 352 | glBegin(GL_QUADS); 353 | glVertex3f(0,0,0); 354 | glVertex3f(0,0,-40); 355 | glVertex3f(4,0,-40); 356 | glVertex3f(4,0,0); 357 | glEnd(); 358 | glColor3f(1,0.972,0.862); 359 | glBegin(GL_QUADS); 360 | glVertex3f(4,0,-4); 361 | glVertex3f(4,0,-36); 362 | glVertex3f(4,2,-36); 363 | glVertex3f(4,2,-4); 364 | glEnd(); 365 | glColor3f(0,0,0); 366 | for(k=-2;k>-38;k-=6) 367 | { 368 | glBegin(GL_QUADS); 369 | glVertex3f(0.1,0,k); 370 | glVertex3f(0.1,4,k); 371 | glVertex3f(0.1,4,k-2); 372 | glVertex3f(0.1,0,k-2); 373 | glEnd(); 374 | } 375 | glPopMatrix(); 376 | } 377 | } 378 | 379 | void disp_mba() //mba block interiors 380 | {int k; 381 | glPushMatrix(); 382 | glTranslatef(-70,0.1,-30); 383 | glColor3f(0.5,0.5,0.5); 384 | glBegin(GL_QUADS); 385 | glVertex3f(0,0,0); 386 | glVertex3f(20,0,0); 387 | glVertex3f(20,0,-40); 388 | glVertex3f(0,0,-40); 389 | glEnd(); 390 | glColor3f(0,0,0); 391 | for(k=2;k<18;k+=4) 392 | { 393 | glBegin(GL_QUADS); 394 | glVertex3f(k,0,-0.1); 395 | glVertex3f(k,4,-0.1); 396 | glVertex3f(k+2,4,-0.1); 397 | glVertex3f(k+2,0,-0.1); 398 | glEnd(); 399 | } 400 | for(k=-2;k>-38;k-=6) 401 | { 402 | glBegin(GL_QUADS); 403 | glVertex3f(0.1,0,k); 404 | glVertex3f(0.1,4,k); 405 | glVertex3f(0.1,4,k-2); 406 | glVertex3f(0.1,0,k-2); 407 | glEnd(); 408 | } 409 | glPopMatrix(); 410 | glPushMatrix(); 411 | glTranslatef(-50,0.1,-30); 412 | for(k=-2;k>-38;k-=6) 413 | { 414 | glBegin(GL_QUADS); 415 | glVertex3f(-0.1,0,k); 416 | glVertex3f(-0.1,4,k); 417 | glVertex3f(-0.1,4,k-2); 418 | glVertex3f(-0.1,0,k-2); 419 | glEnd(); 420 | } 421 | glPopMatrix(); 422 | glPushMatrix(); 423 | glTranslatef(-50,0.1,-70); 424 | for(k=-2;k>-18;k-=4) 425 | { 426 | glBegin(GL_QUADS); 427 | glVertex3f(k,0,0.1); 428 | glVertex3f(k,4,0.1); 429 | glVertex3f(k-2,4,0.1); 430 | glVertex3f(k-2,0,0.1); 431 | glEnd(); 432 | } 433 | glPopMatrix(); 434 | for(int i=0;i<15;i+=5) 435 | { 436 | glPushMatrix(); 437 | glTranslatef(-70,6+i,-30); 438 | glColor3f(1,0.894,0.709); 439 | glBegin(GL_QUADS); 440 | glVertex3f(0,0,0); 441 | glVertex3f(20,0,0); 442 | glVertex3f(20,0,-4); 443 | glVertex3f(0,0,-4); 444 | glEnd(); 445 | glColor3f(1,0.972,0.862); 446 | glBegin(GL_QUADS); 447 | glVertex3f(4,0,-4); 448 | glVertex3f(16,0,-4); 449 | glVertex3f(16,2,-4); 450 | glVertex3f(4,2,-4); 451 | glEnd(); 452 | glColor3f(0,0,0); 453 | for(k=2;k<18;k+=4) 454 | { 455 | glBegin(GL_QUADS); 456 | glVertex3f(k,0,-0.1); 457 | glVertex3f(k,4,-0.1); 458 | glVertex3f(k+2,4,-0.1); 459 | glVertex3f(k+2,0,-0.1); 460 | glEnd(); 461 | } 462 | glPushMatrix(); 463 | glTranslatef(20,0,0); 464 | glColor3f(1,0.894,0.709); 465 | glBegin(GL_QUADS); 466 | glVertex3f(0,0,0); 467 | glVertex3f(0,0,-40); 468 | glVertex3f(-4,0,-40); 469 | glVertex3f(-4,0,0); 470 | glEnd(); 471 | glColor3f(1,0.972,0.862); 472 | glBegin(GL_QUADS); 473 | glVertex3f(-4,0,-4); 474 | glVertex3f(-4,0,-36); 475 | glVertex3f(-4,2,-36); 476 | glVertex3f(-4,2,-4); 477 | glEnd(); 478 | glColor3f(0,0,0); 479 | for(k=-2;k>-38;k-=6) 480 | { 481 | glBegin(GL_QUADS); 482 | glVertex3f(-0.1,0,k); 483 | glVertex3f(-0.1,4,k); 484 | glVertex3f(-0.1,4,k-2); 485 | glVertex3f(-0.1,0,k-2); 486 | glEnd(); 487 | } 488 | glTranslatef(0,0,-40); 489 | glColor3f(1,0.894,0.709); 490 | glBegin(GL_QUADS); 491 | glVertex3f(0,0,0); 492 | glVertex3f(-20,0,0); 493 | glVertex3f(-20,0,4); 494 | glVertex3f(0,0,4); 495 | glEnd(); 496 | glColor3f(1,0.972,0.862); 497 | glBegin(GL_QUADS); 498 | glVertex3f(-4,0,4); 499 | glVertex3f(-16,0,4); 500 | glVertex3f(-16,2,4); 501 | glVertex3f(-4,2,4); 502 | glEnd(); 503 | glColor3f(0,0,0); 504 | for(k=-2;k>-18;k-=4) 505 | { 506 | glBegin(GL_QUADS); 507 | glVertex3f(k,0,0.1); 508 | glVertex3f(k,4,0.1); 509 | glVertex3f(k-2,4,0.1); 510 | glVertex3f(k-2,0,0.1); 511 | glEnd(); 512 | } 513 | glPopMatrix(); 514 | glColor3f(1,0.894,0.709); 515 | glBegin(GL_QUADS); 516 | glVertex3f(0,0,0); 517 | glVertex3f(0,0,-40); 518 | glVertex3f(4,0,-40); 519 | glVertex3f(4,0,0); 520 | glEnd(); 521 | glColor3f(1,0.972,0.862); 522 | glBegin(GL_QUADS); 523 | glVertex3f(4,0,-4); 524 | glVertex3f(4,0,-36); 525 | glVertex3f(4,2,-36); 526 | glVertex3f(4,2,-4); 527 | glEnd(); 528 | glColor3f(0,0,0); 529 | for(k=-2;k>-38;k-=6) 530 | { 531 | glBegin(GL_QUADS); 532 | glVertex3f(0.1,0,k); 533 | glVertex3f(0.1,4,k); 534 | glVertex3f(0.1,4,k-2); 535 | glVertex3f(0.1,0,k-2); 536 | glEnd(); 537 | } 538 | glPopMatrix(); 539 | } 540 | 541 | } 542 | class temple //construction of temple 543 | { 544 | float stair[4][3]; 545 | float room[8][3]; 546 | float ceil[6][3]; 547 | public: 548 | temple() 549 | { 550 | stair[0][0]=0;stair[0][1]=0;stair[0][2]=0; 551 | stair[1][0]=12;stair[1][1]=0;stair[1][2]=0; 552 | stair[2][0]=12;stair[2][1]=0;stair[2][2]=-12; 553 | stair[3][0]=0;stair[3][1]=0;stair[3][2]=-12; 554 | 555 | room[0][0]=0;room[0][1]=0;room[0][2]=0; 556 | room[1][0]=0;room[1][1]=6;room[1][2]=0; 557 | room[2][0]=0;room[2][1]=6;room[2][2]=-7; 558 | room[3][0]=0;room[3][1]=0;room[3][2]=-7; 559 | room[4][0]=7;room[4][1]=0;room[4][2]=-7; 560 | room[5][0]=7;room[5][1]=6;room[5][2]=-7; 561 | room[6][0]=7;room[6][1]=6;room[6][2]=0; 562 | room[7][0]=7;room[7][1]=0;room[7][2]=0; 563 | 564 | ceil[0][0]=0;ceil[0][1]=6;ceil[0][2]=4; 565 | ceil[1][0]=3.5;ceil[1][1]=9;ceil[1][2]=4; 566 | ceil[2][0]=7;ceil[2][1]=6;ceil[2][2]=4; 567 | ceil[3][0]=7;ceil[3][1]=6;ceil[3][2]=-9; 568 | ceil[4][0]=3.5;ceil[4][1]=9;ceil[4][2]=-9; 569 | ceil[5][0]=0;ceil[5][1]=6;ceil[5][2]=-9; 570 | } 571 | void disp_stair(int x, int y, int z) 572 | { 573 | glColor3f(1,0.960,0.933); 574 | glBegin(GL_QUADS); 575 | glVertex3f(stair[0][0]-x,stair[0][1]-y,stair[0][2]+z); 576 | glVertex3f(stair[1][0]+x,stair[1][1]-y,stair[1][2]+z); 577 | glVertex3f(stair[2][0]+x,stair[2][1]-y,stair[2][2]-z); 578 | glVertex3f(stair[3][0]-x,stair[3][1]-y,stair[3][2]-z); 579 | glEnd(); 580 | glColor3f(0.933,0.913,0.8); 581 | glBegin(GL_QUADS); 582 | glVertex3f(stair[0][0]-x,stair[0][1]-y,stair[0][2]+z); 583 | glVertex3f(stair[0][0]-x,stair[0][1]-1-y,stair[0][2]+z); 584 | glVertex3f(stair[1][0]+x,stair[1][1]-1-y,stair[1][2]+z); 585 | glVertex3f(stair[1][0]+x,stair[1][1]-y,stair[1][2]+z); 586 | 587 | glVertex3f(stair[1][0]+x,stair[1][1]-y,stair[1][2]+z); 588 | glVertex3f(stair[1][0]+x,stair[1][1]-1-y,stair[1][2]+z); 589 | glVertex3f(stair[2][0]+x,stair[2][1]-1-y,stair[2][2]-z); 590 | glVertex3f(stair[2][0]+x,stair[2][1]-y,stair[2][2]-z); 591 | 592 | glVertex3f(stair[2][0]+x,stair[2][1]-y,stair[2][2]-z); 593 | glVertex3f(stair[3][0]-x,stair[3][1]-y,stair[3][2]-z); 594 | glVertex3f(stair[3][0]-x,stair[3][1]-1-y,stair[3][2]-z); 595 | glVertex3f(stair[2][0]+x,stair[2][1]-1-y,stair[2][2]-z); 596 | 597 | glVertex3f(stair[3][0]-x,stair[3][1]-y,stair[3][2]-z); 598 | glVertex3f(stair[0][0]-x,stair[0][1]-y,stair[0][2]+z); 599 | glVertex3f(stair[0][0]-x,stair[0][1]-1-y,stair[0][2]+z); 600 | glVertex3f(stair[3][0]-x,stair[3][1]-1-y,stair[3][2]-z); 601 | glEnd(); 602 | } 603 | 604 | void disp_room() 605 | { 606 | glColor3f(0.803,0.803,0.756); 607 | glBegin(GL_QUADS); 608 | glVertex3fv(room[0]); 609 | glVertex3fv(room[1]); 610 | glVertex3fv(room[2]); 611 | glVertex3fv(room[3]); 612 | glVertex3fv(room[3]); 613 | glVertex3fv(room[2]); 614 | glVertex3fv(room[5]); 615 | glVertex3fv(room[4]); 616 | glVertex3fv(room[4]); 617 | glVertex3fv(room[5]); 618 | glVertex3fv(room[6]); 619 | glVertex3fv(room[7]); 620 | glVertex3fv(room[1]); 621 | glVertex3fv(room[2]); 622 | glVertex3fv(room[5]); 623 | glVertex3fv(room[6]); 624 | glVertex3fv(room[0]); 625 | glVertex3f(room[0][0]+1,room[0][1],room[0][2]); 626 | glVertex3f(room[1][0]+1,room[1][1],room[1][2]); 627 | glVertex3fv(room[1]); 628 | glVertex3fv(room[7]); 629 | glVertex3f(room[7][0]-1,room[7][1],room[7][2]); 630 | glVertex3f(room[6][0]-1,room[6][1],room[6][2]); 631 | glVertex3fv(room[6]); 632 | glEnd(); 633 | } 634 | void disp_ceil() 635 | { 636 | glColor3f(1,0.843,0); 637 | glBegin(GL_TRIANGLES); 638 | glVertex3fv(ceil[2]); 639 | glVertex3fv(ceil[1]); 640 | glVertex3fv(ceil[0]); 641 | glVertex3fv(ceil[3]); 642 | glVertex3fv(ceil[4]); 643 | glVertex3fv(ceil[5]); 644 | glEnd(); 645 | glColor3f(0.933,0.866,0.509); 646 | glBegin(GL_POLYGON); 647 | glVertex3fv(ceil[2]); 648 | glVertex3fv(ceil[1]); 649 | glVertex3fv(ceil[4]); 650 | glVertex3fv(ceil[3]); 651 | glEnd(); 652 | glBegin(GL_POLYGON); 653 | glVertex3fv(ceil[0]); 654 | glVertex3fv(ceil[1]); 655 | glVertex3fv(ceil[4]); 656 | glVertex3fv(ceil[5]); 657 | glEnd(); 658 | } 659 | void draw_pil() 660 | { 661 | GLUquadricObj *quadratic; 662 | quadratic = gluNewQuadric(); 663 | glPushMatrix(); 664 | glRotatef(-90.0f, 1.0f, 0.0f, 0.0f); 665 | glColor3f(0.933,0.866,0.509); 666 | gluCylinder(quadratic,0.5,0.5,6.0f,32,32); 667 | glPopMatrix(); 668 | } 669 | void draw_mesh() 670 | { 671 | glColor3f(1,0.843,0); 672 | for(float i=0;i<0.9;i+=0.2) 673 | for(float j=0;j<6;j+=0.2) 674 | { 675 | glBegin(GL_LINE_LOOP); 676 | glVertex3f(i,j,0); 677 | glVertex3f(i+0.2,j,0); 678 | glVertex3f(i+0.2,j+0.2,0); 679 | glVertex3f(i,j+0.2,0); 680 | glEnd(); 681 | } 682 | } 683 | void disp_temple() 684 | { 685 | disp_stair(0,0,0); 686 | glPushMatrix(); 687 | disp_stair(2,1,2); 688 | disp_stair(4,2,4); 689 | 690 | glPopMatrix(); 691 | glPushMatrix(); 692 | glTranslatef(4,0,-9); 693 | glRotatef(-90,0,1,0); 694 | disp_room(); 695 | disp_ceil(); 696 | glPushMatrix(); 697 | glTranslatef(0.4,0,2.5); 698 | draw_pil(); 699 | glTranslatef(6.2,0,0); 700 | draw_pil(); 701 | glPopMatrix(); 702 | glPushMatrix(); 703 | glTranslatef(1.5,0,-3); 704 | draw_idol(); 705 | glPopMatrix(); 706 | glPushMatrix(); 707 | glTranslatef(1,0,0); 708 | draw_mesh(); 709 | glTranslatef(4,0,0); 710 | draw_mesh(); 711 | glPopMatrix(); 712 | glPopMatrix(); 713 | 714 | } 715 | 716 | }temp; 717 | class building //construction of the block buildings 718 | { 719 | float structure[8][3]; 720 | public: 721 | building(float a, float b, float c) 722 | { 723 | structure[0][0]=0;structure[0][1]=0;structure[0][2]=0; 724 | structure[1][0]=a;structure[1][1]=0;structure[1][2]=0; 725 | structure[2][0]=a;structure[2][1]=b;structure[2][2]=0; 726 | structure[3][0]=0;structure[3][1]=b;structure[3][2]=0; 727 | structure[4][0]=0;structure[4][1]=0;structure[4][2]=c; 728 | structure[5][0]=a;structure[5][1]=0;structure[5][2]=c; 729 | structure[6][0]=a;structure[6][1]=b;structure[6][2]=c; 730 | structure[7][0]=0;structure[7][1]=b;structure[7][2]=c; 731 | } 732 | void disp_build(char text[15],char side='/0') 733 | { 734 | float door[3]; 735 | glColor3f(1,0.980,0.980); 736 | glBegin(GL_QUADS); 737 | glVertex3fv(structure[0]); 738 | glVertex3fv(structure[1]); 739 | glVertex3fv(structure[2]); 740 | glVertex3fv(structure[3]); 741 | glEnd(); 742 | glBegin(GL_QUADS); 743 | glVertex3fv(structure[0]); 744 | glVertex3fv(structure[4]); 745 | glVertex3fv(structure[7]); 746 | glVertex3fv(structure[3]); 747 | glEnd(); 748 | glBegin(GL_QUADS); 749 | glVertex3fv(structure[4]); 750 | glVertex3fv(structure[5]); 751 | glVertex3fv(structure[6]); 752 | glVertex3fv(structure[7]); 753 | glEnd(); 754 | glBegin(GL_QUADS); 755 | glVertex3fv(structure[1]); 756 | glVertex3fv(structure[2]); 757 | glVertex3fv(structure[6]); 758 | glVertex3fv(structure[5]); 759 | glEnd(); 760 | 761 | if(structure[1][0]>(-1*structure[4][2])) 762 | { 763 | for(float i=10; istructure[4][2]; j-=15) 829 | { 830 | glColor3f(0,0,0); 831 | glBegin(GL_POLYGON); 832 | glVertex3f(-0.1,0,j); 833 | glVertex3f(-0.1,0,j-5); 834 | glVertex3f(-0.1,5,j-5); 835 | glVertex3f(-0.1,5,j); 836 | glEnd(); 837 | glBegin(GL_POLYGON); 838 | glVertex3f(structure[1][0]+0.1,0,j); 839 | glVertex3f(structure[1][0]+0.1,0,j-5); 840 | glVertex3f(structure[1][0]+0.1,5,j-5); 841 | glVertex3f(structure[1][0]+0.1,5,j); 842 | glEnd(); 843 | } 844 | for(float j=0;j>structure[4][2];j-=15) 845 | { 846 | glColor3f(1,0,0); 847 | glBegin(GL_POLYGON); 848 | glVertex3f(-0.1,-10,j); 849 | glVertex3f(-0.1,-10,j-2); 850 | glVertex3f(-0.1,10,j-2); 851 | glVertex3f(-0.1,10,j); 852 | glEnd(); 853 | glBegin(GL_POLYGON); 854 | glVertex3f(structure[1][0]+0.1,-10,j); 855 | glVertex3f(structure[1][0]+0.1,-10,j-2); 856 | glVertex3f(structure[1][0]+0.1,10,j-2); 857 | glVertex3f(structure[1][0]+0.1,10,j); 858 | glEnd(); 859 | } 860 | glPopMatrix(); 861 | } 862 | door[2]=(structure[4][2]/2); 863 | door[0]=structure[1][0]; 864 | glColor3f(0,0,0); 865 | if(side=='r') 866 | { 867 | glBegin(GL_POLYGON); 868 | glVertex3f(door[0]+0.2,0,door[2]-4); 869 | glVertex3f(door[0]+0.2,0,door[2]+4); 870 | glVertex3f(door[0]+0.2,7,door[2]+4); 871 | glVertex3f(door[0]+0.2,7,door[2]-4); 872 | glEnd(); 873 | glPushMatrix(); 874 | glTranslatef(door[0]+3,0,-2); 875 | glRotatef(90,0,1,0); 876 | draw_board(); 877 | glPushMatrix(); 878 | glTranslatef(1,2,0.1); 879 | glScalef(.01, .01, .01); 880 | glLineWidth(2); 881 | glColor3f(0,0,0); 882 | for (int c=0; text[c] != 0; ++c) 883 | glutStrokeCharacter(GLUT_STROKE_ROMAN, text[c]); 884 | glPopMatrix(); 885 | glPopMatrix(); 886 | } 887 | else if(side=='l') 888 | { 889 | glBegin(GL_POLYGON); 890 | glVertex3f(-0.2,0,door[2]-4); 891 | glVertex3f(-0.2,0,door[2]+4); 892 | glVertex3f(-0.2,7,door[2]+4); 893 | glVertex3f(-0.2,7,door[2]-4); 894 | glEnd(); 895 | glPushMatrix(); 896 | glTranslatef(-3,0,-10); 897 | glRotatef(-90,0,1,0); 898 | draw_board(); 899 | glPushMatrix(); 900 | glTranslatef(1,2,0.1); 901 | glScalef(.01, .01, .01); 902 | glLineWidth(2); 903 | glColor3f(0,0,0); 904 | for (int c=0; text[c] != 0; ++c) 905 | glutStrokeCharacter(GLUT_STROKE_ROMAN, text[c]); 906 | glPopMatrix(); 907 | glPopMatrix(); 908 | } 909 | } 910 | glPushMatrix(); 911 | glTranslatef(0,10,0); 912 | glColor3f(0,0,1); 913 | for(int i=0;i