[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 |
---|
[7841] | 13 | co-programmer: Patrick Boenzli |
---|
[4333] | 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 | |
---|
[8490] | 27 | #include "md2/md2Model.h" |
---|
[4675] | 28 | #include "model.h" |
---|
[5486] | 29 | #include "collision_test_entity.h" |
---|
[7156] | 30 | #include "list.h" |
---|
[4615] | 31 | |
---|
[4646] | 32 | #include "graphics_engine.h" |
---|
[4636] | 33 | |
---|
[7157] | 34 | #include "state.h" |
---|
| 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; |
---|
[4719] | 44 | bool drawModel = false; |
---|
[4679] | 45 | |
---|
[4710] | 46 | WorldEntity* a; |
---|
| 47 | WorldEntity* b; |
---|
| 48 | //Terrain* c; |
---|
[4719] | 49 | bool animateModel = false; |
---|
[4701] | 50 | |
---|
[7711] | 51 | |
---|
| 52 | |
---|
[4343] | 53 | void Framework::moduleInit(int argc, char** argv) |
---|
[4333] | 54 | { |
---|
[4646] | 55 | GraphicsEngine::getInstance()->setWindowName("Collision Cluster", "collision"); |
---|
| 56 | |
---|
[4546] | 57 | CDEngine::getInstance(); |
---|
[4679] | 58 | |
---|
[7157] | 59 | State::setObjectManager(new ObjectManager); |
---|
[4710] | 60 | /* Primitive Data Test */ |
---|
| 61 | // sVec3D* data = new sVec3D[6]; |
---|
| 62 | // float tmp[6][3] = {{0.0, 4.2, 2.4}, {3.0, 3.0, 2.0}, {5.0, 1.0, 6.0}, {6.5, 1.0, 3.0}, {7.0, 3.0, 5.0}, {8.0, 6.0, 6.0}}; |
---|
| 63 | // for(int i = 0; i < 6; ++i) |
---|
| 64 | // { |
---|
| 65 | // data[i][0] = tmp[i][0]; |
---|
| 66 | // data[i][1] = tmp[i][1]; |
---|
| 67 | // data[i][2] = tmp[i][2]; |
---|
| 68 | // } |
---|
| 69 | // CDEngine::getInstance()->debugSpawnTree(5, data, 6); |
---|
[4552] | 70 | |
---|
[4679] | 71 | /* MD2 Model Test */ |
---|
[4675] | 72 | // model = new MD2Model("models/tris.md2", "models/tris.pcx"); |
---|
| 73 | // model->tick(0.1f); |
---|
| 74 | // CDEngine::getInstance()->debugSpawnTree(9, model->data->pVertices, model->data->numVertices); |
---|
[4552] | 75 | |
---|
[4679] | 76 | /* OBJ - Model Test */ |
---|
| 77 | // mod = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN); |
---|
| 78 | // CDEngine::getInstance()->debugSpawnTree(9, (sVec3D*)mod->getVertexArray(), mod->getVertexArrayCount()); |
---|
| 79 | |
---|
[7711] | 80 | entityList = new tList<WorldEntity>(); |
---|
[4679] | 81 | |
---|
[5819] | 82 | if (argc > 1) |
---|
| 83 | { |
---|
| 84 | printf("Loading model %s\n", argv[1]); |
---|
[7711] | 85 | b = new CollisionTestEntity(argv[1]); b->setName("Jaeger"); |
---|
[5819] | 86 | } |
---|
[7711] | 87 | else |
---|
| 88 | { |
---|
| 89 | printf("----------------------- WARNING ---------------------\n\n"); |
---|
| 90 | printf("no path specified, using default model: models/ships/fighter.obj\n\n"); |
---|
| 91 | printf("----------------------- WARNING ---------------------\n"); |
---|
| 92 | b = new CollisionTestEntity("models/test/cd_test_0.obj"); b->setName("Jaeger"); |
---|
| 93 | } |
---|
[4903] | 94 | // b->setRelCoor(0.0, 0.0, -20.0); |
---|
| 95 | // b->setRelDir(Quaternion(-M_PI/2.0f, Vector(0.0, 1.0, 0.0))); |
---|
[7711] | 96 | if(b != NULL) |
---|
| 97 | printf("model successfully loaded\n"); |
---|
| 98 | entityList->add(b); |
---|
[4630] | 99 | |
---|
[7711] | 100 | |
---|
| 101 | // a = new Terrain(); |
---|
| 102 | |
---|
| 103 | |
---|
[4903] | 104 | // entityList->add(b); |
---|
[4630] | 105 | |
---|
[7157] | 106 | //CDEngine::getInstance()->setEntityList(entityList); |
---|
[4675] | 107 | |
---|
[4552] | 108 | LightManager* lightMan = LightManager::getInstance(); |
---|
[4717] | 109 | lightMan->setAmbientColor(.1,.1,.1); |
---|
[4741] | 110 | (new Light())->setAbsCoor(-5.0, 50.0, -40.0); |
---|
| 111 | (new Light())->setAbsCoor(100, 80, 60); |
---|
[4636] | 112 | |
---|
[4710] | 113 | |
---|
[4675] | 114 | /* properties */ |
---|
[4636] | 115 | drawMode = DRAW_MODEL; |
---|
[4673] | 116 | depth = 0; |
---|
[4679] | 117 | dt = lastFrame = currentFrame = 0; |
---|
[4704] | 118 | iterata = 0.05f; |
---|
[4636] | 119 | |
---|
[4647] | 120 | moduleHelp(); |
---|
[4333] | 121 | } |
---|
| 122 | |
---|
[4546] | 123 | |
---|
[4334] | 124 | void Framework::moduleEventHandler(SDL_Event* event) |
---|
| 125 | { |
---|
| 126 | switch (event->type) |
---|
[4622] | 127 | { |
---|
[4334] | 128 | case SDL_KEYDOWN: |
---|
| 129 | switch (event->key.keysym.sym) |
---|
[4622] | 130 | { |
---|
[4636] | 131 | case SDLK_a: |
---|
| 132 | drawMode |= DRAW_ALL; |
---|
[4615] | 133 | break; |
---|
[4638] | 134 | case SDLK_0: |
---|
| 135 | { |
---|
| 136 | printf("Setting tree depth = 0\n"); |
---|
| 137 | depth = 0; |
---|
| 138 | int temp = drawMode & DRAW_ALL; |
---|
| 139 | drawMode ^= temp; |
---|
| 140 | drawMode |= DRAW_SINGLE; |
---|
| 141 | break; |
---|
| 142 | } |
---|
[4622] | 143 | case SDLK_1: |
---|
[4636] | 144 | { |
---|
| 145 | printf("Setting tree depth = 1\n"); |
---|
| 146 | depth = 1; |
---|
| 147 | int temp = drawMode & DRAW_ALL; |
---|
| 148 | drawMode ^= temp; |
---|
| 149 | drawMode |= DRAW_SINGLE; |
---|
[4622] | 150 | break; |
---|
[4636] | 151 | } |
---|
| 152 | case SDLK_2: |
---|
| 153 | { |
---|
| 154 | printf("Setting tree depth = 2\n"); |
---|
| 155 | depth = 2; |
---|
| 156 | int temp = drawMode & DRAW_ALL; |
---|
| 157 | drawMode ^= temp; |
---|
| 158 | drawMode |= DRAW_SINGLE; |
---|
| 159 | break; |
---|
| 160 | } |
---|
| 161 | case SDLK_3: |
---|
| 162 | { |
---|
| 163 | printf("Setting tree depth = 3\n"); |
---|
| 164 | depth = 3; |
---|
| 165 | int temp = drawMode & DRAW_ALL; |
---|
| 166 | drawMode ^= temp; |
---|
| 167 | drawMode |= DRAW_SINGLE; |
---|
| 168 | break; |
---|
| 169 | } |
---|
| 170 | case SDLK_4: |
---|
| 171 | { |
---|
| 172 | printf("Setting tree depth = 4\n"); |
---|
| 173 | depth = 4; |
---|
| 174 | int temp = drawMode & DRAW_ALL; |
---|
| 175 | drawMode ^= temp; |
---|
| 176 | drawMode |= DRAW_SINGLE; |
---|
| 177 | break; |
---|
| 178 | } |
---|
| 179 | case SDLK_5: |
---|
| 180 | { |
---|
| 181 | printf("Setting tree depth = 5\n"); |
---|
| 182 | depth = 5; |
---|
| 183 | int temp = drawMode & DRAW_ALL; |
---|
| 184 | drawMode ^= temp; |
---|
| 185 | drawMode |= DRAW_SINGLE; |
---|
| 186 | break; |
---|
| 187 | } |
---|
| 188 | case SDLK_6: |
---|
| 189 | { |
---|
| 190 | printf("Setting tree depth = 6\n"); |
---|
| 191 | depth = 6; |
---|
| 192 | int temp = drawMode & DRAW_ALL; |
---|
| 193 | drawMode ^= temp; |
---|
| 194 | drawMode |= DRAW_SINGLE; |
---|
| 195 | break; |
---|
| 196 | } |
---|
| 197 | case SDLK_s: |
---|
| 198 | if(drawMode & DRAW_SEPARATING_PLANE) |
---|
| 199 | { |
---|
| 200 | int temp = drawMode & DRAW_SEPARATING_PLANE; |
---|
| 201 | drawMode ^= temp; |
---|
| 202 | printf("Removing Separation Plane\n"); |
---|
| 203 | } |
---|
| 204 | else |
---|
| 205 | { |
---|
| 206 | drawMode |= DRAW_SEPARATING_PLANE; |
---|
| 207 | printf("Drawing Separation Plane\n"); |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | break; |
---|
| 211 | case SDLK_p: |
---|
| 212 | if(drawMode & DRAW_BV_POLYGON) |
---|
| 213 | { |
---|
| 214 | int temp = drawMode & DRAW_BV_POLYGON; |
---|
| 215 | drawMode ^= temp; |
---|
| 216 | printf("Removing OBB Polygons\n"); |
---|
| 217 | } |
---|
| 218 | else |
---|
| 219 | { |
---|
| 220 | drawMode |= DRAW_BV_POLYGON; |
---|
| 221 | printf("Drawing OBB Polygons\n"); |
---|
| 222 | } |
---|
| 223 | break; |
---|
[4704] | 224 | case SDLK_o: |
---|
| 225 | if(iterata == 0.0f) |
---|
| 226 | { |
---|
| 227 | iterata = 0.05f; |
---|
| 228 | } |
---|
| 229 | else |
---|
| 230 | { |
---|
| 231 | iterata = 0.0f; |
---|
| 232 | } |
---|
| 233 | break; |
---|
[4636] | 234 | |
---|
[4622] | 235 | } |
---|
| 236 | } |
---|
[4333] | 237 | } |
---|
| 238 | |
---|
[4546] | 239 | |
---|
[4333] | 240 | void Framework::moduleTick(float dt) |
---|
| 241 | { |
---|
[4679] | 242 | |
---|
[7157] | 243 | //CDEngine::getInstance()->checkCollisions(); |
---|
[4688] | 244 | |
---|
[4679] | 245 | |
---|
[5033] | 246 | // b->shiftCoor(Vector(0.0, 0.0, iterata * dt * 12.0f)); |
---|
[4679] | 247 | |
---|
[4701] | 248 | |
---|
[4708] | 249 | tIterator<WorldEntity>* iterator = entityList->getIterator(); |
---|
[5115] | 250 | WorldEntity* entity = iterator->firstElement(); |
---|
[4708] | 251 | while( entity != NULL) |
---|
[4675] | 252 | { |
---|
[4721] | 253 | if( unlikely(animateModel)) |
---|
[4719] | 254 | entity->tick(dt); |
---|
[4708] | 255 | entity = iterator->nextElement(); |
---|
[4675] | 256 | } |
---|
| 257 | delete iterator; |
---|
[4333] | 258 | } |
---|
| 259 | |
---|
[4546] | 260 | |
---|
[4349] | 261 | void Framework::moduleDraw() const |
---|
[4334] | 262 | { |
---|
[4718] | 263 | //CDEngine::getInstance()->debugDraw(depth, drawMode); |
---|
[4710] | 264 | |
---|
[4708] | 265 | tIterator<WorldEntity>* iterator = entityList->getIterator(); |
---|
[5115] | 266 | WorldEntity* entity = iterator->firstElement(); |
---|
[4708] | 267 | while( entity != NULL) |
---|
[4679] | 268 | { |
---|
[4707] | 269 | if( likely(drawModel)) |
---|
[5482] | 270 | entity->draw(); |
---|
[4707] | 271 | entity->drawBVTree(depth, drawMode); |
---|
[7711] | 272 | // printf("%i, %i\n", depth, drawMode); |
---|
[4708] | 273 | entity = iterator->nextElement(); |
---|
[4679] | 274 | } |
---|
| 275 | delete iterator; |
---|
[4707] | 276 | |
---|
| 277 | LightManager::getInstance()->draw(); |
---|
[4334] | 278 | } |
---|
[4333] | 279 | |
---|
[4334] | 280 | |
---|
[4333] | 281 | void Framework::moduleHelp(void) const |
---|
| 282 | { |
---|
[4647] | 283 | printf("\n\n==========================="); |
---|
| 284 | printf("Collision Detection Modler:\n"); |
---|
| 285 | printf("Key Bindings:\n"); |
---|
| 286 | printf(" -| Displaying Polygons\t\t p\n"); |
---|
| 287 | printf(" -| Displaying Separation Plane\t s\n"); |
---|
| 288 | printf("\n"); |
---|
| 289 | printf(" -| Tree Depth 0\t\t 0\n"); |
---|
| 290 | printf(" -| Tree Depth 1\t\t 1\n"); |
---|
| 291 | printf(" -| Tree Depth 2\t\t 2\n"); |
---|
| 292 | printf(" -| Tree Depth 3\t\t 3\n"); |
---|
| 293 | printf(" -| Tree Depth 4\t\t 4\n"); |
---|
| 294 | printf(" -| Tree Depth 5\t\t 5\n"); |
---|
| 295 | printf("===========================\n\n"); |
---|
| 296 | |
---|
[4333] | 297 | } |
---|
| 298 | |
---|
[4646] | 299 | int boxPolygons(GtkWidget* nonInterest, void* widget) |
---|
| 300 | { |
---|
| 301 | if(drawMode & DRAW_BV_POLYGON) |
---|
| 302 | { |
---|
| 303 | int temp = drawMode & DRAW_BV_POLYGON; |
---|
| 304 | drawMode ^= temp; |
---|
| 305 | printf("Removing OBB Polygons\n"); |
---|
| 306 | } |
---|
| 307 | else |
---|
| 308 | { |
---|
| 309 | drawMode |= DRAW_BV_POLYGON; |
---|
| 310 | printf("Drawing OBB Polygons\n"); |
---|
| 311 | } |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | int seperatingPlanes(GtkWidget* nonInterest, void* widget) |
---|
| 315 | { |
---|
| 316 | if(drawMode & DRAW_SEPARATING_PLANE) |
---|
| 317 | { |
---|
| 318 | int temp = drawMode & DRAW_SEPARATING_PLANE; |
---|
| 319 | drawMode ^= temp; |
---|
| 320 | printf("Removing Separation Plane\n"); |
---|
| 321 | } |
---|
| 322 | else |
---|
| 323 | { |
---|
| 324 | drawMode |= DRAW_SEPARATING_PLANE; |
---|
| 325 | printf("Drawing Separation Plane\n"); |
---|
| 326 | } |
---|
| 327 | } |
---|
| 328 | |
---|
[4671] | 329 | |
---|
| 330 | int blendedBox(GtkWidget* nonInterest, void* widget) |
---|
| 331 | { |
---|
| 332 | if(drawMode & DRAW_BV_BLENDED) |
---|
| 333 | { |
---|
| 334 | int temp = drawMode & DRAW_BV_BLENDED; |
---|
| 335 | drawMode ^= temp; |
---|
| 336 | printf("Removing OBB Polygons\n"); |
---|
| 337 | } |
---|
| 338 | else |
---|
| 339 | { |
---|
| 340 | drawMode |= DRAW_BV_BLENDED; |
---|
| 341 | printf("Drawing OBB Polygons\n"); |
---|
| 342 | } |
---|
| 343 | } |
---|
| 344 | |
---|
| 345 | |
---|
[4686] | 346 | int drawModels(GtkWidget* nonInterest, void* widget) |
---|
| 347 | { |
---|
| 348 | drawModel = !drawModel; |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | |
---|
[4719] | 352 | int animateModels(GtkWidget* nonInterest, void* widget) |
---|
| 353 | { |
---|
| 354 | animateModel = !animateModel; |
---|
| 355 | } |
---|
| 356 | |
---|
| 357 | |
---|
[4712] | 358 | int drawPoints(GtkWidget* nonInterest, void* widget) |
---|
| 359 | { |
---|
| 360 | if(drawMode & DRAW_POINTS) |
---|
| 361 | { |
---|
| 362 | int temp = drawMode & DRAW_POINTS; |
---|
| 363 | drawMode ^= temp; |
---|
| 364 | |
---|
| 365 | } |
---|
| 366 | else |
---|
| 367 | { |
---|
| 368 | drawMode |= DRAW_POINTS; |
---|
| 369 | printf("Drawing OBB Polygons\n"); |
---|
| 370 | } |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | |
---|
[4646] | 374 | int treeDepth(GtkWidget* nonInterest, void* widget) |
---|
| 375 | { |
---|
| 376 | Option* option = (Option*) widget; |
---|
| 377 | const char* name = option->getTitle(); |
---|
| 378 | char* value = option->save(); |
---|
| 379 | |
---|
| 380 | depth = atoi(value); |
---|
| 381 | printf("Setting tree depth = %i\n", depth); |
---|
| 382 | int temp = drawMode & DRAW_ALL; |
---|
| 383 | drawMode ^= temp; |
---|
| 384 | drawMode |= DRAW_SINGLE; |
---|
| 385 | |
---|
| 386 | delete value; |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | |
---|
[4343] | 390 | void Framework::moduleInitGui(int argc, char** argv) |
---|
[4333] | 391 | { |
---|
[4626] | 392 | Window* guiMainWindow = NULL; |
---|
| 393 | |
---|
| 394 | initGUI(0, NULL); |
---|
| 395 | |
---|
| 396 | guiMainWindow = new Window("Collision_detection"); |
---|
| 397 | { |
---|
[4646] | 398 | Box* windowBox = new Box('v'); |
---|
| 399 | { |
---|
[4671] | 400 | CheckButton* BoxPolygons = new CheckButton("Draw OBB Polygons"); |
---|
[4646] | 401 | BoxPolygons->connectSignal("clicked", (void*)BoxPolygons, boxPolygons); |
---|
| 402 | windowBox->fill(BoxPolygons); |
---|
| 403 | |
---|
| 404 | |
---|
[4671] | 405 | CheckButton* BlendedBox = new CheckButton("Draw OBB Blended"); |
---|
| 406 | BlendedBox->connectSignal("clicked", (void*)BlendedBox, blendedBox); |
---|
| 407 | windowBox->fill(BlendedBox); |
---|
| 408 | |
---|
| 409 | |
---|
[4686] | 410 | CheckButton* DrawModels = new CheckButton("Draw Models"); |
---|
| 411 | DrawModels->connectSignal("clicked", (void*)DrawModels, drawModels); |
---|
| 412 | windowBox->fill(DrawModels); |
---|
| 413 | |
---|
| 414 | |
---|
[4719] | 415 | |
---|
| 416 | CheckButton* AnimateModels = new CheckButton("Animate Models"); |
---|
| 417 | AnimateModels->connectSignal("clicked", (void*)AnimateModels, animateModels); |
---|
| 418 | windowBox->fill(AnimateModels); |
---|
| 419 | |
---|
| 420 | |
---|
[4712] | 421 | CheckButton* DrawPoints = new CheckButton("Draw Points"); |
---|
| 422 | DrawPoints->connectSignal("clicked", (void*)DrawPoints, drawPoints); |
---|
| 423 | windowBox->fill(DrawPoints); |
---|
| 424 | |
---|
| 425 | |
---|
[4646] | 426 | CheckButton* SeperatingPlanes = new CheckButton("SeperatingPlanes"); |
---|
| 427 | SeperatingPlanes->connectSignal("clicked", (void*)SeperatingPlanes, seperatingPlanes); |
---|
| 428 | windowBox->fill(SeperatingPlanes); |
---|
| 429 | |
---|
[4671] | 430 | |
---|
[4712] | 431 | Slider* TreeDepth = new Slider("TreeDepth", 0, 17); |
---|
[4646] | 432 | TreeDepth->connectSignal("value_changed", (void*)TreeDepth, treeDepth); |
---|
| 433 | windowBox->fill(TreeDepth); |
---|
| 434 | } |
---|
| 435 | guiMainWindow->fill(windowBox); |
---|
[4626] | 436 | } |
---|
| 437 | Window::mainWindow->showall(); |
---|
| 438 | Window::mainWindow->setSize(300, 500); |
---|
[4333] | 439 | } |
---|