Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

collision_detection: and again a heavy cleanup in the function arguments

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