Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: merged the branche bsp_model back here

File size: 3.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 "model.h"
23#include "world_entity.h"
24#include "terrain.h"
25// #include "player.h"
26
27#include "spatial_separation.h"
28#include "quadtree.h"
29#include "quadtree_node.h"
30
31#include "bsp_manager.h"
32
33using namespace std;
34
35
36/**
37 *  standard constructor
38 */
39CDEngine::CDEngine ()
40{
41  this->setClassID(CL_CD_ENGINE, "CDEngine");
42
43  this->bAbordOnFirstCollision = false;
44}
45
46
47/**
48 *  the singleton reference to this class
49 */
50CDEngine* CDEngine::singletonRef = NULL;
51
52
53/**
54 *  standard deconstructor
55 */
56CDEngine::~CDEngine ()
57{
58  CDEngine::singletonRef = NULL;
59}
60
61
62/**
63 *
64 */
65void CDEngine::checkCollisions(ObjectManager::EntityList& list1, ObjectManager::EntityList& list2)
66{
67  BVTree* tree;
68  ObjectManager::EntityList::iterator entity1, entity2, pre1, pre2;
69  PRINTF(5)("checking for collisions\n");
70
71  pre1 = list1.begin();
72  while (pre1 != list1.end())
73  {
74    entity1 = pre1++;
75    if( likely((*entity1) != this->terrain))
76    {
77      pre2 = list2.begin();
78      while (pre2 != list2.end())
79      {
80        entity2 = pre2++;
81        if( likely((*entity2) != this->terrain))
82        {
83          PRINTF(4)("checking object %s against %s\n", (*entity1)->getName(), (*entity2)->getName());
84          tree = (*entity1)->getOBBTree();
85          if( likely(tree != NULL) && (*entity2)->getOBBTree() != NULL)
86            tree->collideWith(*entity1, *entity2);
87        }
88      }
89    }
90  }
91}
92
93
94/**
95 *  this checks the collisions with the ground
96 */
97void CDEngine::checkCollisionGround(std::list<WorldEntity*>& list1)
98{
99  if( likely( this->terrain != NULL))
100  {
101    Quadtree* q = dynamic_cast<Terrain*>(this->terrain)->ssp->getQuadtree();
102//    QuadtreeNode* n = q->getQuadtreeFromPosition(this->player->getAbsCoor());
103  }
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  }
117}
118
119
120/**
121 * some debug output on the class
122 */
123void CDEngine::debug()
124{
125  PRINT(0)("\n=============================| CDEngine::debug() |===\n");
126  PRINT(0)("=  CDEngine: Spawning Tree Start\n");
127  //this->rootTree->debug();
128  PRINT(0)("=  CDEngine: Spawning Tree: Finished\n");
129  PRINT(0)("=======================================================\n");
130
131}
132
133
134/**
135 * this spawns a tree for debug purposes only
136 */
137void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
138{
139//   if ( this->rootTree == NULL)
140//     this->rootTree = new OBBTree(depth, vertices, numVertices);
141}
142
143
144void CDEngine::drawBV(const ObjectManager::EntityList& drawList, int level) const
145{
146  ObjectManager::EntityList::const_iterator entity;
147  for (entity = drawList.begin(); entity != drawList.end(); entity++)
148    (*entity)->drawBVTree(level, 226);
149}
150
151/**
152 * this draws the debug spawn tree
153 */
154void CDEngine::debugDraw(int depth, int drawMode)
155{
156//   if(this-> rootTree != NULL)
157//     this->rootTree->drawBV(depth, drawMode);
158}
Note: See TracBrowser for help on using the repository browser.