Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9424 was 9406, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File size: 3.7 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
[7711]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION
[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
27
28
[9406]29
[4510]30/**
[4836]31 *  standard constructor
[4510]32*/
[7711]33OBBTree::OBBTree(int depth, const modelInfo* modelInf, WorldEntity* owner)
34  : BVTree()
[4510]35{
[7711]36  this->depth = depth;
[4682]37  this->init();
[7711]38  this->spawnBVTree(*modelInf);
39  this->owner = owner;
[4682]40}
41
42
[9235]43/**
44 *  standard constructor
45 */
46OBBTree::OBBTree()
47  : BVTree()
48{}
[4682]49
[9235]50
[4682]51void OBBTree::init()
52{
[4616]53  this->setClassID(CL_OBB_TREE, "OBBTree");
[5115]54  this->rootNode = NULL;
[4638]55  this->id = 0;
[4510]56}
57
58/**
[4836]59 *  standard deconstructor
[4510]60
61*/
[4573]62OBBTree::~OBBTree ()
[4510]63{
[4814]64  delete this->rootNode;
[4510]65}
[4528]66
67
[7711]68/**
69 *  this function creates a bv tree out of a modelInf structure
70 * @param modelInf the model info of a model (modelInfo), containing vertices, triangle and normal infos
71 */
72void OBBTree::spawnBVTree(const modelInfo& modelInf)
[4531]73{
[4551]74  if( unlikely(this->rootNode != NULL))
[5684]75  {
76    PRINTF(2)("The BVTree has already been spawned, flushing and respawning again...\n");
77    this->flushTree();
78  }
[7711]79  this->rootNode = new OBBTreeNode(*this, NULL, depth-1);
80
81  /* triangles indexes created */
82  int* triangleIndexes = new int[modelInf.numTriangles];
[8316]83  for(unsigned int i = 0; i < modelInf.numTriangles; ++i)
[7711]84    triangleIndexes[i] = i;
85
86  this->rootNode->spawnBVTree(modelInf, triangleIndexes, modelInf.numTriangles);
[5684]87}
88
89
[9235]90void OBBTree::createBox(Vector start, Vector end)
91{
92  this->rootNode = new OBBTreeNode(*this, NULL, 1);
93
94  this->rootNode->createBox(start, end);
95}
96
97
[7711]98/**
99 *  release the current bv tree if any
100 */
[4528]101void OBBTree:: flushTree()
102{}
103
104
[7711]105/**
106 * this collides two bvtrees together. the trees are attached to pnodes Objects A and B
107 * @param nodeA: PNode of object A
108 * @param nodeB: Pnode of object B
109 */
[5026]110void OBBTree::collideWith(WorldEntity* entity1, WorldEntity* entity2)
111{
[5027]112  if( likely(entity2->getOBBTree() != NULL) )
[5028]113    this->rootNode->collideWith(((OBBTree*)entity2->getOBBTree())->getRootNode(), entity1, entity2);
[5026]114}
115
116
117/**
[7711]118 *  draw bv tree
[5026]119 */
[4635]120void OBBTree::drawBV(int depth, int drawMode) const
[4550]121{
122  if( likely(this->rootNode != NULL))
[4581]123  {
[4635]124    this->rootNode->drawBV(depth, drawMode);
[4581]125  }
[4550]126}
[4528]127
128
[7711]129/**
130 *  some debug output and creation function
131 *
132 * doesn't work at the moment
133 */
[4546]134void OBBTree::debug()
135{
136  PRINT(0)("\n==============================| OBBTree::debug() |===\n");
137  PRINT(0)("=  Spawning Tree: Start\n");
[4573]138
[4551]139  /* generate some test vertices */
[4638]140  int const length = 9;
[4589]141  sVec3D* vertList = new sVec3D[length];
[4668]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}};
[4551]145
[4668]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
[4589]150  for(int i = 0; i < length; ++i)
[4553]151    {
152      vertList[i][0] = data[i][0];
153      vertList[i][1] = data[i][1];
154      vertList[i][2] = data[i][2];
155    }
156
[7711]157//   this->spawnBVTree(vertList, length);
[4551]158
[4546]159  PRINT(0)("=  Spawning Tree: Finished\n");
[4573]160  PRINT(0)("=======================================================\n");
[4546]161
162}
Note: See TracBrowser for help on using the repository browser.