Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5038 was 5038, checked in by patrick, 19 years ago

orxonox/trunk: now collision detection enabled again. excluded the cd with the terrain, which took about 33fps :D now the performance is acceptable again

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