1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | |
---|
15 | this file extends the framework file, so it renders what i want. |
---|
16 | */ |
---|
17 | |
---|
18 | #include "framework.h" |
---|
19 | |
---|
20 | #include "fields.h" |
---|
21 | #include "stdlibincl.h" |
---|
22 | #include "light.h" |
---|
23 | |
---|
24 | #include "cd_engine.h" |
---|
25 | #include "bv_tree.h" |
---|
26 | |
---|
27 | #include "md2Model.h" |
---|
28 | #include "model.h" |
---|
29 | #include "test_entity.h" |
---|
30 | #include "environment.h" |
---|
31 | |
---|
32 | #include "graphics_engine.h" |
---|
33 | #include "list.h" |
---|
34 | |
---|
35 | |
---|
36 | Model* mod; |
---|
37 | MD2Model* model; |
---|
38 | int drawMode; |
---|
39 | int depth; |
---|
40 | tList<WorldEntity>* entityList; |
---|
41 | |
---|
42 | int lastFrame, currentFrame, dt; |
---|
43 | bool drawModel; |
---|
44 | |
---|
45 | TestEntity* a; |
---|
46 | Environment* b; |
---|
47 | |
---|
48 | void Framework::moduleInit(int argc, char** argv) |
---|
49 | { |
---|
50 | GraphicsEngine::getInstance()->setWindowName("Collision Cluster", "collision"); |
---|
51 | |
---|
52 | CDEngine::getInstance(); |
---|
53 | |
---|
54 | /* Simple Test */ |
---|
55 | //CDEngine::getInstance()->debug(); |
---|
56 | |
---|
57 | /* MD2 Model Test */ |
---|
58 | // model = new MD2Model("models/tris.md2", "models/tris.pcx"); |
---|
59 | // model->tick(0.1f); |
---|
60 | // CDEngine::getInstance()->debugSpawnTree(9, model->data->pVertices, model->data->numVertices); |
---|
61 | |
---|
62 | /* OBJ - Model Test */ |
---|
63 | // mod = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN); |
---|
64 | // CDEngine::getInstance()->debugSpawnTree(9, (sVec3D*)mod->getVertexArray(), mod->getVertexArrayCount()); |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | entityList = new tList<WorldEntity>(); |
---|
69 | |
---|
70 | a = new TestEntity(); a->setName("Clown1"); |
---|
71 | b = new Environment(); b->setName("Jaeger"); |
---|
72 | b->setRelCoor(0.0, 0.0, -10.0); |
---|
73 | |
---|
74 | // TestEntity* c = new TestEntity(); c->setName("Colwn2"); |
---|
75 | // c->setRelCoor(0.0, 0.0, -20.0); |
---|
76 | |
---|
77 | entityList->add(a); |
---|
78 | entityList->add(b); |
---|
79 | // entityList->add(c); |
---|
80 | |
---|
81 | CDEngine::getInstance()->setEntityList(entityList); |
---|
82 | |
---|
83 | LightManager* lightMan = LightManager::getInstance(); |
---|
84 | lightMan->setAmbientColor(.1,.1,.1); |
---|
85 | lightMan->addLight(); |
---|
86 | lightMan->setPosition(30, 30, 30); |
---|
87 | lightMan->addLight(); |
---|
88 | lightMan->setPosition(-30, -30, -30); |
---|
89 | |
---|
90 | /* properties */ |
---|
91 | drawMode = DRAW_MODEL; |
---|
92 | depth = 0; |
---|
93 | dt = lastFrame = currentFrame = 0; |
---|
94 | |
---|
95 | |
---|
96 | moduleHelp(); |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | void Framework::moduleEventHandler(SDL_Event* event) |
---|
101 | { |
---|
102 | switch (event->type) |
---|
103 | { |
---|
104 | case SDL_KEYDOWN: |
---|
105 | switch (event->key.keysym.sym) |
---|
106 | { |
---|
107 | case SDLK_a: |
---|
108 | drawMode |= DRAW_ALL; |
---|
109 | break; |
---|
110 | case SDLK_0: |
---|
111 | { |
---|
112 | printf("Setting tree depth = 0\n"); |
---|
113 | depth = 0; |
---|
114 | int temp = drawMode & DRAW_ALL; |
---|
115 | drawMode ^= temp; |
---|
116 | drawMode |= DRAW_SINGLE; |
---|
117 | break; |
---|
118 | } |
---|
119 | case SDLK_1: |
---|
120 | { |
---|
121 | printf("Setting tree depth = 1\n"); |
---|
122 | depth = 1; |
---|
123 | int temp = drawMode & DRAW_ALL; |
---|
124 | drawMode ^= temp; |
---|
125 | drawMode |= DRAW_SINGLE; |
---|
126 | break; |
---|
127 | } |
---|
128 | case SDLK_2: |
---|
129 | { |
---|
130 | printf("Setting tree depth = 2\n"); |
---|
131 | depth = 2; |
---|
132 | int temp = drawMode & DRAW_ALL; |
---|
133 | drawMode ^= temp; |
---|
134 | drawMode |= DRAW_SINGLE; |
---|
135 | break; |
---|
136 | } |
---|
137 | case SDLK_3: |
---|
138 | { |
---|
139 | printf("Setting tree depth = 3\n"); |
---|
140 | depth = 3; |
---|
141 | int temp = drawMode & DRAW_ALL; |
---|
142 | drawMode ^= temp; |
---|
143 | drawMode |= DRAW_SINGLE; |
---|
144 | break; |
---|
145 | } |
---|
146 | case SDLK_4: |
---|
147 | { |
---|
148 | printf("Setting tree depth = 4\n"); |
---|
149 | depth = 4; |
---|
150 | int temp = drawMode & DRAW_ALL; |
---|
151 | drawMode ^= temp; |
---|
152 | drawMode |= DRAW_SINGLE; |
---|
153 | break; |
---|
154 | } |
---|
155 | case SDLK_5: |
---|
156 | { |
---|
157 | printf("Setting tree depth = 5\n"); |
---|
158 | depth = 5; |
---|
159 | int temp = drawMode & DRAW_ALL; |
---|
160 | drawMode ^= temp; |
---|
161 | drawMode |= DRAW_SINGLE; |
---|
162 | break; |
---|
163 | } |
---|
164 | case SDLK_6: |
---|
165 | { |
---|
166 | printf("Setting tree depth = 6\n"); |
---|
167 | depth = 6; |
---|
168 | int temp = drawMode & DRAW_ALL; |
---|
169 | drawMode ^= temp; |
---|
170 | drawMode |= DRAW_SINGLE; |
---|
171 | break; |
---|
172 | } |
---|
173 | case SDLK_s: |
---|
174 | if(drawMode & DRAW_SEPARATING_PLANE) |
---|
175 | { |
---|
176 | int temp = drawMode & DRAW_SEPARATING_PLANE; |
---|
177 | drawMode ^= temp; |
---|
178 | printf("Removing Separation Plane\n"); |
---|
179 | } |
---|
180 | else |
---|
181 | { |
---|
182 | drawMode |= DRAW_SEPARATING_PLANE; |
---|
183 | printf("Drawing Separation Plane\n"); |
---|
184 | } |
---|
185 | |
---|
186 | break; |
---|
187 | case SDLK_p: |
---|
188 | if(drawMode & DRAW_BV_POLYGON) |
---|
189 | { |
---|
190 | int temp = drawMode & DRAW_BV_POLYGON; |
---|
191 | drawMode ^= temp; |
---|
192 | printf("Removing OBB Polygons\n"); |
---|
193 | } |
---|
194 | else |
---|
195 | { |
---|
196 | drawMode |= DRAW_BV_POLYGON; |
---|
197 | printf("Drawing OBB Polygons\n"); |
---|
198 | } |
---|
199 | break; |
---|
200 | |
---|
201 | } |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | |
---|
206 | void Framework::moduleTick(float dt) |
---|
207 | { |
---|
208 | |
---|
209 | CDEngine::getInstance()->checkCollisions(); |
---|
210 | |
---|
211 | currentFrame = SDL_GetTicks(); |
---|
212 | dt = currentFrame - lastFrame; |
---|
213 | |
---|
214 | if( dt > 0) |
---|
215 | { |
---|
216 | float fps = 1000/dt; |
---|
217 | |
---|
218 | // temporary, only for showing how fast the text-engine is |
---|
219 | printf("we got %f fps\n", fps); |
---|
220 | } |
---|
221 | else |
---|
222 | { |
---|
223 | /* the frame-rate is limited to 100 frames per second, all other things are for nothing. |
---|
224 | */ |
---|
225 | SDL_Delay(1); |
---|
226 | dt = 10; |
---|
227 | } |
---|
228 | |
---|
229 | b->shiftCoor(Vector(0.0, 0.0, 0.1)); |
---|
230 | |
---|
231 | |
---|
232 | tIterator<WorldEntity>* iterator = entityList->getIterator(); /* get the iterator - JAVA style */ |
---|
233 | WorldEntity* entity = iterator->nextElement(); /* this returns the FIRST element */ |
---|
234 | while( entity != NULL) /* nextElement() will return NULL at the end */ |
---|
235 | { |
---|
236 | entity->tick(0.1); |
---|
237 | entity = iterator->nextElement(); /* give back the next element or NULL if last */ |
---|
238 | } |
---|
239 | delete iterator; |
---|
240 | |
---|
241 | lastFrame = currentFrame; |
---|
242 | } |
---|
243 | |
---|
244 | |
---|
245 | void Framework::moduleDraw() const |
---|
246 | { |
---|
247 | CDEngine::getInstance()->drawBV(depth, drawMode); |
---|
248 | LightManager::getInstance()->draw(); |
---|
249 | |
---|
250 | tIterator<WorldEntity>* iterator = entityList->getIterator(); /* get the iterator - JAVA style */ |
---|
251 | WorldEntity* entity = iterator->nextElement(); /* this returns the FIRST element */ |
---|
252 | while( entity != NULL) /* nextElement() will return NULL at the end */ |
---|
253 | { |
---|
254 | if( drawModel) |
---|
255 | entity->draw(); |
---|
256 | entity->drawBVTree(depth, drawMode); |
---|
257 | entity = iterator->nextElement(); /* give back the next element or NULL if last */ |
---|
258 | } |
---|
259 | delete iterator; |
---|
260 | //model->draw(); |
---|
261 | } |
---|
262 | |
---|
263 | |
---|
264 | void Framework::moduleHelp(void) const |
---|
265 | { |
---|
266 | printf("\n\n==========================="); |
---|
267 | printf("Collision Detection Modler:\n"); |
---|
268 | printf("Key Bindings:\n"); |
---|
269 | printf(" -| Displaying Polygons\t\t p\n"); |
---|
270 | printf(" -| Displaying Separation Plane\t s\n"); |
---|
271 | printf("\n"); |
---|
272 | printf(" -| Tree Depth 0\t\t 0\n"); |
---|
273 | printf(" -| Tree Depth 1\t\t 1\n"); |
---|
274 | printf(" -| Tree Depth 2\t\t 2\n"); |
---|
275 | printf(" -| Tree Depth 3\t\t 3\n"); |
---|
276 | printf(" -| Tree Depth 4\t\t 4\n"); |
---|
277 | printf(" -| Tree Depth 5\t\t 5\n"); |
---|
278 | printf("===========================\n\n"); |
---|
279 | |
---|
280 | } |
---|
281 | |
---|
282 | int boxPolygons(GtkWidget* nonInterest, void* widget) |
---|
283 | { |
---|
284 | if(drawMode & DRAW_BV_POLYGON) |
---|
285 | { |
---|
286 | int temp = drawMode & DRAW_BV_POLYGON; |
---|
287 | drawMode ^= temp; |
---|
288 | printf("Removing OBB Polygons\n"); |
---|
289 | } |
---|
290 | else |
---|
291 | { |
---|
292 | drawMode |= DRAW_BV_POLYGON; |
---|
293 | printf("Drawing OBB Polygons\n"); |
---|
294 | } |
---|
295 | } |
---|
296 | |
---|
297 | int seperatingPlanes(GtkWidget* nonInterest, void* widget) |
---|
298 | { |
---|
299 | if(drawMode & DRAW_SEPARATING_PLANE) |
---|
300 | { |
---|
301 | int temp = drawMode & DRAW_SEPARATING_PLANE; |
---|
302 | drawMode ^= temp; |
---|
303 | printf("Removing Separation Plane\n"); |
---|
304 | } |
---|
305 | else |
---|
306 | { |
---|
307 | drawMode |= DRAW_SEPARATING_PLANE; |
---|
308 | printf("Drawing Separation Plane\n"); |
---|
309 | } |
---|
310 | } |
---|
311 | |
---|
312 | |
---|
313 | int blendedBox(GtkWidget* nonInterest, void* widget) |
---|
314 | { |
---|
315 | if(drawMode & DRAW_BV_BLENDED) |
---|
316 | { |
---|
317 | int temp = drawMode & DRAW_BV_BLENDED; |
---|
318 | drawMode ^= temp; |
---|
319 | printf("Removing OBB Polygons\n"); |
---|
320 | } |
---|
321 | else |
---|
322 | { |
---|
323 | drawMode |= DRAW_BV_BLENDED; |
---|
324 | printf("Drawing OBB Polygons\n"); |
---|
325 | } |
---|
326 | } |
---|
327 | |
---|
328 | |
---|
329 | int drawModels(GtkWidget* nonInterest, void* widget) |
---|
330 | { |
---|
331 | drawModel = !drawModel; |
---|
332 | } |
---|
333 | |
---|
334 | |
---|
335 | int treeDepth(GtkWidget* nonInterest, void* widget) |
---|
336 | { |
---|
337 | Option* option = (Option*) widget; |
---|
338 | const char* name = option->getTitle(); |
---|
339 | char* value = option->save(); |
---|
340 | |
---|
341 | depth = atoi(value); |
---|
342 | printf("Setting tree depth = %i\n", depth); |
---|
343 | int temp = drawMode & DRAW_ALL; |
---|
344 | drawMode ^= temp; |
---|
345 | drawMode |= DRAW_SINGLE; |
---|
346 | |
---|
347 | delete value; |
---|
348 | } |
---|
349 | |
---|
350 | |
---|
351 | void Framework::moduleInitGui(int argc, char** argv) |
---|
352 | { |
---|
353 | Window* guiMainWindow = NULL; |
---|
354 | |
---|
355 | initGUI(0, NULL); |
---|
356 | |
---|
357 | guiMainWindow = new Window("Collision_detection"); |
---|
358 | { |
---|
359 | Box* windowBox = new Box('v'); |
---|
360 | { |
---|
361 | CheckButton* BoxPolygons = new CheckButton("Draw OBB Polygons"); |
---|
362 | BoxPolygons->connectSignal("clicked", (void*)BoxPolygons, boxPolygons); |
---|
363 | windowBox->fill(BoxPolygons); |
---|
364 | |
---|
365 | |
---|
366 | CheckButton* BlendedBox = new CheckButton("Draw OBB Blended"); |
---|
367 | BlendedBox->connectSignal("clicked", (void*)BlendedBox, blendedBox); |
---|
368 | windowBox->fill(BlendedBox); |
---|
369 | |
---|
370 | |
---|
371 | CheckButton* DrawModels = new CheckButton("Draw Models"); |
---|
372 | DrawModels->connectSignal("clicked", (void*)DrawModels, drawModels); |
---|
373 | windowBox->fill(DrawModels); |
---|
374 | |
---|
375 | |
---|
376 | CheckButton* SeperatingPlanes = new CheckButton("SeperatingPlanes"); |
---|
377 | SeperatingPlanes->connectSignal("clicked", (void*)SeperatingPlanes, seperatingPlanes); |
---|
378 | windowBox->fill(SeperatingPlanes); |
---|
379 | |
---|
380 | |
---|
381 | Slider* TreeDepth = new Slider("TreeDepth", 0, 5); |
---|
382 | TreeDepth->connectSignal("value_changed", (void*)TreeDepth, treeDepth); |
---|
383 | windowBox->fill(TreeDepth); |
---|
384 | } |
---|
385 | guiMainWindow->fill(windowBox); |
---|
386 | } |
---|
387 | Window::mainWindow->showall(); |
---|
388 | Window::mainWindow->setSize(300, 500); |
---|
389 | } |
---|