Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: the way, where the fighter flights though is now drawn in quadtree partitions. now you can see where the space craft has been :)

File size: 3.3 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 "list.h"
23
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   /* testing purposes only: */
44   //this->rootTree = new OBBTree();
45}
46
47/**
48 *  the singleton reference to this class
49*/
50CDEngine* CDEngine::singletonRef = NULL;
51
52/**
53 *  standard deconstructor
54
55*/
56CDEngine::~CDEngine ()
57{
58  CDEngine::singletonRef = NULL;
59
60}
61
62
63/**
64  \brief this is the collision checking function
65
66  there are some speed improvements that can be done here. a rewrite of the list a would be appropriate to
67  be able to enhance iteration speed.
68 */
69void CDEngine::checkCollisions()
70{
71  //this->checkCollisionObjects();
72  this->checkCollisionGround();
73}
74
75
76
77void CDEngine::checkCollisionObjects()
78{
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    while( entity2 != NULL)
87    {
88      PRINTF(3)("checking object %s against %s\n", entity1->getName(), entity2->getName());
89      entity1->collideWith(entity2);
90      entity2 = iterator2->nextElement();
91    }
92    entity1 = iterator1->nextElement();
93    entity2 = iterator2->seekElement(entity1);
94
95  }
96  delete iterator1;
97  delete iterator2;
98}
99
100
101void CDEngine::checkCollisionGround()
102{
103  Quadtree* q = this->terrain->ssp->getQuadtree();
104  q->getQuadtreeFromPosition(this->player->getAbsCoor());
105}
106
107
108void CDEngine::drawBV(int depth, int drawMode) const
109{
110  /* this would operate on  worldList bases, for testing purposes, we only use one OBBTree */
111  //this->rootTree->drawBV(depth, drawMode);
112
113  tIterator<WorldEntity>* iterator = entityList->getIterator();
114  WorldEntity* entity = iterator->nextElement();
115  while( entity != NULL)
116  {
117    entity->drawBVTree(depth, drawMode);
118    entity = iterator->nextElement();
119  }
120  delete iterator;
121  //model->draw();
122}
123
124
125
126
127
128void CDEngine::debug()
129{
130  PRINT(0)("\n=============================| CDEngine::debug() |===\n");
131  PRINT(0)("=  CDEngine: Spawning Tree Start\n");
132  //this->rootTree->debug();
133  PRINT(0)("=  CDEngine: Spawning Tree: Finished\n");
134  PRINT(0)("=======================================================\n");
135
136}
137
138void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
139{
140  if ( this->rootTree == NULL)
141    this->rootTree = new OBBTree();
142  this->rootTree->spawnBVTree(depth, vertices, numVertices);
143}
144
145void CDEngine::debugDraw(int depth, int drawMode)
146{
147  if(this-> rootTree != NULL)
148    this->rootTree->drawBV(depth, drawMode);
149}
Note: See TracBrowser for help on using the repository browser.