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