/
globalScene.cpp
executable file
·135 lines (110 loc) · 2.56 KB
/
globalScene.cpp
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
#include "globalScene.h"
GlobalScene::GlobalScene()
{
}
void GlobalScene::init(Viewer &viewer)
{
animationStep=0;
for (int i = 0; i < 10; i++){
pilars[i] = new Pilar(true);
pilars[i]->init(viewer);
}
for (int i = 10; i < 13; i++){
pilars[i] = new Pilar(false);
pilars[i]->init(viewer);
}
for (int i = 0; i < NUM_TORCHES; i++){
torches[i] = new Torch(3);
torches[i]->init(viewer);
}
teapot = new TeaPot();
teapot->init(viewer);
dragon = new Dragon();
dragon->init(viewer);
ground = new Ground(100,100);
ground->init(viewer);
for (int i = 0; i < NUM_WALLS; i++){
walls[i] = new Wall(50,50);
walls[i]->init(viewer);
}
skybox = new Skybox();
skybox->init(viewer);
}
void GlobalScene::drawPillarsAndTorches(){
glPushMatrix();
int step = 10;
glColor3f(0.2,0.2,0.2);
for (int i = 0; i < 5; i++){
pilars[i]->draw();
glTranslatef(step,0,0);
}
glTranslatef(-step , 30, 0);
glRotatef(180, 0, 0, 1);
for (int i = 5; i < 10 ; i++){
pilars[i]->draw();
glTranslatef(step,0,0);
}
glTranslatef(18,70,0);
step = 7;
for (int i = 10; i < 13 ; i++){
pilars[i]->draw();
glTranslatef(step,0,0);
}
glTranslatef(-3*step,0,20);
torches[0]->draw();
glTranslatef(step*2,0,0);
torches[1]->draw();
glRotatef(90, 1, 0, 0);
glTranslatef(-step,2.2,0);
glColor3f(0.8,0.8,0.8);
teapot->draw();
glPopMatrix();
}
void GlobalScene::drawGround(){
glPushMatrix();
glTranslatef(-50, -50, 0);
ground->draw();
glPopMatrix();
}
void GlobalScene::drawSkybox(){
//glPushMatrix();
glScalef(2000,2000,2000);
skybox->draw();
glScalef(0.0005,0.0005,0.0005);
//glPopMatrix();
}
void GlobalScene::drawWalls(){
glPushMatrix();
glTranslatef(-50, -50, 0);
walls[0]->draw();
glTranslatef(50, 0, 0);
walls[1]->draw();
glRotatef(90, 0, 0, 1);
glTranslatef(0, -50, 0);
walls[2]->draw();
glTranslatef(50, 0, 0);
walls[3]->draw();
glPopMatrix();
}
void GlobalScene::draw()
{
drawSkybox();
drawGround();
drawWalls();
drawPillarsAndTorches();
glRotatef(90, 1, 0, 0);
glTranslatef(15, 5, -15);
dragon->draw();
}
void GlobalScene::animate()
{
animationStep += 0.2;
teapot->animate(animationStep);
for (int i = 0; i < NUM_PILARS; i++){
pilars[i]->animate();
}
for (int i = 0; i < NUM_TORCHES; i++){
torches[i]->animate();
}
dragon->animate();
}