Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/objectmanager/src/lib/collision_detection/cd_engine.cc @ 6124

Last change on this file since 6124 was 6124, checked in by bensch, 18 years ago

orxonox/trunk: new Collision-detection algorithm, checking for framerate-increase now

File size: 4.9 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
17
18#include "cd_engine.h"
19#include "obb_tree.h"
20#include "debug.h"
21#include "list.h"
22
23#include "model.h"
24#include "world_entity.h"
25#include "terrain.h"
26// #include "player.h"
27
28#include "spatial_separation.h"
29#include "quadtree.h"
30#include "quadtree_node.h"
31
32
33
34using namespace std;
35
36
37/**
38 *  standard constructor
39 */
40CDEngine::CDEngine ()
41{
42  this->setClassID(CL_CD_ENGINE, "CDEngine");
43}
44
45
46/**
47 *  the singleton reference to this class
48 */
49CDEngine* CDEngine::singletonRef = NULL;
50
51
52/**
53 *  standard deconstructor
54 */
55CDEngine::~CDEngine ()
56{
57  CDEngine::singletonRef = NULL;
58}
59
60
61/**
62 *  this is the collision checking function
63
64    there are some speed improvements that can be done here. a rewrite of the list a would be appropriate to
65    be able to enhance iteration speed.
66 */
67//void CDEngine::checkCollisions()
68//{
69//  this->checkCollisionObjects();
70  //this->checkCollisionGround();
71//}
72
73/**
74 *  this checks the collisions with the objects
75 */
76//void CDEngine::checkCollisionObjects()
77//{
78//   BVTree* tree;
79//   tIterator<WorldEntity>* iterator1 = entityList->getIterator();
80//   tIterator<WorldEntity>* iterator2 = entityList->getIterator();
81//   WorldEntity* entity1 = iterator1->firstElement();
82//   WorldEntity* entity2 = iterator2->iteratorElement(iterator1);
83//   PRINTF(3)("checking for collisions\n");
84//   while( entity1 != NULL)
85//   {
86//     if( likely(entity1 != this->terrain))
87//     {
88//       entity2 = iterator2->nextElement();
89//
90//       while( entity2 != NULL)
91//       {
92//         if( likely(entity2 != this->terrain))
93//         {
94//           PRINTF(4)("checking object %s against %s\n", entity1->getName(), entity2->getName());
95//           tree = entity1->getOBBTree();
96//           if( likely(tree != NULL) && entity2->getOBBTree() != NULL) tree->collideWith(entity1, entity2);
97//         }
98//         entity2 = iterator2->nextElement();
99//       }
100//     }
101//     entity1 = iterator1->nextElement();
102//     entity2 = iterator2->iteratorElement(iterator1);
103//     entity2 = iterator2->nextElement();
104//   }
105//   delete iterator1;
106//   delete iterator2;
107//}
108
109void CDEngine::checkCollisions(std::list<WorldEntity*>& list1, std::list<WorldEntity*>& list2)
110{
111  BVTree* tree;
112  std::list<WorldEntity*>::iterator entity1, entity2;
113  PRINTF(3)("checking for collisions\n");
114  for (entity1 = list1.begin(); entity1 != list1.end(); entity1++)
115  {
116    if( likely((*entity1) != this->terrain))
117    {
118      for (entity2 = list2.begin(); entity2 != list2.end(); entity2++)
119      {
120        if( likely((*entity2) != this->terrain))
121        {
122          PRINTF(4)("checking object %s against %s\n", (*entity1)->getName(), (*entity2)->getName());
123          tree = (*entity1)->getOBBTree();
124          if( likely(tree != NULL) && (*entity2)->getOBBTree() != NULL) tree->collideWith(*entity1, *entity2);
125        }
126      }
127    }
128  }
129}
130
131
132/**
133 *  this checks the collisions with the ground
134 */
135void CDEngine::checkCollisionGround()
136{
137  if( likely( this->terrain != NULL))
138  {
139    Quadtree* q = this->terrain->ssp->getQuadtree();
140
141//    QuadtreeNode* n = q->getQuadtreeFromPosition(this->player->getAbsCoor());
142  }
143  //sTriangleExt* tri = q->getTriangleFromPosition(this->player->getAbsCoor());
144}
145
146
147/**
148 *  this draws the bounding volume tree
149 * @param depth until which depth to draw the tree
150 * @param drawMode mod which states how to draw it
151 */
152void CDEngine::drawBV(int depth, int drawMode) const
153{
154  /* this would operate on  worldList bases, for testing purposes, we only use one OBBTree */
155  //this->rootTree->drawBV(depth, drawMode);
156  /// FIXME
157/*  tIterator<WorldEntity>* iterator = entityList->getIterator();
158  WorldEntity* entity = iterator->firstElement();
159  while( entity != NULL)
160  {
161    entity->drawBVTree(depth, drawMode);
162    entity = iterator->nextElement();
163  }
164  delete iterator;*/
165}
166
167
168/**
169 * some debug output on the class
170 */
171void CDEngine::debug()
172{
173  PRINT(0)("\n=============================| CDEngine::debug() |===\n");
174  PRINT(0)("=  CDEngine: Spawning Tree Start\n");
175  //this->rootTree->debug();
176  PRINT(0)("=  CDEngine: Spawning Tree: Finished\n");
177  PRINT(0)("=======================================================\n");
178
179}
180
181
182/**
183 * this spawns a tree for debug purposes only
184 */
185void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
186{
187  if ( this->rootTree == NULL)
188    this->rootTree = new OBBTree();
189  this->rootTree->spawnBVTree(depth, vertices, numVertices);
190}
191
192
193/**
194 * this draws the debug spawn tree
195 */
196void CDEngine::debugDraw(int depth, int drawMode)
197{
198  if(this-> rootTree != NULL)
199    this->rootTree->drawBV(depth, drawMode);
200}
Note: See TracBrowser for help on using the repository browser.