Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: runtime-segfault prevented

File size: 4.1 KB
RevLine 
[4615]1/*
[4510]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
[4923]11### File Specific:
[4511]12   main-programmer: Patrick Boenzli
[4510]13   co-programmer: ...
14*/
15
[4511]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
[4510]17
[4511]18#include "cd_engine.h"
[4546]19#include "obb_tree.h"
20#include "debug.h"
[4689]21#include "list.h"
[4510]22
[4968]23#include "abstract_model.h"
[4919]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
[5042]33
[4510]34using namespace std;
35
36
37/**
[4836]38 *  standard constructor
[4923]39 */
[4615]40CDEngine::CDEngine ()
[4510]41{
[4923]42  this->setClassID(CL_CD_ENGINE, "CDEngine");
[4510]43}
44
[4923]45
[4510]46/**
[4836]47 *  the singleton reference to this class
[4923]48 */
[4511]49CDEngine* CDEngine::singletonRef = NULL;
[4510]50
[4923]51
[4510]52/**
[4836]53 *  standard deconstructor
[4923]54 */
[4615]55CDEngine::~CDEngine ()
[4510]56{
[4511]57  CDEngine::singletonRef = NULL;
[4510]58}
[4546]59
60
[4695]61/**
[4923]62 *  this is the collision checking function
[4695]63
[4923]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.
[4695]66 */
[4675]67void CDEngine::checkCollisions()
68{
[5038]69  this->checkCollisionObjects();
[5047]70  //this->checkCollisionGround();
[4904]71}
72
[5115]73#include "class_list.h"
74#include "state.h"
[4924]75/**
76 *  this checks the collisions with the objects
77 */
[4904]78void CDEngine::checkCollisionObjects()
79{
[5027]80  BVTree* tree;
[4689]81  tIterator<WorldEntity>* iterator1 = entityList->getIterator();
82  tIterator<WorldEntity>* iterator2 = entityList->getIterator();
[5115]83  WorldEntity* entity1 = iterator1->firstElement();
84  WorldEntity* entity2 = iterator2->iteratorElement(iterator1);
[4704]85  PRINTF(3)("checking for collisions\n");
[5111]86  while( entity1 != NULL)
[4689]87  {
[5038]88    if( likely(entity1 != this->terrain))
[4689]89    {
[5115]90      entity2 = iterator2->nextElement();
91
[5038]92      while( entity2 != NULL)
93      {
[5131]94        if( likely(entity2 != this->terrain))
[5038]95        {
[5115]96          PRINTF(4)("checking object %s against %s\n", entity1->getName(), entity2->getName());
[5038]97          tree = entity1->getOBBTree();
[5115]98          if( likely(tree != NULL) && entity2->getOBBTree() != NULL) tree->collideWith(entity1, entity2);
[5131]99        }
[5038]100        entity2 = iterator2->nextElement();
101      }
[4689]102    }
103    entity1 = iterator1->nextElement();
[5115]104    entity2 = iterator2->iteratorElement(iterator1);
[5134]105    entity2 = iterator2->nextElement();
[5111]106  }
[4689]107  delete iterator1;
108  delete iterator2;
[4675]109}
110
111
[4924]112/**
113 *  this checks the collisions with the ground
114 */
[4904]115void CDEngine::checkCollisionGround()
116{
[5033]117  if( likely( this->terrain != NULL))
118  {
119    Quadtree* q = this->terrain->ssp->getQuadtree();
[4968]120
[5033]121    QuadtreeNode* n = q->getQuadtreeFromPosition(this->player->getAbsCoor());
122  }
[4968]123  //sTriangleExt* tri = q->getTriangleFromPosition(this->player->getAbsCoor());
[4904]124}
[4688]125
126
[4924]127/**
128 *  this draws the bounding volume tree
129 * @param depth until which depth to draw the tree
130 * @param drawMode mod which states how to draw it
131 */
[4635]132void CDEngine::drawBV(int depth, int drawMode) const
[4551]133{
134  /* this would operate on  worldList bases, for testing purposes, we only use one OBBTree */
[4689]135  //this->rootTree->drawBV(depth, drawMode);
136
137  tIterator<WorldEntity>* iterator = entityList->getIterator();
[5115]138  WorldEntity* entity = iterator->firstElement();
[4689]139  while( entity != NULL)
140  {
141    entity->drawBVTree(depth, drawMode);
142    entity = iterator->nextElement();
143  }
144  delete iterator;
[4551]145}
146
147
[4924]148/**
149 * some debug output on the class
150 */
[4546]151void CDEngine::debug()
152{
153  PRINT(0)("\n=============================| CDEngine::debug() |===\n");
154  PRINT(0)("=  CDEngine: Spawning Tree Start\n");
[4689]155  //this->rootTree->debug();
[4546]156  PRINT(0)("=  CDEngine: Spawning Tree: Finished\n");
[4615]157  PRINT(0)("=======================================================\n");
[4546]158
159}
[4615]160
[4924]161
162/**
163 * this spawns a tree for debug purposes only
164 */
[4615]165void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
166{
[4689]167  if ( this->rootTree == NULL)
168    this->rootTree = new OBBTree();
[4615]169  this->rootTree->spawnBVTree(depth, vertices, numVertices);
170}
[4710]171
[4924]172
173/**
174 * this draws the debug spawn tree
175 */
[4710]176void CDEngine::debugDraw(int depth, int drawMode)
177{
178  if(this-> rootTree != NULL)
179    this->rootTree->drawBV(depth, drawMode);
180}
Note: See TracBrowser for help on using the repository browser.