Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: reimplemented the list functions, as i did before in revision 5110.
This time, i looked out for the bugs, and i think i found one

@patrick: i know, that you do not want to code at the moment… :/ → see mail

File size: 4.4 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
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  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  //entity2 = iterator2->nextElement();
86  PRINTF(3)("checking for collisions\n");
87  while( entity1 != NULL)
88  {
89    if( likely(entity1 != this->terrain))
90    {
91      entity2 = iterator2->nextElement();
92
93      while( entity2 != NULL)
94      {
95//        if (entity2 != NULL)
96//          printf("entity2::%s::%s", entity2->getClassName(), getName());
97
98        ///////////////// FIXME
99        ///////////////// COMMENTED OUT, because some part of it generated a segfault
100        ////////////////
101
102/*                if( likely(entity2 != this->terrain))
103        {
104          PRINTF(4)("checking object %s against %s\n", entity1->getName(), entity2->getName());
105          tree = entity1->getOBBTree();
106          if( likely(tree != NULL) && entity2->getOBBTree() != NULL) tree->collideWith(entity1, entity2);
107        }*/
108        entity2 = iterator2->nextElement();
109      }
110//      printf("\n");
111    }
112    entity1 = iterator1->nextElement();
113    entity2 = iterator2->iteratorElement(iterator1);
114  }
115  delete iterator1;
116  delete iterator2;
117}
118
119
120/**
121 *  this checks the collisions with the ground
122 */
123void CDEngine::checkCollisionGround()
124{
125  if( likely( this->terrain != NULL))
126  {
127    Quadtree* q = this->terrain->ssp->getQuadtree();
128
129    QuadtreeNode* n = q->getQuadtreeFromPosition(this->player->getAbsCoor());
130  }
131  //sTriangleExt* tri = q->getTriangleFromPosition(this->player->getAbsCoor());
132}
133
134
135/**
136 *  this draws the bounding volume tree
137 * @param depth until which depth to draw the tree
138 * @param drawMode mod which states how to draw it
139 */
140void CDEngine::drawBV(int depth, int drawMode) const
141{
142  /* this would operate on  worldList bases, for testing purposes, we only use one OBBTree */
143  //this->rootTree->drawBV(depth, drawMode);
144
145  tIterator<WorldEntity>* iterator = entityList->getIterator();
146  WorldEntity* entity = iterator->firstElement();
147  while( entity != NULL)
148  {
149    entity->drawBVTree(depth, drawMode);
150    entity = iterator->nextElement();
151  }
152  delete iterator;
153}
154
155
156/**
157 * some debug output on the class
158 */
159void CDEngine::debug()
160{
161  PRINT(0)("\n=============================| CDEngine::debug() |===\n");
162  PRINT(0)("=  CDEngine: Spawning Tree Start\n");
163  //this->rootTree->debug();
164  PRINT(0)("=  CDEngine: Spawning Tree: Finished\n");
165  PRINT(0)("=======================================================\n");
166
167}
168
169
170/**
171 * this spawns a tree for debug purposes only
172 */
173void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
174{
175  if ( this->rootTree == NULL)
176    this->rootTree = new OBBTree();
177  this->rootTree->spawnBVTree(depth, vertices, numVertices);
178}
179
180
181/**
182 * this draws the debug spawn tree
183 */
184void CDEngine::debugDraw(int depth, int drawMode)
185{
186  if(this-> rootTree != NULL)
187    this->rootTree->drawBV(depth, drawMode);
188}
Note: See TracBrowser for help on using the repository browser.