Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/collision_detection/cd_engine.cc @ 7309

Last change on this file since 7309 was 6316, checked in by bensch, 19 years ago

orxonox/trunk: now painting the BV's again…. no error due to my change in the static model…. puh :)

File size: 5.2 KB
RevLine 
[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
[4511]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
[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]33using namespace std;
34
35
36/**
[4836]37 *  standard constructor
[4923]38 */
[4615]39CDEngine::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]48CDEngine* CDEngine::singletonRef = NULL;
[4510]49
[4923]50
[4510]51/**
[4836]52 *  standard deconstructor
[4923]53 */
[4615]54CDEngine::~CDEngine ()
[4510]55{
[4511]56  CDEngine::singletonRef = NULL;
[4510]57}
[4546]58
59
[4695]60/**
[4923]61 *  this is the collision checking function
[4695]62
[4923]63    there are some speed improvements that can be done here. a rewrite of the list a would be appropriate to
64    be able to enhance iteration speed.
[4695]65 */
[6142]66//void CDEngine::checkCollisions()
67//{
68//  this->checkCollisionObjects();
[5047]69  //this->checkCollisionGround();
[6142]70//}
[4904]71
[4924]72/**
73 *  this checks the collisions with the objects
74 */
[6142]75//void CDEngine::checkCollisionObjects()
76//{
77//   BVTree* tree;
78//   tIterator<WorldEntity>* iterator1 = entityList->getIterator();
79//   tIterator<WorldEntity>* iterator2 = entityList->getIterator();
80//   WorldEntity* entity1 = iterator1->firstElement();
81//   WorldEntity* entity2 = iterator2->iteratorElement(iterator1);
82//   PRINTF(3)("checking for collisions\n");
83//   while( entity1 != NULL)
84//   {
85//     if( likely(entity1 != this->terrain))
86//     {
87//       entity2 = iterator2->nextElement();
88//
89//       while( entity2 != NULL)
90//       {
91//         if( likely(entity2 != this->terrain))
92//         {
93//           PRINTF(4)("checking object %s against %s\n", entity1->getName(), entity2->getName());
94//           tree = entity1->getOBBTree();
95//           if( likely(tree != NULL) && entity2->getOBBTree() != NULL) tree->collideWith(entity1, entity2);
96//         }
97//         entity2 = iterator2->nextElement();
98//       }
99//     }
100//     entity1 = iterator1->nextElement();
101//     entity2 = iterator2->iteratorElement(iterator1);
102//     entity2 = iterator2->nextElement();
103//   }
104//   delete iterator1;
105//   delete iterator2;
106//}
107
108void CDEngine::checkCollisions(std::list<WorldEntity*>& list1, std::list<WorldEntity*>& list2)
[4904]109{
[5027]110  BVTree* tree;
[6142]111  std::list<WorldEntity*>::iterator entity1, entity2, pre1, pre2;
[4704]112  PRINTF(3)("checking for collisions\n");
[6142]113
114  pre1 = list1.begin();
115  while (pre1 != list1.end())
[4689]116  {
[6142]117    entity1 = pre1++;
118    if( likely((*entity1) != this->terrain))
[4689]119    {
[6142]120      pre2 = list2.begin();
121      while (pre2 != list2.end())
[5038]122      {
[6142]123        entity2 = pre2++;
124        if( likely((*entity2) != this->terrain))
[5038]125        {
[6142]126          PRINTF(4)("checking object %s against %s\n", (*entity1)->getName(), (*entity2)->getName());
127          tree = (*entity1)->getOBBTree();
128          if( likely(tree != NULL) && (*entity2)->getOBBTree() != NULL) tree->collideWith(*entity1, *entity2);
[5131]129        }
[5038]130      }
[4689]131    }
[5111]132  }
[4675]133}
134
135
[4924]136/**
137 *  this checks the collisions with the ground
138 */
[4904]139void CDEngine::checkCollisionGround()
140{
[5033]141  if( likely( this->terrain != NULL))
142  {
[6151]143    Quadtree* q = dynamic_cast<Terrain*>(this->terrain)->ssp->getQuadtree();
[4968]144
[5915]145//    QuadtreeNode* n = q->getQuadtreeFromPosition(this->player->getAbsCoor());
[5033]146  }
[4968]147  //sTriangleExt* tri = q->getTriangleFromPosition(this->player->getAbsCoor());
[4904]148}
[4688]149
150
[4924]151/**
152 *  this draws the bounding volume tree
153 * @param depth until which depth to draw the tree
154 * @param drawMode mod which states how to draw it
155 */
[4635]156void CDEngine::drawBV(int depth, int drawMode) const
[4551]157{
158  /* this would operate on  worldList bases, for testing purposes, we only use one OBBTree */
[4689]159  //this->rootTree->drawBV(depth, drawMode);
[6142]160  /// FIXME
161/*  tIterator<WorldEntity>* iterator = entityList->getIterator();
[5115]162  WorldEntity* entity = iterator->firstElement();
[4689]163  while( entity != NULL)
164  {
165    entity->drawBVTree(depth, drawMode);
166    entity = iterator->nextElement();
167  }
[6142]168  delete iterator;*/
[4551]169}
170
171
[4924]172/**
173 * some debug output on the class
174 */
[4546]175void CDEngine::debug()
176{
177  PRINT(0)("\n=============================| CDEngine::debug() |===\n");
178  PRINT(0)("=  CDEngine: Spawning Tree Start\n");
[4689]179  //this->rootTree->debug();
[4546]180  PRINT(0)("=  CDEngine: Spawning Tree: Finished\n");
[4615]181  PRINT(0)("=======================================================\n");
[4546]182
183}
[4615]184
[4924]185
186/**
187 * this spawns a tree for debug purposes only
188 */
[4615]189void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
190{
[4689]191  if ( this->rootTree == NULL)
192    this->rootTree = new OBBTree();
[4615]193  this->rootTree->spawnBVTree(depth, vertices, numVertices);
194}
[4710]195
[4924]196
[6316]197void CDEngine::drawBV(const std::list<WorldEntity*>& drawList ) const
198{
199  std::list<WorldEntity*>::const_iterator entity;
200  for (entity = drawList.begin(); entity != drawList.end(); entity++)
201    if ((*entity)->isVisible())
202      (*entity)->drawBVTree(3, 226);
203}
204
[4924]205/**
206 * this draws the debug spawn tree
207 */
[4710]208void CDEngine::debugDraw(int depth, int drawMode)
209{
210  if(this-> rootTree != NULL)
211    this->rootTree->drawBV(depth, drawMode);
212}
Note: See TracBrowser for help on using the repository browser.