Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/ODE/src/lib/collision_detection/cd_engine.cc

Last change on this file was 10355, checked in by bottac, 18 years ago

Here comes the updated version.

File size: 4.3 KB
Line 
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#include "bsp/bsp_manager.h"
32#include "bsp_entity.h"
33
34
35
36ObjectListDefinition(CDEngine);
37/**
38 * @brief standard constructor
39 */
40CDEngine::CDEngine ()
41{
42  this->registerObject(this, CDEngine::_objectList);
43
44  this->bAbordOnFirstCollision = false;
45
46  this->terrain = NULL;
47}
48
49
50/**
51 *  the singleton reference to this class
52 */
53CDEngine* CDEngine::singletonRef = NULL;
54
55
56/**
57 *  standard deconstructor
58 */
59CDEngine::~CDEngine ()
60{
61  CDEngine::singletonRef = NULL;
62}
63
64
65/**
66 *
67 */
68void CDEngine::checkCollisions(ObjectManager::EntityList& list1, ObjectManager::EntityList& list2)
69{
70
71
72  BVTree* tree;
73  ObjectManager::EntityList::iterator entity1, entity2, pre1, pre2;
74  PRINTF(5)("checking for collisions\n");
75
76  pre1 = list1.begin();
77  while (pre1 != list1.end())
78  {
79    entity1 = pre1++;
80    if( likely((*entity1) != this->terrain))
81    {
82      pre2 = list2.begin();
83      while (pre2 != list2.end())
84      {
85        entity2 = pre2++;
86        if( likely((*entity2) != this->terrain))
87        {
88         
89          PRINTF(5)("checking object %s (%s) against %s (%s)\n",
90           (*entity1)->getClassCName(), (*entity1)->getCName(), (*entity2)->getClassCName(), (*entity2)->getCName());
91          #ifndef WITH_ODE
92          tree = (*entity1)->getOBBTree();
93          if( likely(tree != NULL) && (*entity2)->getOBBTree() != NULL)
94          tree->collideWith(*entity1, *entity2);
95          #endif
96                (*entity1)->checkCollision(*entity2);
97       
98         
99        }
100      }
101    }
102  }
103}
104
105
106/**
107 *  this checks the collisions with the ground
108 */
109void CDEngine::checkCollisionGround(std::list<WorldEntity*>& list1)
110{
111  std::list<WorldEntity*>::iterator entityIterator;
112       
113for( ObjectList<Terrain>::const_iterator bspIterator = Terrain::objectList().begin();
114       bspIterator != Terrain::objectList().end();
115       bspIterator++) {
116   for(entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++)
117      {
118                PRINTF(5)("Checking %s against: %s\n", ((dynamic_cast<Terrain*>(*bspIterator)))->getCName(),    (*entityIterator)->getClassCName());
119        (dynamic_cast<Terrain*>(*bspIterator))->checkCollision(*entityIterator);
120      }
121 }
122       
123  // for all bsp managers check all entities
124  for( ObjectList<BspEntity>::const_iterator bspIterator = BspEntity::objectList().begin();
125       bspIterator != BspEntity::objectList().end();
126       bspIterator++) {
127      for(entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++)
128      {
129       //  PRINTF(0)("Checking: %s a %s\n", (*entityIterator)->getCName(), (*entityIterator)->getClassCName());
130        (dynamic_cast<BspEntity*>(*bspIterator)->getBspManager())->checkCollision(*entityIterator);
131      }
132   
133  }
134 
135}
136
137
138/**
139 * some debug output on the class
140 */
141void CDEngine::debug()
142{
143  PRINT(0)("\n=============================| CDEngine::debug() |===\n");
144  PRINT(0)("=  CDEngine: Spawning Tree Start\n");
145  //this->rootTree->debug();
146  PRINT(0)("=  CDEngine: Spawning Tree: Finished\n");
147  PRINT(0)("=======================================================\n");
148}
149
150
151/**
152 * this spawns a tree for debug purposes only
153 */
154void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
155{
156//   if ( this->rootTree == NULL)
157//     this->rootTree = new OBBTree(depth, vertices, numVertices);
158}
159
160
161void CDEngine::drawBV(const ObjectManager::EntityList& drawList, int level) const
162{
163  ObjectManager::EntityList::const_iterator entity;
164  for (entity = drawList.begin(); entity != drawList.end(); entity++)
165    (*entity)->drawBVTree(level, 226);
166}
167
168
169/**
170 * this draws the debug spawn tree
171 */
172void CDEngine::debugDraw(int depth, int drawMode)
173{
174//   if(this-> rootTree != NULL)
175//     this->rootTree->drawBV(depth, drawMode);
176}
Note: See TracBrowser for help on using the repository browser.