forked from itsfuad/Computer-Graphics-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
248 lines (214 loc) · 5.67 KB
/
Copy pathmain.cpp
File metadata and controls
248 lines (214 loc) · 5.67 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
#include "shoab.h"
#include "masud.h"
#include "mahtab.h"
#include "fuad.h"
#include "welcome.h"
int currentScene = 0; // Start with welcome screen
int numOfScene = 4; // Total number of scenes (excluding welcome)
// Global scene management
void cleanupCurrentScene() {
switch (currentScene) {
case 0:
Welcome::cleanupScene();
break;
case 1:
Fuad::cleanupScene();
break;
case 2:
Masud::cleanupScene();
break;
case 3:
Mahtab::cleanupScene();
break;
case 4:
Shoab::cleanupScene();
break;
}
}
void initCurrentScene() {
switch (currentScene) {
case 0:
Welcome::initScene();
break;
case 1:
Fuad::initScene();
break;
case 2:
Masud::initScene();
break;
case 3:
Mahtab::initScene();
break;
case 4:
Shoab::initScene();
break;
}
}
void updateWindowTitle() {
switch (currentScene) {
case 0:
glutSetWindowTitle("OpenGL City Scene Animation");
break;
case 1:
glutSetWindowTitle("Fuad's Scene - Busy traffic Simulation");
break;
case 2:
glutSetWindowTitle("Masud's Scene - City view with river and road");
break;
case 3:
glutSetWindowTitle("Mahtab's Scene - City view with train, bridge and vehicles");
break;
case 4:
glutSetWindowTitle("Shoab's Scene - Factory with river and vehicles");
break;
}
}
void switchScene(int newScene) {
if (newScene < 0 || newScene > numOfScene) return;
// Cleanup current scene
cleanupCurrentScene();
// Switch to new scene
currentScene = newScene;
// Initialize new scene
initCurrentScene();
// Update window title
updateWindowTitle();
}
void specialKeyboard(int key, int x, int y) {
switch (key) {
case GLUT_KEY_RIGHT:
if (currentScene < numOfScene) {
switchScene(currentScene + 1);
}
break;
case GLUT_KEY_LEFT:
if (currentScene > 0) {
switchScene(currentScene - 1);
}
break;
}
// Handle scene-specific special keys
switch (currentScene) {
case 1:
// Fuad's scene doesn't use special keys
break;
case 2:
Masud::specialKeyboard(key, x, y);
break;
}
}
void handleKeyboard(unsigned char key, int x, int y) {
// Handle keyboard input
switch (currentScene) {
case 0:
Welcome::keyboard(key, x, y);
break;
case 1:
Fuad::keyboard(key, x, y);
break;
case 2:
Masud::keyboard(key, x, y);
break;
case 3:
Mahtab::keyboard(key, x, y);
break;
case 4:
Shoab::keyboard(key, x, y);
break;
}
}
void handleMouse(int button, int state, int x, int y) {
// Handle mouse input
switch (currentScene) {
case 0:
Welcome::mouse(button, state, x, y);
break;
case 1:
Fuad::mouse(button, state, x, y);
break;
case 2:
Masud::mouse(button, state, x, y);
break;
case 3:
Mahtab::mouse(button, state, x, y);
break;
}
}
void handleMouseMotion(int x, int y) {
if (currentScene == 0) {
Welcome::mouseMotion(x, y);
}
}
void updateFunc(int) {
// Update the scene
switch (currentScene) {
case 0:
Welcome::updateScene();
break;
case 1:
Fuad::updateScene();
break;
case 2:
Masud::updateScene();
break;
case 3:
Mahtab::updateScene();
break;
case 4:
Shoab::updateScene();
break;
}
glutTimerFunc(1000 / 60, updateFunc, 0);
}
void displayFunc() {
switch (currentScene) {
case 0:
Welcome::display();
break;
case 1:
Fuad::display();
break;
case 2:
Masud::display();
break;
case 3:
Mahtab::display();
break;
case 4:
Shoab::display();
break;
}
glutSwapBuffers();
}
void initGLUT(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
glutCreateWindow("Computer Graphics Project - City View Animation");
// Set initial window title
updateWindowTitle();
std::cout << "Initializing OpenGL..." << std::endl;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, WINDOW_WIDTH, 0.0, WINDOW_HEIGHT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
srand(time(0));
std::cout << "OpenGL initialization complete" << std::endl;
}
int main(int argc, char **argv) {
initGLUT(argc, argv);
std::cout << "Initializing scene..." << std::endl;
initCurrentScene();
glutDisplayFunc(displayFunc);
glutTimerFunc(0, updateFunc, 0);
glutKeyboardFunc(handleKeyboard);
glutSpecialFunc(specialKeyboard);
glutMouseFunc(handleMouse);
glutMotionFunc(handleMouseMotion); // for welcome screen
std::cout << "Entering main loop..." << std::endl;
glutMainLoop();
return 0;
}