Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10114 was 10033, checked in by patrick, 18 years ago

moved some of the importer sources, probably will need to rebuild the project

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