Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5882 was 5882, checked in by patrick, 18 years ago

collision_detection: very much work on the cd engine, now the obbs do assemble again, but not yet correctly. Much more debug work to come..

File size: 4.2 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#include "list.h"
22
23#include "abstract_model.h"
24#include "world_entity.h"
25#include "terrain.h"
26#include "player.h"
27
28#include "spatial_separation.h"
29#include "quadtree.h"
30#include "quadtree_node.h"
31
32
33
34using namespace std;
35
36
37/**
38 *  standard constructor
39 */
40CDEngine::CDEngine ()
41{
42  this->setClassID(CL_CD_ENGINE, "CDEngine");
43}
44
45
46/**
47 *  the singleton reference to this class
48 */
49CDEngine* CDEngine::singletonRef = NULL;
50
51
52/**
53 *  standard deconstructor
54 */
55CDEngine::~CDEngine ()
56{
57  CDEngine::singletonRef = NULL;
58}
59
60
61/**
62 *  this is the collision checking function
63
64    there are some speed improvements that can be done here. a rewrite of the list a would be appropriate to
65    be able to enhance iteration speed.
66 */
67void CDEngine::checkCollisions()
68{
69  this->checkCollisionObjects();
70  //this->checkCollisionGround();
71}
72
73#include "class_list.h"
74#include "state.h"
75/**
76 *  this checks the collisions with the objects
77 */
78void CDEngine::checkCollisionObjects()
79{
80  const BVTree* tree;
81  tIterator<WorldEntity>* iterator1 = entityList->getIterator();
82  tIterator<WorldEntity>* iterator2 = entityList->getIterator();
83  WorldEntity* entity1 = iterator1->firstElement();
84  WorldEntity* entity2 = iterator2->iteratorElement(iterator1);
85  PRINTF(3)("checking for collisions\n");
86  while( entity1 != NULL)
87  {
88    if( likely(entity1 != this->terrain))
89    {
90      entity2 = iterator2->nextElement();
91
92      while( entity2 != NULL)
93      {
94        if( likely(entity2 != this->terrain))
95        {
96          //printf("checking object %s against %s\n", entity1->getName(), entity2->getName());
97          tree = entity1->getOBBTree();
98
99          if( likely(tree != NULL) && entity2->getOBBTree() != NULL)
100            //tree->collideWith(entity1, entity2);
101            PRINTF(5)("Collision check\n");
102        }
103        entity2 = iterator2->nextElement();
104      }
105    }
106    entity1 = iterator1->nextElement();
107    entity2 = iterator2->iteratorElement(iterator1);
108    entity2 = iterator2->nextElement();
109  }
110  delete iterator1;
111  delete iterator2;
112}
113
114
115/**
116 *  this checks the collisions with the ground
117 */
118void CDEngine::checkCollisionGround()
119{
120  if( likely( this->terrain != NULL))
121  {
122    Quadtree* q = this->terrain->ssp->getQuadtree();
123
124    QuadtreeNode* n = q->getQuadtreeFromPosition(this->player->getAbsCoor());
125  }
126  //sTriangleExt* tri = q->getTriangleFromPosition(this->player->getAbsCoor());
127}
128
129
130/**
131 *  this draws the bounding volume tree
132 * @param depth until which depth to draw the tree
133 * @param drawMode mod which states how to draw it
134 */
135void CDEngine::drawBV(int depth, int drawMode) const
136{
137  /* this would operate on  worldList bases, for testing purposes, we only use one OBBTree */
138  //this->rootTree->drawBV(depth, drawMode);
139
140  tIterator<WorldEntity>* iterator = entityList->getIterator();
141  WorldEntity* entity = iterator->firstElement();
142  while( entity != NULL)
143  {
144    entity->drawBVTree(depth, drawMode);
145    entity = iterator->nextElement();
146  }
147  delete iterator;
148}
149
150
151/**
152 * some debug output on the class
153 */
154void CDEngine::debug()
155{
156  PRINT(0)("\n=============================| CDEngine::debug() |===\n");
157  PRINT(0)("=  CDEngine: Spawning Tree Start\n");
158  //this->rootTree->debug();
159  PRINT(0)("=  CDEngine: Spawning Tree: Finished\n");
160  PRINT(0)("=======================================================\n");
161
162}
163
164
165/**
166 * this spawns a tree for debug purposes only
167 */
168void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
169{
170//   if ( this->rootTree == NULL)
171//     this->rootTree = new OBBTree(depth, vertices, numVertices);
172}
173
174
175/**
176 * this draws the debug spawn tree
177 */
178void CDEngine::debugDraw(int depth, int drawMode)
179{
180  if(this-> rootTree != NULL)
181    this->rootTree->drawBV(depth, drawMode);
182}
Note: See TracBrowser for help on using the repository browser.