Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5703 was 5703, checked in by patrick, 18 years ago

collision_detection: cleanup and recode of some small parts.

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