[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 | |
---|
[4708] | 46 | Environment* 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 | |
---|
[4708] | 71 | //a = new TestEntity(); a->setName("Clown1"); |
---|
| 72 | a = new Environment(); a->setName("Clown"); |
---|
[4701] | 73 | b = new Environment(); b->setName("Jaeger"); |
---|
[4708] | 74 | |
---|
[4679] | 75 | b->setRelCoor(0.0, 0.0, -10.0); |
---|
[4708] | 76 | b->setRelDir(Quaternion(-M_PI/2.0f, Vector(0.0, 1.0, 0.0))); |
---|
[4630] | 77 | |
---|
[4695] | 78 | // TestEntity* c = new TestEntity(); c->setName("Colwn2"); |
---|
| 79 | // c->setRelCoor(0.0, 0.0, -20.0); |
---|
[4694] | 80 | |
---|
[4675] | 81 | entityList->add(a); |
---|
[4679] | 82 | entityList->add(b); |
---|
[4630] | 83 | |
---|
[4688] | 84 | CDEngine::getInstance()->setEntityList(entityList); |
---|
[4675] | 85 | |
---|
[4552] | 86 | LightManager* lightMan = LightManager::getInstance(); |
---|
| 87 | lightMan->setAmbientColor(.1,.1,.1); |
---|
| 88 | lightMan->addLight(); |
---|
[4638] | 89 | lightMan->setPosition(30, 30, 30); |
---|
[4552] | 90 | lightMan->addLight(); |
---|
[4638] | 91 | lightMan->setPosition(-30, -30, -30); |
---|
[4636] | 92 | |
---|
[4675] | 93 | /* properties */ |
---|
[4636] | 94 | drawMode = DRAW_MODEL; |
---|
[4673] | 95 | depth = 0; |
---|
[4679] | 96 | dt = lastFrame = currentFrame = 0; |
---|
[4704] | 97 | iterata = 0.05f; |
---|
[4636] | 98 | |
---|
[4647] | 99 | moduleHelp(); |
---|
[4333] | 100 | } |
---|
| 101 | |
---|
[4546] | 102 | |
---|
[4334] | 103 | void Framework::moduleEventHandler(SDL_Event* event) |
---|
| 104 | { |
---|
| 105 | switch (event->type) |
---|
[4622] | 106 | { |
---|
[4334] | 107 | case SDL_KEYDOWN: |
---|
| 108 | switch (event->key.keysym.sym) |
---|
[4622] | 109 | { |
---|
[4636] | 110 | case SDLK_a: |
---|
| 111 | drawMode |= DRAW_ALL; |
---|
[4615] | 112 | break; |
---|
[4638] | 113 | case SDLK_0: |
---|
| 114 | { |
---|
| 115 | printf("Setting tree depth = 0\n"); |
---|
| 116 | depth = 0; |
---|
| 117 | int temp = drawMode & DRAW_ALL; |
---|
| 118 | drawMode ^= temp; |
---|
| 119 | drawMode |= DRAW_SINGLE; |
---|
| 120 | break; |
---|
| 121 | } |
---|
[4622] | 122 | case SDLK_1: |
---|
[4636] | 123 | { |
---|
| 124 | printf("Setting tree depth = 1\n"); |
---|
| 125 | depth = 1; |
---|
| 126 | int temp = drawMode & DRAW_ALL; |
---|
| 127 | drawMode ^= temp; |
---|
| 128 | drawMode |= DRAW_SINGLE; |
---|
[4622] | 129 | break; |
---|
[4636] | 130 | } |
---|
| 131 | case SDLK_2: |
---|
| 132 | { |
---|
| 133 | printf("Setting tree depth = 2\n"); |
---|
| 134 | depth = 2; |
---|
| 135 | int temp = drawMode & DRAW_ALL; |
---|
| 136 | drawMode ^= temp; |
---|
| 137 | drawMode |= DRAW_SINGLE; |
---|
| 138 | break; |
---|
| 139 | } |
---|
| 140 | case SDLK_3: |
---|
| 141 | { |
---|
| 142 | printf("Setting tree depth = 3\n"); |
---|
| 143 | depth = 3; |
---|
| 144 | int temp = drawMode & DRAW_ALL; |
---|
| 145 | drawMode ^= temp; |
---|
| 146 | drawMode |= DRAW_SINGLE; |
---|
| 147 | break; |
---|
| 148 | } |
---|
| 149 | case SDLK_4: |
---|
| 150 | { |
---|
| 151 | printf("Setting tree depth = 4\n"); |
---|
| 152 | depth = 4; |
---|
| 153 | int temp = drawMode & DRAW_ALL; |
---|
| 154 | drawMode ^= temp; |
---|
| 155 | drawMode |= DRAW_SINGLE; |
---|
| 156 | break; |
---|
| 157 | } |
---|
| 158 | case SDLK_5: |
---|
| 159 | { |
---|
| 160 | printf("Setting tree depth = 5\n"); |
---|
| 161 | depth = 5; |
---|
| 162 | int temp = drawMode & DRAW_ALL; |
---|
| 163 | drawMode ^= temp; |
---|
| 164 | drawMode |= DRAW_SINGLE; |
---|
| 165 | break; |
---|
| 166 | } |
---|
| 167 | case SDLK_6: |
---|
| 168 | { |
---|
| 169 | printf("Setting tree depth = 6\n"); |
---|
| 170 | depth = 6; |
---|
| 171 | int temp = drawMode & DRAW_ALL; |
---|
| 172 | drawMode ^= temp; |
---|
| 173 | drawMode |= DRAW_SINGLE; |
---|
| 174 | break; |
---|
| 175 | } |
---|
| 176 | case SDLK_s: |
---|
| 177 | if(drawMode & DRAW_SEPARATING_PLANE) |
---|
| 178 | { |
---|
| 179 | int temp = drawMode & DRAW_SEPARATING_PLANE; |
---|
| 180 | drawMode ^= temp; |
---|
| 181 | printf("Removing Separation Plane\n"); |
---|
| 182 | } |
---|
| 183 | else |
---|
| 184 | { |
---|
| 185 | drawMode |= DRAW_SEPARATING_PLANE; |
---|
| 186 | printf("Drawing Separation Plane\n"); |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | break; |
---|
| 190 | case SDLK_p: |
---|
| 191 | if(drawMode & DRAW_BV_POLYGON) |
---|
| 192 | { |
---|
| 193 | int temp = drawMode & DRAW_BV_POLYGON; |
---|
| 194 | drawMode ^= temp; |
---|
| 195 | printf("Removing OBB Polygons\n"); |
---|
| 196 | } |
---|
| 197 | else |
---|
| 198 | { |
---|
| 199 | drawMode |= DRAW_BV_POLYGON; |
---|
| 200 | printf("Drawing OBB Polygons\n"); |
---|
| 201 | } |
---|
| 202 | break; |
---|
[4704] | 203 | case SDLK_o: |
---|
| 204 | if(iterata == 0.0f) |
---|
| 205 | { |
---|
| 206 | iterata = 0.05f; |
---|
| 207 | } |
---|
| 208 | else |
---|
| 209 | { |
---|
| 210 | iterata = 0.0f; |
---|
| 211 | } |
---|
| 212 | break; |
---|
[4636] | 213 | |
---|
[4622] | 214 | } |
---|
| 215 | } |
---|
[4333] | 216 | } |
---|
| 217 | |
---|
[4546] | 218 | |
---|
[4333] | 219 | void Framework::moduleTick(float dt) |
---|
| 220 | { |
---|
[4679] | 221 | |
---|
[4696] | 222 | CDEngine::getInstance()->checkCollisions(); |
---|
[4688] | 223 | |
---|
[4679] | 224 | |
---|
[4704] | 225 | b->shiftCoor(Vector(0.0, 0.0, iterata)); |
---|
[4679] | 226 | |
---|
[4701] | 227 | |
---|
[4708] | 228 | tIterator<WorldEntity>* iterator = entityList->getIterator(); |
---|
| 229 | WorldEntity* entity = iterator->nextElement(); |
---|
| 230 | while( entity != NULL) |
---|
[4675] | 231 | { |
---|
[4706] | 232 | entity->tick(dt); |
---|
[4708] | 233 | entity = iterator->nextElement(); |
---|
[4675] | 234 | } |
---|
| 235 | delete iterator; |
---|
[4333] | 236 | } |
---|
| 237 | |
---|
[4546] | 238 | |
---|
[4349] | 239 | void Framework::moduleDraw() const |
---|
[4334] | 240 | { |
---|
[4708] | 241 | tIterator<WorldEntity>* iterator = entityList->getIterator(); |
---|
| 242 | WorldEntity* entity = iterator->nextElement(); |
---|
| 243 | while( entity != NULL) |
---|
[4679] | 244 | { |
---|
[4707] | 245 | if( likely(drawModel)) |
---|
[4679] | 246 | entity->draw(); |
---|
[4707] | 247 | entity->drawBVTree(depth, drawMode); |
---|
[4708] | 248 | entity = iterator->nextElement(); |
---|
[4679] | 249 | } |
---|
| 250 | delete iterator; |
---|
[4707] | 251 | |
---|
| 252 | LightManager::getInstance()->draw(); |
---|
[4334] | 253 | } |
---|
[4333] | 254 | |
---|
[4334] | 255 | |
---|
[4333] | 256 | void Framework::moduleHelp(void) const |
---|
| 257 | { |
---|
[4647] | 258 | printf("\n\n==========================="); |
---|
| 259 | printf("Collision Detection Modler:\n"); |
---|
| 260 | printf("Key Bindings:\n"); |
---|
| 261 | printf(" -| Displaying Polygons\t\t p\n"); |
---|
| 262 | printf(" -| Displaying Separation Plane\t s\n"); |
---|
| 263 | printf("\n"); |
---|
| 264 | printf(" -| Tree Depth 0\t\t 0\n"); |
---|
| 265 | printf(" -| Tree Depth 1\t\t 1\n"); |
---|
| 266 | printf(" -| Tree Depth 2\t\t 2\n"); |
---|
| 267 | printf(" -| Tree Depth 3\t\t 3\n"); |
---|
| 268 | printf(" -| Tree Depth 4\t\t 4\n"); |
---|
| 269 | printf(" -| Tree Depth 5\t\t 5\n"); |
---|
| 270 | printf("===========================\n\n"); |
---|
| 271 | |
---|
[4333] | 272 | } |
---|
| 273 | |
---|
[4646] | 274 | int boxPolygons(GtkWidget* nonInterest, void* widget) |
---|
| 275 | { |
---|
| 276 | if(drawMode & DRAW_BV_POLYGON) |
---|
| 277 | { |
---|
| 278 | int temp = drawMode & DRAW_BV_POLYGON; |
---|
| 279 | drawMode ^= temp; |
---|
| 280 | printf("Removing OBB Polygons\n"); |
---|
| 281 | } |
---|
| 282 | else |
---|
| 283 | { |
---|
| 284 | drawMode |= DRAW_BV_POLYGON; |
---|
| 285 | printf("Drawing OBB Polygons\n"); |
---|
| 286 | } |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | int seperatingPlanes(GtkWidget* nonInterest, void* widget) |
---|
| 290 | { |
---|
| 291 | if(drawMode & DRAW_SEPARATING_PLANE) |
---|
| 292 | { |
---|
| 293 | int temp = drawMode & DRAW_SEPARATING_PLANE; |
---|
| 294 | drawMode ^= temp; |
---|
| 295 | printf("Removing Separation Plane\n"); |
---|
| 296 | } |
---|
| 297 | else |
---|
| 298 | { |
---|
| 299 | drawMode |= DRAW_SEPARATING_PLANE; |
---|
| 300 | printf("Drawing Separation Plane\n"); |
---|
| 301 | } |
---|
| 302 | } |
---|
| 303 | |
---|
[4671] | 304 | |
---|
| 305 | int blendedBox(GtkWidget* nonInterest, void* widget) |
---|
| 306 | { |
---|
| 307 | if(drawMode & DRAW_BV_BLENDED) |
---|
| 308 | { |
---|
| 309 | int temp = drawMode & DRAW_BV_BLENDED; |
---|
| 310 | drawMode ^= temp; |
---|
| 311 | printf("Removing OBB Polygons\n"); |
---|
| 312 | } |
---|
| 313 | else |
---|
| 314 | { |
---|
| 315 | drawMode |= DRAW_BV_BLENDED; |
---|
| 316 | printf("Drawing OBB Polygons\n"); |
---|
| 317 | } |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | |
---|
[4686] | 321 | int drawModels(GtkWidget* nonInterest, void* widget) |
---|
| 322 | { |
---|
| 323 | drawModel = !drawModel; |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | |
---|
[4646] | 327 | int treeDepth(GtkWidget* nonInterest, void* widget) |
---|
| 328 | { |
---|
| 329 | Option* option = (Option*) widget; |
---|
| 330 | const char* name = option->getTitle(); |
---|
| 331 | char* value = option->save(); |
---|
| 332 | |
---|
| 333 | depth = atoi(value); |
---|
| 334 | printf("Setting tree depth = %i\n", depth); |
---|
| 335 | int temp = drawMode & DRAW_ALL; |
---|
| 336 | drawMode ^= temp; |
---|
| 337 | drawMode |= DRAW_SINGLE; |
---|
| 338 | |
---|
| 339 | delete value; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | |
---|
[4343] | 343 | void Framework::moduleInitGui(int argc, char** argv) |
---|
[4333] | 344 | { |
---|
[4626] | 345 | Window* guiMainWindow = NULL; |
---|
| 346 | |
---|
| 347 | initGUI(0, NULL); |
---|
| 348 | |
---|
| 349 | guiMainWindow = new Window("Collision_detection"); |
---|
| 350 | { |
---|
[4646] | 351 | Box* windowBox = new Box('v'); |
---|
| 352 | { |
---|
[4671] | 353 | CheckButton* BoxPolygons = new CheckButton("Draw OBB Polygons"); |
---|
[4646] | 354 | BoxPolygons->connectSignal("clicked", (void*)BoxPolygons, boxPolygons); |
---|
| 355 | windowBox->fill(BoxPolygons); |
---|
| 356 | |
---|
| 357 | |
---|
[4671] | 358 | CheckButton* BlendedBox = new CheckButton("Draw OBB Blended"); |
---|
| 359 | BlendedBox->connectSignal("clicked", (void*)BlendedBox, blendedBox); |
---|
| 360 | windowBox->fill(BlendedBox); |
---|
| 361 | |
---|
| 362 | |
---|
[4686] | 363 | CheckButton* DrawModels = new CheckButton("Draw Models"); |
---|
| 364 | DrawModels->connectSignal("clicked", (void*)DrawModels, drawModels); |
---|
| 365 | windowBox->fill(DrawModels); |
---|
| 366 | |
---|
| 367 | |
---|
[4646] | 368 | CheckButton* SeperatingPlanes = new CheckButton("SeperatingPlanes"); |
---|
| 369 | SeperatingPlanes->connectSignal("clicked", (void*)SeperatingPlanes, seperatingPlanes); |
---|
| 370 | windowBox->fill(SeperatingPlanes); |
---|
| 371 | |
---|
[4671] | 372 | |
---|
[4646] | 373 | Slider* TreeDepth = new Slider("TreeDepth", 0, 5); |
---|
| 374 | TreeDepth->connectSignal("value_changed", (void*)TreeDepth, treeDepth); |
---|
| 375 | windowBox->fill(TreeDepth); |
---|
| 376 | } |
---|
| 377 | guiMainWindow->fill(windowBox); |
---|
[4626] | 378 | } |
---|
| 379 | Window::mainWindow->showall(); |
---|
| 380 | Window::mainWindow->setSize(300, 500); |
---|
[4333] | 381 | } |
---|