Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5922 was 5882, checked in by patrick, 19 years ago

collision_detection: very much work on the cd engine, now the obbs do assemble again, but not yet correctly. Much more debug work to come..

File size: 3.1 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
[5713]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
27using namespace std;
28
29
30/**
[4836]31 *  standard constructor
[4510]32*/
[5716]33OBBTree::OBBTree(int depth, const modelInfo& modelInf)
34  : BVTree()
[5684]35{
[5716]36  this->depth = depth;
[5684]37  this->init();
[5716]38  this->spawnBVTree(modelInf);
[5684]39}
[4682]40
41
[5684]42
[4682]43void OBBTree::init()
44{
[4616]45  this->setClassID(CL_OBB_TREE, "OBBTree");
[5115]46  this->rootNode = NULL;
[4638]47  this->id = 0;
[4510]48}
49
50/**
[4836]51 *  standard deconstructor
[4510]52
53*/
[4573]54OBBTree::~OBBTree ()
[4510]55{
[4814]56  delete this->rootNode;
[4510]57}
[4528]58
59
60
[5716]61void OBBTree::spawnBVTree(const modelInfo& modelInf)
[5684]62{
63  if( unlikely(this->rootNode != NULL))
64  {
65    PRINTF(2)("The BVTree has already been spawned, flushing and respawning again...\n");
66    this->flushTree();
67  }
[5717]68  this->rootNode = new OBBTreeNode(*this, depth-1);
[5713]69
[5702]70  /* triangles indexes created */
71  int* triangleIndexes = new int[modelInf.numTriangles];
[5705]72  for(int i = 0; i < modelInf.numTriangles; ++i)
73    triangleIndexes[i] = i;
[5713]74
[5716]75  this->rootNode->spawnBVTree(modelInf, triangleIndexes, modelInf.numTriangles);
[5684]76}
77
78
[5717]79
80
[4528]81void OBBTree:: flushTree()
82{}
83
84
[5026]85/**
86 * this collides two bvtrees together. the trees are attached to pnodes Objects A and B
87 * @param nodeA: PNode of object A
88 * @param nodeB: Pnode of object B
89 */
[5718]90void OBBTree::collideWith(const WorldEntity& entity1, const WorldEntity& entity2) const
[4695]91{
[5718]92  if( likely(entity2.getOBBTree() != NULL) )
93    this->rootNode->collideWith(*(((OBBTree*)entity2.getOBBTree())->getRootNode()), entity1, entity2);
[4695]94}
[4528]95
96
[5718]97
[4635]98void OBBTree::drawBV(int depth, int drawMode) const
[4550]99{
100  if( likely(this->rootNode != NULL))
[4581]101  {
[4635]102    this->rootNode->drawBV(depth, drawMode);
[4581]103  }
[4550]104}
[4528]105
106
107
[4546]108void OBBTree::debug()
109{
110  PRINT(0)("\n==============================| OBBTree::debug() |===\n");
111  PRINT(0)("=  Spawning Tree: Start\n");
[4573]112
[4551]113  /* generate some test vertices */
[4638]114  int const length = 9;
[4589]115  sVec3D* vertList = new sVec3D[length];
[4668]116//   sVec3D data[length]  = {{0.0, 0.0, 0.0},{1.0, 2.0, 5.0},{0.0, 6.0, 9.0},
117//                           {1.0, 4.0, 12.0}, {1.0, 2.0, 16.0}, {0.0, 0.0, 19.0},
118//                           {0.0, 3.0, 23.0}, {1.0, 5.0, 30.0}, {0.0, 10.0, 35.0}};
[4551]119
[4668]120  sVec3D data[length]  = {{0.0, 0.0, 0.0},{1.0, 2.0, 5.0},{1.0, 5.0, 30.0},
121                          {0.0, 3.0, 23.0}, {0.0, 6.0, 9.0}, {0.0, 10.0, 35.0},
122                          {1.0, 4.0, 12.0}, {1.0, 2.0, 16.0}, {0.0, 0.0, 19.0}};
123
[4589]124  for(int i = 0; i < length; ++i)
[4553]125    {
126      vertList[i][0] = data[i][0];
127      vertList[i][1] = data[i][1];
128      vertList[i][2] = data[i][2];
129    }
130
[5882]131//   this->spawnBVTree(vertList, length);
[4551]132
[4546]133  PRINT(0)("=  Spawning Tree: Finished\n");
[4573]134  PRINT(0)("=======================================================\n");
[4546]135
136}
Note: See TracBrowser for help on using the repository browser.