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