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