Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/collision_detection/obb_tree.cc @ 5603

Last change on this file since 5603 was 5481, checked in by bensch, 19 years ago

orxonox/trunk: BV-nodes are now renddered more efficiently.

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