Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 23, 2006, 2:25:13 PM (18 years ago)
Author:
bensch
Message:

orxonox/cd_merge: merged the old collision-detection here.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/cd_merge/src/lib/collision_detection/obb_tree.cc

    r5684 r6657  
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION
    1717
    1818#include "obb_tree.h"
     
    3131 *  standard constructor
    3232*/
    33 OBBTree::OBBTree ()
     33OBBTree::OBBTree(int depth, const modelInfo& modelInf)
     34  : BVTree()
    3435{
     36  this->depth = depth;
    3537  this->init();
    36 }
    37 
    38 OBBTree::OBBTree(int depth, sVec3D *verticesList, const int length)
    39 {
    40   this->init();
    41   this->spawnBVTree(depth, verticesList, length);
    42 }
    43 
    44 OBBTree::OBBTree(int depth, const modelInfo& modInfo)
    45 {
    46   this->init();
    47   this->spawnBVTree(depth, modInfo);
     38  this->spawnBVTree(modelInf);
    4839}
    4940
     
    5344{
    5445  this->setClassID(CL_OBB_TREE, "OBBTree");
    55 
    5646  this->rootNode = NULL;
    57 
    5847  this->id = 0;
    5948}
     
    6958
    7059
    71 void OBBTree::spawnBVTree(int depth, sVec3D *verticesList, const int length)
    72 {
    73   if( unlikely(this->rootNode != NULL))
    74     {
    75       PRINTF(2)("The BVTree has already been spawned, flushing and respawning again...\n");
    76       this->flushTree();
    77     }
    78   OBBTreeNode* node = new OBBTreeNode();
    79   this->rootNode = node;
    80   this->rootNode->setTreeRef(this);
    81   this->rootNode->spawnBVTree(--depth, verticesList, length);
    82 }
    83 
    84 
    85 void OBBTree::spawnBVTree(int depth, const modelInfo& modInfo)
     60/**
     61 *  this function creates a bv tree out of a modelInf structure
     62 * @param modelInf the model info of a model (modelInfo), containing vertices, triangle and normal infos
     63 */
     64void OBBTree::spawnBVTree(const modelInfo& modelInf)
    8665{
    8766  if( unlikely(this->rootNode != NULL))
     
    9069    this->flushTree();
    9170  }
    92   OBBTreeNode* node = new OBBTreeNode();
    93   this->rootNode = node;
    94   this->rootNode->setTreeRef(this);
    95   this->rootNode->spawnBVTree(--depth, modInfo);
     71  this->rootNode = new OBBTreeNode(*this, NULL, depth-1);
     72
     73  /* triangles indexes created */
     74  int* triangleIndexes = new int[modelInf.numTriangles];
     75  for( int i = 0; i < modelInf.numTriangles; ++i)
     76    triangleIndexes[i] = i;
     77
     78  this->rootNode->spawnBVTree(modelInf, triangleIndexes, modelInf.numTriangles);
    9679}
    9780
    9881
     82/**
     83 *  release the current bv tree if any
     84 */
    9985void OBBTree:: flushTree()
    10086{}
    10187
    10288
    103 void OBBTree::collideWith(WorldEntity* entity1, WorldEntity* entity2)
     89/**
     90 * this collides two bvtrees together. the trees are attached to pnodes Objects A and B
     91 * @param nodeA: PNode of object A
     92 * @param nodeB: Pnode of object B
     93 */
     94void OBBTree::collideWith(const WorldEntity& entity1, const WorldEntity& entity2) const
    10495{
    105   if( likely(entity2->getOBBTree() != NULL) )
    106     this->rootNode->collideWith(((OBBTree*)entity2->getOBBTree())->getRootNode(), entity1, entity2);
     96  if( likely(entity2.getOBBTree() != NULL) )
     97    this->rootNode->collideWith(*(((OBBTree*)entity2.getOBBTree())->getRootNode()), entity1, entity2);
    10798}
    10899
    109100
    110101/**
    111  * this collides two bvtrees together. the trees are attached to pnodes Objects A and B
    112  * @param tree: the other tree to collide with (Object B)
    113  * @param nodeA: PNode of object A
    114  * @param nodeB: Pnode of object B
     102 *  draw bv tree
    115103 */
    116 void OBBTree::collideWith(BVTree* tree, WorldEntity* nodeA, WorldEntity* nodeB)
    117 {
    118   this->rootNode->collideWith(((OBBTree*)tree)->getRootNode(), nodeA, nodeB);
    119 }
    120 
    121 
    122104void OBBTree::drawBV(int depth, int drawMode) const
    123105{
     
    129111
    130112
    131 
     113/**
     114 *  some debug output and creation function
     115 *
     116 * doesn't work at the moment
     117 */
    132118void OBBTree::debug()
    133119{
     
    153139    }
    154140
    155   this->spawnBVTree(3, vertList, length);
     141//   this->spawnBVTree(vertList, length);
    156142
    157143  PRINT(0)("=  Spawning Tree: Finished\n");
Note: See TracChangeset for help on using the changeset viewer.