Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File size: 3.8 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
[7711]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
[8490]22#include "class_list.h"
23
[6022]24#include "model.h"
[4919]25#include "world_entity.h"
26#include "terrain.h"
[5915]27// #include "player.h"
[4919]28
29#include "spatial_separation.h"
30#include "quadtree.h"
31#include "quadtree_node.h"
32
[8186]33#include "bsp_manager.h"
[8490]34#include "bsp_entity.h"
[4919]35
[4510]36
37
[9406]38
[4510]39/**
[4836]40 *  standard constructor
[4923]41 */
[4615]42CDEngine::CDEngine ()
[4510]43{
[4923]44  this->setClassID(CL_CD_ENGINE, "CDEngine");
[7711]45
46  this->bAbordOnFirstCollision = false;
[9406]47
[9110]48  this->terrain = NULL;
[4510]49}
50
[4923]51
[4510]52/**
[4836]53 *  the singleton reference to this class
[4923]54 */
[4511]55CDEngine* CDEngine::singletonRef = NULL;
[4510]56
[4923]57
[4510]58/**
[4836]59 *  standard deconstructor
[4923]60 */
[4615]61CDEngine::~CDEngine ()
[4510]62{
[4511]63  CDEngine::singletonRef = NULL;
[4510]64}
[4546]65
66
[4695]67/**
[7711]68 *
[4695]69 */
[7370]70void CDEngine::checkCollisions(ObjectManager::EntityList& list1, ObjectManager::EntityList& list2)
[4904]71{
[5027]72  BVTree* tree;
[7370]73  ObjectManager::EntityList::iterator entity1, entity2, pre1, pre2;
[7711]74  PRINTF(5)("checking for collisions\n");
[6142]75
76  pre1 = list1.begin();
77  while (pre1 != list1.end())
[4689]78  {
[6142]79    entity1 = pre1++;
80    if( likely((*entity1) != this->terrain))
[4689]81    {
[6142]82      pre2 = list2.begin();
83      while (pre2 != list2.end())
[5038]84      {
[6142]85        entity2 = pre2++;
86        if( likely((*entity2) != this->terrain))
[5038]87        {
[9406]88          PRINTF(5)("checking object %s (%s) against %s (%s)\n",
89            (*entity1)->getClassCName(), (*entity1)->getCName(), (*entity2)->getClassCName(), (*entity2)->getCName());
[6142]90          tree = (*entity1)->getOBBTree();
[7711]91          if( likely(tree != NULL) && (*entity2)->getOBBTree() != NULL)
92            tree->collideWith(*entity1, *entity2);
[5131]93        }
[5038]94      }
[4689]95    }
[5111]96  }
[4675]97}
98
99
[4924]100/**
101 *  this checks the collisions with the ground
102 */
[8186]103void CDEngine::checkCollisionGround(std::list<WorldEntity*>& list1)
[4904]104{
[8316]105
[8490]106  std::list<BaseObject*>::const_iterator bspIterator;
107  std::list<WorldEntity*>::iterator entityIterator;
108  const std::list<BaseObject*>* bspList = ClassList::getList(CL_BSP_ENTITY);
109  if( bspList == NULL)
110    return;
[8186]111
[8490]112  // for all bsp managers check all entities
113  for( bspIterator = bspList->begin(); bspIterator != bspList->end(); bspIterator++) {
114      for(entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++)
115      {
[9406]116//         PRINTF(0)("Checking: %s a %s\n", (*entityIterator)->getName(), (*entityIterator)->getClassCName());
[8490]117        (dynamic_cast<BspEntity*>(*bspIterator)->getBspManager())->checkCollision(*entityIterator);
118      }
[8186]119  }
[4904]120}
[4688]121
122
[4924]123/**
124 * some debug output on the class
125 */
[4546]126void CDEngine::debug()
127{
128  PRINT(0)("\n=============================| CDEngine::debug() |===\n");
129  PRINT(0)("=  CDEngine: Spawning Tree Start\n");
[4689]130  //this->rootTree->debug();
[4546]131  PRINT(0)("=  CDEngine: Spawning Tree: Finished\n");
[4615]132  PRINT(0)("=======================================================\n");
[4546]133}
[4615]134
[4924]135
136/**
137 * this spawns a tree for debug purposes only
138 */
[4615]139void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
140{
[7711]141//   if ( this->rootTree == NULL)
142//     this->rootTree = new OBBTree(depth, vertices, numVertices);
[4615]143}
[4710]144
[4924]145
[7739]146void CDEngine::drawBV(const ObjectManager::EntityList& drawList, int level) const
[6316]147{
[7370]148  ObjectManager::EntityList::const_iterator entity;
[6316]149  for (entity = drawList.begin(); entity != drawList.end(); entity++)
[7739]150    (*entity)->drawBVTree(level, 226);
[6316]151}
152
[8490]153
[4924]154/**
155 * this draws the debug spawn tree
156 */
[4710]157void CDEngine::debugDraw(int depth, int drawMode)
158{
[7711]159//   if(this-> rootTree != NULL)
160//     this->rootTree->drawBV(depth, drawMode);
[4710]161}
Note: See TracBrowser for help on using the repository browser.