Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8690 was 8690, checked in by ponder, 18 years ago
File size: 3.9 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_entity.h"
25
26// #include "player.h"
27
28#include "spatial_separation.h"
29#include "quadtree.h"
30#include "quadtree_node.h"
31
32#include "bsp_manager.h"
33
34using namespace std;
35
36
37/**
38 *  standard constructor
39 */
40CDEngine::CDEngine ()
41{
42  this->setClassID(CL_CD_ENGINE, "CDEngine");
43
44  this->bAbordOnFirstCollision = false;
45}
46
47
48/**
49 *  the singleton reference to this class
50 */
51CDEngine* CDEngine::singletonRef = NULL;
52
53
54/**
55 *  standard deconstructor
56 */
57CDEngine::~CDEngine ()
58{
59  CDEngine::singletonRef = NULL;
60}
61
62
63/**
64 *
65 */
66void CDEngine::checkCollisions(ObjectManager::EntityList& list1, ObjectManager::EntityList& list2)
67{
68  BVTree* tree;
69  ObjectManager::EntityList::iterator entity1, entity2, pre1, pre2;
70  PRINTF(5)("checking for collisions\n");
71
72  pre1 = list1.begin();
73  while (pre1 != list1.end())
74  {
75    entity1 = pre1++;
76    if( likely((*entity1) != this->terrain))
77    {
78      pre2 = list2.begin();
79      while (pre2 != list2.end())
80      {
81        entity2 = pre2++;
82        if( likely((*entity2) != this->terrain))
83        {
84          PRINTF(4)("checking object %s against %s\n", (*entity1)->getName(), (*entity2)->getName());
85          tree = (*entity1)->getOBBTree();
86          if( likely(tree != NULL) && (*entity2)->getOBBTree() != NULL)
87            tree->collideWith(*entity1, *entity2);
88        }
89                else {
90                        this->checkCollisionGround( list1 );
91                }
92      }
93    }
94        else {
95                this->checkCollisionGround( list2 );
96        }
97  }
98}
99
100
101/**
102 *  this checks the collisions with the ground
103 */
104void CDEngine::checkCollisionGround(std::list<WorldEntity*>& list1)
105{
106  if( likely( this->terrain != NULL ) )
107  {
108        TerrainEntity *ground = dynamic_cast<TerrainEntity*>(this->terrain);
109    std::list<WorldEntity*>::iterator iterator;
110    PRINTF(2)("checking for collisions\n");
111    iterator = list1.begin();
112    while ( iterator != list1.end() ) {
113                const Vector& position = (*iterator)->getAbsCoor();
114                float height = ground->getHeight( position.x, position.z );             
115                if ( position.y < height )
116                        (*iterator)->setAbsCoor( position.x, height, position.z );
117    }   
118  }
119 
120  if( likely( this->bspManager != NULL))
121  {
122    std::list<WorldEntity*>::iterator iterator;
123    PRINTF(3)("checking for collisions\n");
124
125    iterator = list1.begin();
126    while (iterator != list1.end())
127    {
128      bspManager->checkCollision(*iterator);
129      iterator++;
130    }
131  }
132}
133
134
135/**
136 * some debug output on the class
137 */
138void CDEngine::debug()
139{
140  PRINT(0)("\n=============================| CDEngine::debug() |===\n");
141  PRINT(0)("=  CDEngine: Spawning Tree Start\n");
142  //this->rootTree->debug();
143  PRINT(0)("=  CDEngine: Spawning Tree: Finished\n");
144  PRINT(0)("=======================================================\n");
145
146}
147
148
149/**
150 * this spawns a tree for debug purposes only
151 */
152void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
153{
154//   if ( this->rootTree == NULL)
155//     this->rootTree = new OBBTree(depth, vertices, numVertices);
156}
157
158
159void CDEngine::drawBV(const ObjectManager::EntityList& drawList, int level) const
160{
161  ObjectManager::EntityList::const_iterator entity;
162  for (entity = drawList.begin(); entity != drawList.end(); entity++)
163    (*entity)->drawBVTree(level, 226);
164}
165
166/**
167 * this draws the debug spawn tree
168 */
169void CDEngine::debugDraw(int depth, int drawMode)
170{
171//   if(this-> rootTree != NULL)
172//     this->rootTree->drawBV(depth, drawMode);
173}
Note: See TracBrowser for help on using the repository browser.