[4615] | 1 | /* |
---|
[4510] | 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 | |
---|
[4923] | 11 | ### File Specific: |
---|
[4511] | 12 | main-programmer: Patrick Boenzli |
---|
[4510] | 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
[7365] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION |
---|
[4510] | 17 | |
---|
[4511] | 18 | #include "cd_engine.h" |
---|
[4546] | 19 | #include "obb_tree.h" |
---|
| 20 | #include "debug.h" |
---|
[4510] | 21 | |
---|
[6022] | 22 | #include "model.h" |
---|
[4919] | 23 | #include "world_entity.h" |
---|
| 24 | #include "terrain.h" |
---|
[5915] | 25 | // #include "player.h" |
---|
[4919] | 26 | |
---|
| 27 | #include "spatial_separation.h" |
---|
| 28 | #include "quadtree.h" |
---|
| 29 | #include "quadtree_node.h" |
---|
| 30 | |
---|
| 31 | |
---|
[5042] | 32 | |
---|
[4510] | 33 | using namespace std; |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | /** |
---|
[4836] | 37 | * standard constructor |
---|
[4923] | 38 | */ |
---|
[4615] | 39 | CDEngine::CDEngine () |
---|
[4510] | 40 | { |
---|
[4923] | 41 | this->setClassID(CL_CD_ENGINE, "CDEngine"); |
---|
[4510] | 42 | } |
---|
| 43 | |
---|
[4923] | 44 | |
---|
[4510] | 45 | /** |
---|
[4836] | 46 | * the singleton reference to this class |
---|
[4923] | 47 | */ |
---|
[4511] | 48 | CDEngine* CDEngine::singletonRef = NULL; |
---|
[4510] | 49 | |
---|
[4923] | 50 | |
---|
[4510] | 51 | /** |
---|
[4836] | 52 | * standard deconstructor |
---|
[4923] | 53 | */ |
---|
[4615] | 54 | CDEngine::~CDEngine () |
---|
[4510] | 55 | { |
---|
[4511] | 56 | CDEngine::singletonRef = NULL; |
---|
[4510] | 57 | } |
---|
[4546] | 58 | |
---|
| 59 | |
---|
[4695] | 60 | /** |
---|
[7365] | 61 | * |
---|
[4695] | 62 | */ |
---|
[6142] | 63 | void CDEngine::checkCollisions(std::list<WorldEntity*>& list1, std::list<WorldEntity*>& list2) |
---|
[4904] | 64 | { |
---|
[5027] | 65 | BVTree* tree; |
---|
[6142] | 66 | std::list<WorldEntity*>::iterator entity1, entity2, pre1, pre2; |
---|
[7365] | 67 | PRINTF(5)("checking for collisions\n"); |
---|
[6142] | 68 | |
---|
| 69 | pre1 = list1.begin(); |
---|
| 70 | while (pre1 != list1.end()) |
---|
[4689] | 71 | { |
---|
[6142] | 72 | entity1 = pre1++; |
---|
| 73 | if( likely((*entity1) != this->terrain)) |
---|
[4689] | 74 | { |
---|
[6142] | 75 | pre2 = list2.begin(); |
---|
| 76 | while (pre2 != list2.end()) |
---|
[5038] | 77 | { |
---|
[6142] | 78 | entity2 = pre2++; |
---|
| 79 | if( likely((*entity2) != this->terrain)) |
---|
[5038] | 80 | { |
---|
[6142] | 81 | PRINTF(4)("checking object %s against %s\n", (*entity1)->getName(), (*entity2)->getName()); |
---|
| 82 | tree = (*entity1)->getOBBTree(); |
---|
[7365] | 83 | if( likely(tree != NULL) && (*entity2)->getOBBTree() != NULL) |
---|
| 84 | tree->collideWith(*entity1, *entity2); |
---|
[5131] | 85 | } |
---|
[5038] | 86 | } |
---|
[4689] | 87 | } |
---|
[5111] | 88 | } |
---|
[4675] | 89 | } |
---|
| 90 | |
---|
| 91 | |
---|
[4924] | 92 | /** |
---|
| 93 | * this checks the collisions with the ground |
---|
| 94 | */ |
---|
[4904] | 95 | void CDEngine::checkCollisionGround() |
---|
| 96 | { |
---|
[5033] | 97 | if( likely( this->terrain != NULL)) |
---|
| 98 | { |
---|
[6151] | 99 | Quadtree* q = dynamic_cast<Terrain*>(this->terrain)->ssp->getQuadtree(); |
---|
[4968] | 100 | |
---|
[5915] | 101 | // QuadtreeNode* n = q->getQuadtreeFromPosition(this->player->getAbsCoor()); |
---|
[5033] | 102 | } |
---|
[4968] | 103 | //sTriangleExt* tri = q->getTriangleFromPosition(this->player->getAbsCoor()); |
---|
[4904] | 104 | } |
---|
[4688] | 105 | |
---|
| 106 | |
---|
[4924] | 107 | /** |
---|
| 108 | * some debug output on the class |
---|
| 109 | */ |
---|
[4546] | 110 | void CDEngine::debug() |
---|
| 111 | { |
---|
| 112 | PRINT(0)("\n=============================| CDEngine::debug() |===\n"); |
---|
| 113 | PRINT(0)("= CDEngine: Spawning Tree Start\n"); |
---|
[4689] | 114 | //this->rootTree->debug(); |
---|
[4546] | 115 | PRINT(0)("= CDEngine: Spawning Tree: Finished\n"); |
---|
[4615] | 116 | PRINT(0)("=======================================================\n"); |
---|
[4546] | 117 | |
---|
| 118 | } |
---|
[4615] | 119 | |
---|
[4924] | 120 | |
---|
| 121 | /** |
---|
| 122 | * this spawns a tree for debug purposes only |
---|
| 123 | */ |
---|
[4615] | 124 | void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices) |
---|
| 125 | { |
---|
[7365] | 126 | // if ( this->rootTree == NULL) |
---|
| 127 | // this->rootTree = new OBBTree(depth, vertices, numVertices); |
---|
[4615] | 128 | } |
---|
[4710] | 129 | |
---|
[4924] | 130 | |
---|
[6316] | 131 | void CDEngine::drawBV(const std::list<WorldEntity*>& drawList ) const |
---|
| 132 | { |
---|
| 133 | std::list<WorldEntity*>::const_iterator entity; |
---|
| 134 | for (entity = drawList.begin(); entity != drawList.end(); entity++) |
---|
[7365] | 135 | (*entity)->drawBVTree(3, 226); |
---|
[6316] | 136 | } |
---|
| 137 | |
---|
[4924] | 138 | /** |
---|
| 139 | * this draws the debug spawn tree |
---|
| 140 | */ |
---|
[4710] | 141 | void CDEngine::debugDraw(int depth, int drawMode) |
---|
| 142 | { |
---|
[7365] | 143 | // if(this-> rootTree != NULL) |
---|
| 144 | // this->rootTree->drawBV(depth, drawMode); |
---|
[4710] | 145 | } |
---|