Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/collision_detection/src/lib/collision_detection/obb_tree.cc @ 5702

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

collision_detection: interface change, const war continued

File size: 3.9 KB
RevLine 
[4573]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
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 "obb_tree.h"
[4550]19#include "obb_tree_node.h"
[4531]20#include "obb.h"
[4546]21#include "debug.h"
[4550]22#include "compiler.h"
[4616]23#include "material.h"
[5026]24#include "world_entity.h"
[4700]25#include "p_node.h"
[4510]26
27using namespace std;
28
29
30/**
[4836]31 *  standard constructor
[4510]32*/
[4573]33OBBTree::OBBTree ()
[4510]34{
[4682]35  this->init();
36}
37
38OBBTree::OBBTree(int depth, sVec3D *verticesList, const int length)
39{
40  this->init();
41  this->spawnBVTree(depth, verticesList, length);
42}
43
[5684]44OBBTree::OBBTree(int depth, const modelInfo& modInfo)
45{
46  this->init();
47  this->spawnBVTree(depth, modInfo);
48}
[4682]49
50
[5684]51
[4682]52void OBBTree::init()
53{
[4616]54  this->setClassID(CL_OBB_TREE, "OBBTree");
[4622]55
[5115]56  this->rootNode = NULL;
57
[4638]58  this->id = 0;
[4510]59}
60
61/**
[4836]62 *  standard deconstructor
[4510]63
64*/
[4573]65OBBTree::~OBBTree ()
[4510]66{
[4814]67  delete this->rootNode;
[4510]68}
[4528]69
70
[4551]71void OBBTree::spawnBVTree(int depth, sVec3D *verticesList, const int length)
[4531]72{
[4551]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;
[4622]80  this->rootNode->setTreeRef(this);
[4626]81  this->rootNode->spawnBVTree(--depth, verticesList, length);
[4531]82}
[4528]83
84
[5702]85void OBBTree::spawnBVTree(int depth, const modelInfo& modelInf)
[5684]86{
87  if( unlikely(this->rootNode != NULL))
88  {
89    PRINTF(2)("The BVTree has already been spawned, flushing and respawning again...\n");
90    this->flushTree();
91  }
92  OBBTreeNode* node = new OBBTreeNode();
93  this->rootNode = node;
94  this->rootNode->setTreeRef(this);
[5702]95 
96  /* triangles indexes created */
97  int* triangleIndexes = new int[modelInf.numTriangles];
98 
99  this->rootNode->spawnBVTree(--depth, modelInf, triangleIndexes, modelInf.numTriangles);
[5684]100}
101
102
[4528]103void OBBTree:: flushTree()
104{}
105
106
[5026]107void OBBTree::collideWith(WorldEntity* entity1, WorldEntity* entity2)
108{
[5027]109  if( likely(entity2->getOBBTree() != NULL) )
[5028]110    this->rootNode->collideWith(((OBBTree*)entity2->getOBBTree())->getRootNode(), entity1, entity2);
[5026]111}
112
113
114/**
115 * this collides two bvtrees together. the trees are attached to pnodes Objects A and B
116 * @param tree: the other tree to collide with (Object B)
117 * @param nodeA: PNode of object A
118 * @param nodeB: Pnode of object B
119 */
[5028]120void OBBTree::collideWith(BVTree* tree, WorldEntity* nodeA, WorldEntity* nodeB)
[4695]121{
[4700]122  this->rootNode->collideWith(((OBBTree*)tree)->getRootNode(), nodeA, nodeB);
[4695]123}
[4528]124
125
[4635]126void OBBTree::drawBV(int depth, int drawMode) const
[4550]127{
128  if( likely(this->rootNode != NULL))
[4581]129  {
[4635]130    this->rootNode->drawBV(depth, drawMode);
[4581]131  }
[4550]132}
[4528]133
134
135
[4546]136void OBBTree::debug()
137{
138  PRINT(0)("\n==============================| OBBTree::debug() |===\n");
139  PRINT(0)("=  Spawning Tree: Start\n");
[4573]140
[4551]141  /* generate some test vertices */
[4638]142  int const length = 9;
[4589]143  sVec3D* vertList = new sVec3D[length];
[4668]144//   sVec3D data[length]  = {{0.0, 0.0, 0.0},{1.0, 2.0, 5.0},{0.0, 6.0, 9.0},
145//                           {1.0, 4.0, 12.0}, {1.0, 2.0, 16.0}, {0.0, 0.0, 19.0},
146//                           {0.0, 3.0, 23.0}, {1.0, 5.0, 30.0}, {0.0, 10.0, 35.0}};
[4551]147
[4668]148  sVec3D data[length]  = {{0.0, 0.0, 0.0},{1.0, 2.0, 5.0},{1.0, 5.0, 30.0},
149                          {0.0, 3.0, 23.0}, {0.0, 6.0, 9.0}, {0.0, 10.0, 35.0},
150                          {1.0, 4.0, 12.0}, {1.0, 2.0, 16.0}, {0.0, 0.0, 19.0}};
151
[4589]152  for(int i = 0; i < length; ++i)
[4553]153    {
154      vertList[i][0] = data[i][0];
155      vertList[i][1] = data[i][1];
156      vertList[i][2] = data[i][2];
157    }
158
[4638]159  this->spawnBVTree(3, vertList, length);
[4551]160
[4546]161  PRINT(0)("=  Spawning Tree: Finished\n");
[4573]162  PRINT(0)("=======================================================\n");
[4546]163
164}
Note: See TracBrowser for help on using the repository browser.