| 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: Patrick Boenzli |
|---|
| 13 | co-programmer: ... |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION |
|---|
| 17 | |
|---|
| 18 | #include "cd_engine.h" |
|---|
| 19 | #include "obb_tree.h" |
|---|
| 20 | #include "debug.h" |
|---|
| 21 | #include "abstract_model.h" |
|---|
| 22 | #include "world_entity.h" |
|---|
| 23 | #include "list.h" |
|---|
| 24 | |
|---|
| 25 | using namespace std; |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | /** |
|---|
| 29 | \brief standard constructor |
|---|
| 30 | */ |
|---|
| 31 | CDEngine::CDEngine () |
|---|
| 32 | { |
|---|
| 33 | this->setClassName("CDEngine"); |
|---|
| 34 | this->setClassID(CL_CD_ENGINE, "CDEngine"); |
|---|
| 35 | |
|---|
| 36 | /* testing purposes only: */ |
|---|
| 37 | //this->rootTree = new OBBTree(); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | /** |
|---|
| 41 | \brief the singleton reference to this class |
|---|
| 42 | */ |
|---|
| 43 | CDEngine* CDEngine::singletonRef = NULL; |
|---|
| 44 | |
|---|
| 45 | /** |
|---|
| 46 | \brief standard deconstructor |
|---|
| 47 | |
|---|
| 48 | */ |
|---|
| 49 | CDEngine::~CDEngine () |
|---|
| 50 | { |
|---|
| 51 | CDEngine::singletonRef = NULL; |
|---|
| 52 | |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | void CDEngine::checkCollisions() |
|---|
| 57 | { |
|---|
| 58 | tIterator<WorldEntity>* iterator1 = entityList->getIterator(); |
|---|
| 59 | tIterator<WorldEntity>* iterator2 = entityList->getIterator(); |
|---|
| 60 | WorldEntity* entity1 = iterator1->nextElement(); |
|---|
| 61 | WorldEntity* entity2 = iterator2->nextElement(); |
|---|
| 62 | while( entity1 != NULL) |
|---|
| 63 | { |
|---|
| 64 | while( entity2 != NULL && entity1 != entity2) |
|---|
| 65 | { |
|---|
| 66 | entity1->collideWith(entity2); |
|---|
| 67 | entity2 = iterator2->nextElement(); |
|---|
| 68 | } |
|---|
| 69 | entity1 = iterator1->nextElement(); |
|---|
| 70 | } |
|---|
| 71 | delete iterator1; |
|---|
| 72 | delete iterator2; |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | void CDEngine::checkCollisionObjects() |
|---|
| 80 | {} |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | void CDEngine::checkCollisionGround() |
|---|
| 84 | {} |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | void CDEngine::drawBV(int depth, int drawMode) const |
|---|
| 88 | { |
|---|
| 89 | /* this would operate on worldList bases, for testing purposes, we only use one OBBTree */ |
|---|
| 90 | //this->rootTree->drawBV(depth, drawMode); |
|---|
| 91 | |
|---|
| 92 | tIterator<WorldEntity>* iterator = entityList->getIterator(); |
|---|
| 93 | WorldEntity* entity = iterator->nextElement(); |
|---|
| 94 | while( entity != NULL) |
|---|
| 95 | { |
|---|
| 96 | entity->drawBVTree(depth, drawMode); |
|---|
| 97 | entity = iterator->nextElement(); |
|---|
| 98 | } |
|---|
| 99 | delete iterator; |
|---|
| 100 | //model->draw(); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | void CDEngine::debug() |
|---|
| 108 | { |
|---|
| 109 | PRINT(0)("\n=============================| CDEngine::debug() |===\n"); |
|---|
| 110 | PRINT(0)("= CDEngine: Spawning Tree Start\n"); |
|---|
| 111 | //this->rootTree->debug(); |
|---|
| 112 | PRINT(0)("= CDEngine: Spawning Tree: Finished\n"); |
|---|
| 113 | PRINT(0)("=======================================================\n"); |
|---|
| 114 | |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices) |
|---|
| 118 | { |
|---|
| 119 | if ( this->rootTree == NULL) |
|---|
| 120 | this->rootTree = new OBBTree(); |
|---|
| 121 | this->rootTree->spawnBVTree(depth, vertices, numVertices); |
|---|
| 122 | } |
|---|