Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8243 was 8186, checked in by bensch, 19 years ago

trunk: merged the branche bsp_model back here

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