Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: merged the cd branche back to trunk

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