Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain.old/src/lib/collision_detection/cd_engine.cc @ 9777

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

merged back

File size: 4.5 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_DETECTION
17
18#include "cd_engine.h"
19#include "obb_tree.h"
20#include "debug.h"
21
22#include "class_list.h"
23
24#include "model.h"
25#include "world_entity.h"
26#include "terrain_entity.h"
27// #include "player.h"
28
29#include "spatial_separation.h"
30#include "quadtree.h"
31#include "quadtree_node.h"
32
33#include "bsp_manager.h"
34#include "bsp_entity.h"
35
36using namespace std;
37
38
39/**
40 *  standard constructor
41 */
42CDEngine::CDEngine ()
43{
44  this->setClassID(CL_CD_ENGINE, "CDEngine");
45
46  this->bAbordOnFirstCollision = false;
47
48  this->terrain = NULL;
49}
50
51
52/**
53 *  the singleton reference to this class
54 */
55CDEngine* CDEngine::singletonRef = NULL;
56
57
58/**
59 *  standard deconstructor
60 */
61CDEngine::~CDEngine ()
62{
63  CDEngine::singletonRef = NULL;
64}
65
66
67/**
68 *
69 */
70void CDEngine::checkCollisions(ObjectManager::EntityList& list1, ObjectManager::EntityList& list2)
71{
72  BVTree* tree;
73  ObjectManager::EntityList::iterator entity1, entity2, pre1, pre2;
74  PRINTF(5)("checking for collisions\n");
75
76  pre1 = list1.begin();
77  while (pre1 != list1.end())
78  {
79    entity1 = pre1++;
80    if( likely((*entity1) != this->terrain))
81    {
82      pre2 = list2.begin();
83      while (pre2 != list2.end())
84      {
85        entity2 = pre2++;
86        if( likely((*entity2) != this->terrain))
87        {
88          PRINTF(5)("checking object %s (%s) against %s (%s)\n", (*entity1)->getClassName(), (*entity1)->getName(), (*entity2)->getClassName(), (*entity2)->getName());
89          tree = (*entity1)->getOBBTree();
90          if( likely(tree != NULL) && (*entity2)->getOBBTree() != NULL)
91            tree->collideWith(*entity1, *entity2);
92        }
93      }
94    }
95  }
96}
97
98
99/**
100 *  this checks the collisions with the ground
101 */
102void CDEngine::checkCollisionGround(std::list<WorldEntity*>& list1)
103{
104
105  std::list<BaseObject*>::const_iterator bspIterator;
106  std::list<WorldEntity*>::iterator entityIterator;
107  const std::list<BaseObject*>* bspList = ClassList::getList(CL_BSP_ENTITY);
108  if( bspList != NULL)
109  {
110
111    // for all bsp managers check all entities
112    for( bspIterator = bspList->begin(); bspIterator != bspList->end(); bspIterator++)
113    {
114      for(entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++)
115      {
116        //               PRINTF(0)("Checking: %s a %s\n", (*entityIterator)->getName(), (*entityIterator)->getClassName());
117        (dynamic_cast<BspEntity*>(*bspIterator)->getBspManager())->checkCollision(*entityIterator);
118      }
119    }
120  }
121
122  /// COLLISION OF THE Modular-TERRAIN
123/*  const std::list<BaseObject*>* tl = ClassList::getList( CL_TERRAIN );
124  std::list<BaseObject*>::const_iterator ti;
125  if ( tl == NULL )
126    return;
127  float offset = 8.0f;
128  for ( ti = tl->begin(); ti != tl->end(); ++ti )
129  {
130    TerrainEntity* terrain = dynamic_cast<TerrainEntity*>( *ti );
131    for( entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++ )
132    {
133      Vector pos( (*entityIterator)->getAbsCoor() );
134      Vector normal;
135      float height = pos.y;
136      terrain->getAltitude( pos, normal );
137      if ( height-offset < pos.y )
138      {
139        ( *entityIterator )->registerCollision(
140          *entityIterator, terrain, pos, normal );
141      }
142    }
143  }*/
144}
145
146
147/**
148 * some debug output on the class
149 */
150void CDEngine::debug()
151{
152  PRINT(0)("\n=============================| CDEngine::debug() |===\n");
153  PRINT(0)("=  CDEngine: Spawning Tree Start\n");
154  //this->rootTree->debug();
155  PRINT(0)("=  CDEngine: Spawning Tree: Finished\n");
156  PRINT(0)("=======================================================\n");
157}
158
159
160/**
161 * this spawns a tree for debug purposes only
162 */
163void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
164{
165  //   if ( this->rootTree == NULL)
166  //     this->rootTree = new OBBTree(depth, vertices, numVertices);
167}
168
169
170void CDEngine::drawBV(const ObjectManager::EntityList& drawList, int level) const
171{
172  ObjectManager::EntityList::const_iterator entity;
173  for (entity = drawList.begin(); entity != drawList.end(); entity++)
174    (*entity)->drawBVTree(level, 226);
175}
176
177
178/**
179 * this draws the debug spawn tree
180 */
181void CDEngine::debugDraw(int depth, int drawMode)
182{
183  //   if(this-> rootTree != NULL)
184  //     this->rootTree->drawBV(depth, drawMode);
185}
Note: See TracBrowser for help on using the repository browser.