Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: now collision detection is accurate. Now I have to tune the code, so the cd becomes faster

File size: 2.9 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 "abstract_model.h"
22#include "world_entity.h"
23#include "list.h"
24
25using namespace std;
26
27
28/**
29   \brief standard constructor
30*/
31CDEngine::CDEngine ()
32{
33   this->setClassName("CDEngine");
34   this->setClassID(CL_CD_ENGINE, "CDEngine");
35
36   /* testing purposes only: */
37   //this->rootTree = new OBBTree();
38}
39
40/**
41   \brief the singleton reference to this class
42*/
43CDEngine* CDEngine::singletonRef = NULL;
44
45/**
46   \brief standard deconstructor
47
48*/
49CDEngine::~CDEngine ()
50{
51  CDEngine::singletonRef = NULL;
52
53}
54
55
56/**
57  \brief this is the collision checking function
58
59  there are some speed improvements that can be done here. a rewrite of the list a would be appropriate to
60  be able to enhance iteration speed.
61 */
62void CDEngine::checkCollisions()
63{
64  tIterator<WorldEntity>* iterator1 = entityList->getIterator();
65  tIterator<WorldEntity>* iterator2 = entityList->getIterator();
66  WorldEntity* entity1 = iterator1->nextElement();
67  WorldEntity* entity2 = iterator2->seekElement(entity1);
68  PRINTF(3)("checking for collisions\n");
69  while( entity1 != NULL)
70  {
71    while( entity2 != NULL)
72    {
73      PRINTF(3)("checking object %s against %s\n", entity1->getName(), entity2->getName());
74      entity1->collideWith(entity2);
75      entity2 = iterator2->nextElement();
76
77    }
78    entity1 = iterator1->nextElement();
79    entity2 = iterator2->seekElement(entity1);
80
81  }
82  delete iterator1;
83  delete iterator2;
84}
85
86
87
88void CDEngine::checkCollisionObjects()
89{}
90
91
92void CDEngine::checkCollisionGround()
93{}
94
95
96void CDEngine::drawBV(int depth, int drawMode) const
97{
98  /* this would operate on  worldList bases, for testing purposes, we only use one OBBTree */
99  //this->rootTree->drawBV(depth, drawMode);
100
101  tIterator<WorldEntity>* iterator = entityList->getIterator();
102  WorldEntity* entity = iterator->nextElement();
103  while( entity != NULL)
104  {
105    entity->drawBVTree(depth, drawMode);
106    entity = iterator->nextElement();
107  }
108  delete iterator;
109  //model->draw();
110}
111
112
113
114
115
116void CDEngine::debug()
117{
118  PRINT(0)("\n=============================| CDEngine::debug() |===\n");
119  PRINT(0)("=  CDEngine: Spawning Tree Start\n");
120  //this->rootTree->debug();
121  PRINT(0)("=  CDEngine: Spawning Tree: Finished\n");
122  PRINT(0)("=======================================================\n");
123
124}
125
126void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
127{
128  if ( this->rootTree == NULL)
129    this->rootTree = new OBBTree();
130  this->rootTree->spawnBVTree(depth, vertices, numVertices);
131}
Note: See TracBrowser for help on using the repository browser.