Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8453 was 8328, checked in by ponder, 18 years ago
  • Renamed Terrain into TerrainEntity in order to avoid conflicts between the importer/terrain class and the world_entities/terrain.
  • Changed TerrainEntity to support the new terrain class.
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_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      }
90    }
91  }
92}
93
94
95/**
96 *  this checks the collisions with the ground
97 */
98void CDEngine::checkCollisionGround(std::list<WorldEntity*>& list1)
99{
100  if( likely( this->terrain != NULL))
101  {
102        //kraus: TODO put collision detection for terrain class here...
103    //Quadtree* q = dynamic_cast<TerrainEntity*>(this->terrain)->ssp->getQuadtree();
104        //QuadtreeNode* n = q->getQuadtreeFromPosition(this->player->getAbsCoor());
105  }
106 
107  if( likely( this->bspManager != NULL))
108  {
109    std::list<WorldEntity*>::iterator iterator;
110    PRINTF(3)("checking for collisions\n");
111
112    iterator = list1.begin();
113    while (iterator != list1.end())
114    {
115      bspManager->checkCollision(*iterator);
116      iterator++;
117    }
118  }
119}
120
121
122/**
123 * some debug output on the class
124 */
125void CDEngine::debug()
126{
127  PRINT(0)("\n=============================| CDEngine::debug() |===\n");
128  PRINT(0)("=  CDEngine: Spawning Tree Start\n");
129  //this->rootTree->debug();
130  PRINT(0)("=  CDEngine: Spawning Tree: Finished\n");
131  PRINT(0)("=======================================================\n");
132
133}
134
135
136/**
137 * this spawns a tree for debug purposes only
138 */
139void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
140{
141//   if ( this->rootTree == NULL)
142//     this->rootTree = new OBBTree(depth, vertices, numVertices);
143}
144
145
146void CDEngine::drawBV(const ObjectManager::EntityList& drawList, int level) const
147{
148  ObjectManager::EntityList::const_iterator entity;
149  for (entity = drawList.begin(); entity != drawList.end(); entity++)
150    (*entity)->drawBVTree(level, 226);
151}
152
153/**
154 * this draws the debug spawn tree
155 */
156void CDEngine::debugDraw(int depth, int drawMode)
157{
158//   if(this-> rootTree != NULL)
159//     this->rootTree->drawBV(depth, drawMode);
160}
Note: See TracBrowser for help on using the repository browser.