-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
979 lines (784 loc) · 21.3 KB
/
main.cpp
File metadata and controls
979 lines (784 loc) · 21.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
/************************************
* Erik Kremer and Caleb Gomer
* Computer Graphics Project 1
*
* An OpenGL implementation of the
* TARDIS police phone box from Doctor Who
* with Triforces from the Legend of Zelda
* This project is hosted on github
* https://github.com/calebgomer/TARDIS
* Please note: some of the camera positioning
* techniques were learned from this great tutorial
* http://www.lighthouse3d.com/tutorials/glut-tutorial/?2
***********************************/
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <cmath>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <utility>
#include <string>
#include "SOIL.h"
using namespace std;
/****************************
* determines camera mode
* 0 - manual WASD keyboard control
* 1 - a front view of the main police box
* 2 - a top-left view of the main box
* 3 - a top-down view of the box
* 4 - a view looking up from the top of the box
* (note, use 'x' and 'c' to see objects in view 4)
***************************/
int camera_mode = 0;
const int MANUAL_CAMERA = 0;
//angle of rotation for the camera direction
float angle = 0.0f;
//actual vector representing the camera's direction
float lx=0.0f, ly=0.0f, lz=-1.0f;
//XYZ position of the camera
float x=0.0f, y=0.0f, yy=0.0f, z=5.0f;
//the key states. These variables will be zero
//when no key is being pressed
float deltaAngle = 0.0f;
float deltaMove = 0.0f;
float deltaY = 0.0f;
float deltaYY = 0.0f;
//use 'r' to toggle rotations
bool rotate_everything = false;
int rotate_offset = 0;
//press 't' to toggle wireframes
bool draw_wireframes = false;
//press 'x' to toggle more police boxes
bool show_more_tardises = false;
//press 'c' to toggle more triforces
bool show_triforces = false;
//top of the polic box cylinder light thingy
GLUquadric* qobj;
//tardis lists
GLuint
tardis_face_list,
tardis_window_list,
tardis_panel_list,
tardis_blackpanel_list,
tardis_list;
//the number of tardises to draw
const int num_tardises = 10;
//triforce lists
GLuint
triforce_list,
triangle_list;
//the number of triforces to draw
const int num_triforces = 1000;
GLfloat triforces[num_triforces][3];
//textures
GLuint
ground_texture,
dw_texture;
//print a word
static void printw(string word){
for(int i=0; i < word.length();i++){
glutStrokeCharacter(GLUT_STROKE_ROMAN, word[i]);
}
}
//change the size of the screen
void changeSize(int w, int h) {
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if (h == 0)
h = 1;
float ratio = w * 1.0 / h;
// Use the Projection Matrix
glMatrixMode(GL_PROJECTION);
// Reset Matrix
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Set the correct perspective.
gluPerspective(45.0f, ratio, 0.1f, 100.0f);
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW);
}
//uses SOIL library to load PNGs for textures
static GLuint LoadPNG(char* filename)
{
GLuint texture = SOIL_load_OGL_texture
(
filename,
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);
if (texture == 0)
printf("Texture Load Error: %s", filename);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
return texture;
}
//draws an excessive number of triforces on the screen
void triforce_bomb() {
if (!show_triforces)
return;
glPushMatrix();
for (int i = num_tardises; i < num_triforces; i++) {
glPushMatrix();
//randomize color
int r = min(255,max(0,((int)abs(triforces[i][0]*2.56)%256+abs(((rotate_offset%50)-25)))));
int g = min(255,max(0,((int)abs(triforces[i][1]*2.56)%256 + abs(((rotate_offset%50)-25)))));
int b = min(255,max(0,((int)abs(triforces[i][2]*2.56)%256 + abs(((rotate_offset%50)-25)))));
glColor3ub(r, g, b);
//randomize position
glTranslatef(triforces[i][0], triforces[i][1], triforces[i][2]);
//randomize rotation
glRotatef(((int)triforces[i][0])%360, ((int)triforces[i][0])%2,((int)triforces[i][0])%2,((int)triforces[i][0])%2);
glRotatef(((int)triforces[i][0])%360+rotate_offset, 0, 1, 0);
//randomize scale
float x = (50-((int)abs(triforces[i][0])%100))/50.0;
x = x*2;
glScalef(x,x,x);
//draw the triforce
glCallList(triforce_list);
glScalef(1, 1, 1);
glPopMatrix();
}
glPopMatrix();
}
//draws an excessive number of tardises on the screen
void tardis_bomb() {
if (!show_more_tardises)
return;
glPushMatrix();
for (int i = 0; i < num_tardises; i++) {
glPushMatrix();
//randomize color
int r = min(255,max(0,((int)abs(triforces[i][0]*2.56)%256+abs(((rotate_offset%50)-25)))));
int g = min(255,max(0,((int)abs(triforces[i][1]*2.56)%256 + abs(((rotate_offset%50)-25)))));
int b = min(255,max(0,((int)abs(triforces[i][2]*2.56)%256 + abs(((rotate_offset%50)-25)))));
glColor3ub(r, g, b);
//randomize position
glTranslatef(triforces[i][0], triforces[i][1], triforces[i][2]);
//randomize rotation
glRotatef(((int)triforces[i][0])%360, ((int)triforces[i][0])%2,((int)triforces[i][0])%2,((int)triforces[i][0])%2);
glRotatef(((int)triforces[i][0])%360+rotate_offset, 0, 1, 0);
//randomize scale
glScalef(0.05, 0.05, 0.05);
//draw the tardis
glTranslatef(-125, 0, 125);
glCallList(tardis_list);
glScalef(1, 1, 1);
glPopMatrix();
}
glPopMatrix();
}
//computes the new position of the camera
void computePos(float deltaMove) {
x += deltaMove * lx * 0.1f;
z += deltaMove * lz * 0.1f;
y += deltaY;
yy += deltaY + deltaYY;
deltaY = 0.0f;
deltaYY = 0.0f;
}
//computes the new angle of the camera
void computeDir(float deltaAngle) {
angle += deltaAngle;
lx = sin(angle);
lz = -cos(angle);
}
//renders the scene
void renderScene(void) {
if (deltaMove)
computePos(deltaMove);
if (deltaAngle)
computeDir(deltaAngle);
if (rotate_everything)
rotate_offset++;
// Clear Color and Depth Buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Reset transformations
glLoadIdentity();
// Set the camera
switch (camera_mode) {
case MANUAL_CAMERA:
gluLookAt(x, y, z, x+lx, yy, z+lz, 0.0f, 1.0f, 0.0f);
break;
case 1:
gluLookAt(0, 0, 40, 0, 18, 0, 0, 1, 0);
break;
case 2:
gluLookAt(-50, 30, 40, 0, 15, 0, 0, 1, 0);
break;
case 3:
gluLookAt(0, 80, -30, 0, 0, 0, 0, 0, 1);
break;
case 4:
gluLookAt(0, 40, 0, 20, 50, 20, 0, 1, 0);
break;
}
glPolygonMode (GL_BACK, GL_LINE);
// Draw ground
glEnable(GL_TEXTURE_2D);
glColor3ub(255, 255, 255);
glBindTexture(GL_TEXTURE_2D, ground_texture);
glBegin(GL_QUADS);
glTexCoord3f(0,0,0); glVertex3f(-100.0f, -0.1f, -100.0f);
glTexCoord3f(1,0,0); glVertex3f(-100.0f, -0.1f, 100.0f);
glTexCoord3f(1,1,0); glVertex3f( 100.0f, -0.1f, 100.0f);
glTexCoord3f(0,1,0); glVertex3f( 100.0f, -0.1f, -100.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
//TRIFORCE-BOMB
triforce_bomb();
//FLOATING TARDISES
tardis_bomb();
//rotate
glRotatef((rotate_offset%240)*1.5, 0, 1, 0);
//TARDIS
glScalef(0.05f, 0.05f, 0.05f);
glTranslatef(-125, 0, 125);
glCallList(tardis_list);
glutSwapBuffers();
}
/******************************************
* Press Special Key
*****************************************/
void pressKey(int key, int xx, int yy) {
switch (key) {
case GLUT_KEY_LEFT : deltaYY = -0.2f; break;
case GLUT_KEY_RIGHT : deltaYY = +0.2f; break;
case GLUT_KEY_UP : deltaY = +5.0f; break;
case GLUT_KEY_DOWN : deltaY = -5.0f; break;
case GLUT_KEY_F1 : deltaY = +50.0f; break;
case GLUT_KEY_F2 : deltaY = -50.0f; break;
}
}
/******************************************
* Release Special Key
*****************************************/
void releaseKey(int key, int x, int y) {
switch (key) {
case GLUT_KEY_LEFT : break;
case GLUT_KEY_RIGHT : break;
case GLUT_KEY_UP : break;
case GLUT_KEY_DOWN : break;
}
}
/******************************************
* Press Keyboard
*****************************************/
void keyboardFunc (unsigned char key, int x, int y) {
switch (key) {
case 033:
case 'q':
exit(1);
break;
case 'a' : deltaAngle = -0.01f; camera_mode = 0; break;
case 'd' : deltaAngle = 0.01f; camera_mode = 0; break;
case 'w' : deltaMove = 3.0f; camera_mode = 0; break;
case 's' : deltaMove = -3.0f; camera_mode = 0; break;
default:
break;
}
}
/******************************************
* Release Keyboard
*****************************************/
void releaseKeyboard (unsigned char key, int x, int y) {
switch (key) {
//toggle wireframes
case 't':
glPolygonMode(GL_FRONT, (draw_wireframes)?GL_LINE:GL_FILL);
draw_wireframes = !draw_wireframes;
break;
case 'x':
show_more_tardises = !show_more_tardises;
break;
case 'c':
show_triforces = !show_triforces;
break;
case 'r':
rotate_everything = !rotate_everything;
break;
case '1':
camera_mode = 1;
break;
case '2':
camera_mode = 2;
break;
case '3':
camera_mode = 3;
break;
case '4':
camera_mode = 4;
break;
case 'a' :
case 'd' : deltaAngle = 0.0f;break;
case 'w' :
case 's' : deltaMove = 0;break;
default:
break;
}
}
/******************************************
* Triangle
* One of three triangles in a triforce
*****************************************/
static void triangle(float thickness) {
glPushMatrix();
glTranslatef(-2, 0, -0.175);
glBegin(GL_TRIANGLES);
glVertex3f(1, 1, 0); //front
glVertex3f(2, 0, 0);
glVertex3f(0, 0, 0);
glVertex3f(0, 0, thickness); //back
glVertex3f(2, 0, thickness);
glVertex3f(1, 1, thickness);
glEnd(); //end triangles
glBegin(GL_QUADS);
glVertex3f(1, 1, thickness); //left panel
glVertex3f(1, 1, 0);
glVertex3f(0, 0, 0);
glVertex3f(0, 0, thickness);
glVertex3f(2, 0, thickness); //right panel
glVertex3f(2, 0, 0);
glVertex3f(1, 1, 0);
glVertex3f(1, 1, thickness);
glVertex3f(0, 0, thickness); //bottom panel
glVertex3f(0, 0, 0);
glVertex3f(2, 0, 0);
glVertex3f(2, 0, thickness);
glEnd(); //end triangles
glPopMatrix();
}
/******************************************
* Triforce
* A symbol of power from the Legend of Zelda
* consisting of three triangles
*****************************************/
static void triforce() {
glPushMatrix();
//bottom left triangle
glCallList(triangle_list);
//top middle triangle
glTranslatef(1, 1, 0);
glCallList(triangle_list);
//bottom right triangle
glTranslatef(1, -1, 0);
glCallList(triangle_list);
glPopMatrix();
}
static void tardis_blackpanel(){
glBegin(GL_QUADS);
glColor3ub(0,0,0);
glVertex3f(15, 35, 5.1f);
glVertex3f(15, 7, 5.1f);
glVertex3f(225, 7, 5.1f);
glVertex3f(225, 35, 5.1f);
glEnd();
glColor3ub(255,255,255);
glPushMatrix();
glTranslatef(30,10,5.5f);
glScalef(0.2, 0.2, 0.2);
printw("POLICE");
glPopMatrix();
glPushMatrix();
glTranslatef(155,10,5.5f);
glScalef(0.2, 0.2, 0.2);
printw("BOX");
glPopMatrix();
glPushMatrix();
glTranslatef(120,23,5.5f);
glScalef(0.07, 0.07, 0.07);
printw("PUBLIC");
glPopMatrix();
glPushMatrix();
glTranslatef(124,13,5.5f);
glScalef(0.07, 0.07, 0.07);
printw("CALL");
glPopMatrix();
}
static void tardis_panel() {
glBegin(GL_QUADS);
glVertex3f(0, 0, 0);
glVertex3f(62.5, 0, 0);
glVertex3f(62.5, 60, 0);
glVertex3f(0, 60, 0);
glEnd();
}
static void tardis_window() {
glColor3ub(255, 255, 255);
glBegin(GL_QUADS);
glVertex3f(0, 0, 0);
glVertex3f(70, 0, 0);
glVertex3f(70, 75, 0);
glVertex3f(0, 75, 0);
glEnd();
glTranslatef(0, 0, 0.1f);
glColor3ub(40, 80, 132);
glLineWidth(10);
glBegin(GL_LINES);
glVertex3f(70, 37.5, 0);
glVertex3f(0, 37.5, 0);
glEnd();
glBegin(GL_LINES);
glVertex3f(22.5, 75, 0);
glVertex3f(22.5, 0, 0);
glEnd();
glBegin(GL_LINES);
glVertex3f(50, 75, 0);
glVertex3f(50, 0, 0);
glEnd();
glLineWidth(1);
}
static void tardis_face() {
//panels inside main box
glColor3ub(33, 71, 120);
glBegin(GL_QUADS);
glVertex3f(132.5, 10, 1.5);
glVertex3f(122.5, 10, 1.5);
glVertex3f(122.5, 400, 1.5);
glVertex3f(132.5, 400, 1.5);
glEnd();
glTranslatef(45.0f, 50.0f, 1.0f);
glCallList(tardis_panel_list);
glTranslatef(100.0f, 0.0f, 0.0f);
glCallList(tardis_panel_list);
glTranslatef(-100.0f, 75.0f, 0.0f);
glCallList(tardis_panel_list);
glTranslatef(100.0f, 0.0f, 0.0f);
glCallList(tardis_panel_list);
glTranslatef(-100.0f, 75.0f, 0.0f);
glCallList(tardis_panel_list);
glTranslatef(100.0f, 0.0f, 0.0f);
glCallList(tardis_panel_list);
//WindowPanes
glTranslatef(-105.0f, 75.0f, 0.0f);
glCallList(tardis_window_list);
glTranslatef(102.5f, 0.0f, 0.0f);
glCallList(tardis_window_list);
}
static void tardis(){
//large top square on the top of the tardis
//(behind police public call box square)
glPushMatrix();
glTranslatef(5.0f, 380.0f, 5.0f);
glBegin(GL_QUAD_STRIP);
glColor3ub(24, 47, 89);
glVertex3f(240, 0, 0);
glVertex3f(240, 40, 0);
glVertex3f(0, 0, 0);
glVertex3f(0, 40, 0);
glVertex3f(0, 0, -240);
glVertex3f(0, 40, -240);
glVertex3f(240, 0, -240);
glVertex3f(240, 40, -240);
glVertex3f(240, 0, 0);
glVertex3f(240, 40, 0);
glEnd();
glBegin(GL_QUADS);
//top of this box
glColor3ub(33, 71, 120);
glVertex3f(240, 40, 0);
glVertex3f(240, 40, -240);
glVertex3f(0, 40, -240);
glVertex3f(0, 40, 0);
//bottom of this box
glColor3ub(33, 71, 120);
glVertex3f(240, 0, 0);
glVertex3f(0, 0, 0);
glVertex3f(0, 0, -240);
glVertex3f(240, 0, -240);
glEnd();
//black back behind 'police box' text
glPushMatrix();
//front face
glTranslatef(0,0,-5);
glCallList(tardis_blackpanel_list);
glPopMatrix();
glPushMatrix();
//left face
glRotatef(-90.0f,0.0f, 1.0f, 0.0f);
glTranslatef(-240, 0, -5);
glCallList(tardis_blackpanel_list);
glPopMatrix();
glPushMatrix();
//right face
glRotatef(90.0f,0.0f, 1.0f, 0.0f);
glTranslatef(0, 0, 235);
glCallList(tardis_blackpanel_list);
glPopMatrix();
glPushMatrix();
//back face
glRotatef(180.0f,0.0f, 1.0f, 0.0f);
glTranslatef(-240, 0, 235);
glCallList(tardis_blackpanel_list);
glPopMatrix();
//very top boxes
glTranslatef(15,40,-15);
glColor3ub(22, 45, 87);
glBegin(GL_QUAD_STRIP);
glVertex3f(210, 0, 0);
glVertex3f(210, 15, 0);
glVertex3f(0, 0, 0);
glVertex3f(0, 15, 0);
glVertex3f(0, 0, -210);
glVertex3f(0, 15, -210);
glVertex3f(210, 0, -210);
glVertex3f(210, 15, -210);
glVertex3f(210, 0, 0);
glVertex3f(210, 15, 0);
glEnd();
glBegin(GL_QUADS);
//top of this box
glColor3ub(33, 71, 120);
glVertex3f(210, 15, 0);
glVertex3f(210, 15, -210);
glVertex3f(0, 15, -210);
glVertex3f(0, 15, 0);
glEnd();
glTranslatef(10,15,-10);
glBegin(GL_QUAD_STRIP);
glColor3ub(22, 45, 87);
glVertex3f(190, 0, 0);
glVertex3f(190, 5, 0);
glVertex3f(0, 0, 0);
glVertex3f(0, 5, 0);
glVertex3f(0, 0, -190);
glVertex3f(0, 5, -190);
glVertex3f(190, 0, -190);
glVertex3f(190, 5, -190);
glVertex3f(190, 0, 0);
glVertex3f(190, 5, 0);
glEnd();
glBegin(GL_QUADS);
//top of this box
glColor3ub(33, 71, 120);
glVertex3f(190, 5, 0);
glVertex3f(190, 5, -190);
glVertex3f(0, 5, -190);
glVertex3f(0, 5, 0);
glEnd();
glColor3ub(32, 60, 105);
glTranslatef(82.5,5,-82.5);
glLineWidth(4);
glBegin(GL_LINES);
glVertex3f(0, 0, 0);
glVertex3f(0, 27.5, 0);
glEnd();
glBegin(GL_LINES);
glVertex3f(25, 0, 0);
glVertex3f(25, 27.5, 0);
glEnd();
glBegin(GL_LINES);
glVertex3f(25, 0, -25);
glVertex3f(25, 27.5, -25);
glEnd();
glBegin(GL_LINES);
glVertex3f(0, 0, -25);
glVertex3f(0, 27.5, -25);
glEnd();
glLineWidth(1);
glBegin(GL_TRIANGLE_FAN);
glVertex3f(12.5, 35, -12.5);
glVertex3f(-2.5, 27.5, 2.5);
glVertex3f(27.5, 27.5, 2.5);
glVertex3f(27.5, 27.5, -27.5);
glVertex3f(-2.5, 27.5, -27.5);
glVertex3f(-2.5, 27.5, 2.5);
glEnd();
glColor3ub(33, 71, 120);
glBegin(GL_LINES);
glVertex3f(12.5, 35, -12.5);
glVertex3f(-2.5, 27.5, 2.5);
glEnd();
glBegin(GL_LINES);
glVertex3f(12.5, 35, -12.5);
glVertex3f(-2.5, 27.5, -27.5);
glEnd();
glBegin(GL_LINES);
glVertex3f(12.5, 35, -12.5);
glVertex3f(27.5, 27.5, -27.5);
glEnd();
glBegin(GL_LINES);
glVertex3f(12.5, 35, -12.5);
glVertex3f(27.5, 27.5, 2.5);
glEnd();
glColor3ub(179,200,255);
glTranslatef(12.5,0,-12.5);
glRotatef(-90,1,0,0);
gluCylinder(qobj, 10,10,27.5,120,160);
glPopMatrix();
//main box rectangle
glPushMatrix();
glTranslatef(10.0f, 10.0f, 0.0f);
glColor3ub(31, 61, 114);
glBegin(GL_QUAD_STRIP);
glVertex3f(230,0,0);//bottom right
glVertex3f(230,370,0);//top right
glVertex3f(0,0,0);//bottom left
glVertex3f(0,370,0);//top left
glColor3ub(32, 60, 105);
glVertex3f(0,0,-230);
glVertex3f(0,370,-230);
glVertex3f(230,0,-230);
glVertex3f(230,370,-230);
glVertex3f(230,0,0);//bottom right
glVertex3f(230,370,0);//top right
glEnd();
glPopMatrix();
//base platform rectangle
glPushMatrix();
glColor3ub(40, 80, 132);
glBegin(GL_QUAD_STRIP);
glVertex3f(245,0,5);
glVertex3f(245,10,5);
glVertex3f(5,0,5);
glVertex3f(5,10,5);
glVertex3f(5,0,-235);
glVertex3f(5,10,-235);
glVertex3f(245,0,-235);
glVertex3f(245,10,-235);
glVertex3f(245,0,5);
glVertex3f(245,10,5);
glEnd();
//base platform bottom face
glColor3ub(31, 61, 114);
glBegin(GL_QUADS);
glVertex3f(245,0,5);
glVertex3f(5,0,5);
glVertex3f(5,0,-235);
glVertex3f(245,0,-235);
glEnd();
glEnable(GL_TEXTURE_2D);
glColor3ub(255, 255, 255);
glBindTexture(GL_TEXTURE_2D, dw_texture);
glBegin(GL_QUADS);
glTexCoord3f(0,0,0); glVertex3f(240, 0.5, -230);
glTexCoord3f(1,0,0); glVertex3f(10, 0.5, -230);
glTexCoord3f(1,1,0); glVertex3f(10, 0.5, 0);
glTexCoord3f(0,1,0); glVertex3f(240, 0.5, 0);
glEnd();
glDisable(GL_TEXTURE_2D);
//triangles around the base of the tardis
glColor3ub(36, 67, 120);
glBegin(GL_QUAD_STRIP);
glVertex3f(245,10,5);
glVertex3f(240,15,0);
glVertex3f(5,10,5);
glVertex3f(10,15,0);
glVertex3f(5,10,-235);
glVertex3f(10,15,-230);
glVertex3f(245,10,-235);
glVertex3f(240,15,-230);
glVertex3f(245,10,5);
glVertex3f(240,15,0);
glEnd();
glPopMatrix();
//front face
glPushMatrix();
glCallList(tardis_face_list);
glTranslatef(-91,-70,1);
glColor3ub(208,206,217);
glBegin(GL_QUADS);
glVertex3f(50,50,0);
glVertex3f(0,50,0);
glVertex3f(0,0,0);
glVertex3f(50,0,0);
glEnd();
glPopMatrix();
//left face
glPushMatrix();
glRotatef(-90.0f,0.0f, 1.0f, 0.0f);
glTranslatef(-240, 0, -10);
glCallList(tardis_face_list);
glPopMatrix();
//right face
glPushMatrix();
glRotatef(90.0f,0.0f, 1.0f, 0.0f);
glTranslatef(-10, 0, 240);
glCallList(tardis_face_list);
glPopMatrix();
//back face
glPushMatrix();
glRotatef(180.0f,0.0f, 1.0f, 0.0f);
glTranslatef(-250, 0, 230);
glCallList(tardis_face_list);
glPopMatrix();
}
// setup lists
void init() {
//load ground texture
ground_texture = LoadPNG((char *)"/<path-to-image>/ground.png");
//load dw texture
dw_texture = LoadPNG((char *)"/<path-to-image>/dw.png");
//cylinder light at the top of the police box
qobj = gluNewQuadric();
gluQuadricDrawStyle(qobj, GLU_FILL);
gluQuadricNormals(qobj, GLU_SMOOTH);
gluQuadricOrientation(qobj, GLU_OUTSIDE);
tardis_blackpanel_list = glGenLists(1);
glNewList(tardis_blackpanel_list,GL_COMPILE);
tardis_blackpanel();
glEndList();
tardis_panel_list = glGenLists(1);
glNewList(tardis_panel_list,GL_COMPILE);
tardis_panel();
glEndList();
tardis_window_list = glGenLists(1);
glNewList(tardis_window_list,GL_COMPILE);
tardis_window();
glEndList();
tardis_face_list = glGenLists(1);
glNewList(tardis_face_list, GL_COMPILE);
tardis_face();
glEndList();
tardis_list = glGenLists(1);
glNewList(tardis_list,GL_COMPILE);
tardis();
glEndList();
triangle_list = glGenLists(1);
glNewList(triangle_list, GL_COMPILE);
triangle(0.35);
glEndList();
triforce_list = glGenLists(1);
glNewList(triforce_list, GL_COMPILE);
triforce();
glEndList();
}
int main(int argc, char **argv) {
//compute the locations of all the triforces one time
for (int i = 0; i < num_triforces; i++) {
triforces[i][0]= rand()%200-100;
triforces[i][1]= rand()%100;
triforces[i][2]= rand()%200-100;
}
// init GLUT and create window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(0,0);
glutInitWindowSize(1024,768);
glutCreateWindow("TARDIS+ - Time and Relative Dimmension in Space + Triforces");
init(); //setup lists and stuff
// register callbacks
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
glutIdleFunc(renderScene);
glutSpecialFunc(pressKey);
glutKeyboardFunc(keyboardFunc);
glutKeyboardUpFunc(releaseKeyboard);
// here are the new entries
glutIgnoreKeyRepeat(1);
glutSpecialUpFunc(releaseKey);
// OpenGL init
glEnable(GL_DEPTH_TEST);
// enter GLUT event processing cycle
glutMainLoop();
return 1;
}