Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8726 was 8715, checked in by ponder, 19 years ago
  • Added special checks for macosx to acinclude.m4 and configure.ac. This sucks
  • Reapplied the endianness checks to the md2_model file. They got lost during the merge operation.
  • Tried to do the collision detection for the ground. But somehow it doesn't work. Perhaps an offset will do.
File size: 4.3 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
49
50/**
51 *  the singleton reference to this class
52 */
53CDEngine* CDEngine::singletonRef = NULL;
54
55
56/**
57 *  standard deconstructor
58 */
59CDEngine::~CDEngine ()
60{
61  CDEngine::singletonRef = NULL;
62}
63
64
65/**
66 *
67 */
68void CDEngine::checkCollisions(ObjectManager::EntityList& list1, ObjectManager::EntityList& list2)
69{
70  BVTree* tree;
71  ObjectManager::EntityList::iterator entity1, entity2, pre1, pre2;
72  PRINTF(5)("checking for collisions\n");
73
74  pre1 = list1.begin();
75  while (pre1 != list1.end())
76  {
77    entity1 = pre1++;
78    if( likely((*entity1) != this->terrain))
79    {
80      pre2 = list2.begin();
81      while (pre2 != list2.end())
82      {
83        entity2 = pre2++;
84        if( likely((*entity2) != this->terrain))
85        {
86          PRINTF(4)("checking object %s against %s\n", (*entity1)->getName(), (*entity2)->getName());
87          tree = (*entity1)->getOBBTree();
88          if( likely(tree != NULL) && (*entity2)->getOBBTree() != NULL)
89            tree->collideWith(*entity1, *entity2);
90        }
91      }
92    }
93  }
94}
95
96
97/**
98 *  this checks the collisions with the ground
99 */
100void CDEngine::checkCollisionGround(std::list<WorldEntity*>& list1)
101{
102
103  std::list<BaseObject*>::const_iterator bspIterator;
104  std::list<WorldEntity*>::iterator entityIterator;
105  const std::list<BaseObject*>* bspList = ClassList::getList(CL_BSP_ENTITY);
106  if( bspList != NULL) {
107
108        // for all bsp managers check all entities
109        for( bspIterator = bspList->begin(); bspIterator != bspList->end(); bspIterator++) {
110        for(entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++)
111        {
112//               PRINTF(0)("Checking: %s a %s\n", (*entityIterator)->getName(), (*entityIterator)->getClassName());
113                (dynamic_cast<BspEntity*>(*bspIterator)->getBspManager())->checkCollision(*entityIterator);
114        }
115        }
116        }
117        const std::list<BaseObject*>* tl = ClassList::getList( CL_TERRAIN );
118  std::list<BaseObject*>::const_iterator ti;   
119        if ( tl == NULL )
120                return;
121        for ( ti = tl->begin(); ti != tl->end(); ++ti ) {
122                        TerrainEntity* terrain = dynamic_cast<TerrainEntity*>( *ti );
123      for( entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++ )
124                {
125                                const Vector& pos = (*entityIterator)->getAbsCoor();
126                               
127                                float height = terrain->getHeight( pos.x, pos.z );
128                                printf( "pos.y-height: %f\n", pos.y-height );
129                                if ( height > pos.y ) {
130                                        (*entityIterator)->setAbsCoor( pos.x, height, pos.z );
131                                }
132      }
133        }
134}
135
136
137/**
138 * some debug output on the class
139 */
140void CDEngine::debug()
141{
142  PRINT(0)("\n=============================| CDEngine::debug() |===\n");
143  PRINT(0)("=  CDEngine: Spawning Tree Start\n");
144  //this->rootTree->debug();
145  PRINT(0)("=  CDEngine: Spawning Tree: Finished\n");
146  PRINT(0)("=======================================================\n");
147}
148
149
150/**
151 * this spawns a tree for debug purposes only
152 */
153void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
154{
155//   if ( this->rootTree == NULL)
156//     this->rootTree = new OBBTree(depth, vertices, numVertices);
157}
158
159
160void CDEngine::drawBV(const ObjectManager::EntityList& drawList, int level) const
161{
162  ObjectManager::EntityList::const_iterator entity;
163  for (entity = drawList.begin(); entity != drawList.end(); entity++)
164    (*entity)->drawBVTree(level, 226);
165}
166
167
168/**
169 * this draws the debug spawn tree
170 */
171void CDEngine::debugDraw(int depth, int drawMode)
172{
173//   if(this-> rootTree != NULL)
174//     this->rootTree->drawBV(depth, drawMode);
175}
Note: See TracBrowser for help on using the repository browser.