Changeset 4924 in orxonox.OLD for orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.cc
- Timestamp:
- Jul 21, 2005, 4:46:41 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.cc
r4923 r4924 9 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: Patrick Boenzli 13 13 co-programmer: ... … … 19 19 20 20 #include "quadtree_node.h" 21 #include "vector.h" 22 21 23 #include "material.h" 22 #include "vector.h" 24 23 25 24 26 using namespace std; … … 27 29 /** 28 30 * standard constructor 29 @todo this constructor is not jet implemented - do it 30 */ 31 */ 31 32 Quadtree::Quadtree (modelInfo* pModelInfo, const int treeDepth) 32 33 { 33 34 35 34 this->setClassID(CL_QUADTREE, "Quadtree"); 35 this->pModelInfo = pModelInfo; 36 this->treeDepth = treeDepth; 36 37 37 38 39 40 41 42 43 44 45 46 47 38 /* initialize the materials for debug draw */ 39 this->materials = new Material*[4]; 40 for(int i = 0; i < 4; ++i) 41 { 42 materials[i] = new Material(); 43 materials[i]->setIllum(3); 44 } 45 materials[0]->setAmbient(0.0, 0.3, 0.0); 46 materials[1]->setAmbient(0.4, 0.0, 0.2); 47 materials[2]->setAmbient(1.0, 0.0, 0.0); 48 materials[3]->setAmbient(5.0, 3.0, 1.0); 48 49 49 50 50 /* build the tree */ 51 this->rootNode = new QuadtreeNode(this->pModelInfo, this, this->treeDepth); 51 52 52 53 54 55 56 57 printf("============================\n");58 this->rootNode->buildHashTable(this->nodes, index);59 }60 61 53 /* make an array with access to the leafs of the Quad-Tree */ 54 this->nodes = new QuadtreeNode*[(int)pow(4, treeDepth)]; 55 int* index = new int; *index = 0; 56 for(int i = 0; i < (int)pow(2, treeDepth); ++i) 57 { 58 this->rootNode->buildHashTable(this->nodes, index); 59 } 60 /* sort and revert the hash table to fit the right position */ 61 this->sortHashTable(this->nodes); 62 this->revertHashTable(this->nodes); 62 63 63 for(int i = 0; i < (int)pow(4, treeDepth); ++i) 64 { 65 printf("node %i, %f, %f \n", i, this->nodes[i]->getDimension()->getCenter()->x, this->nodes[i]->getDimension()->getCenter()->z); 66 } 67 68 this->quadLength = this->nodes[0]->getDimension()->getAxis() * 2.0f; 69 Rectangle* r = this->rootNode->getDimension(); 70 71 Vector* offset = new Vector(); 72 float xOff = r->getCenter()->x - r->getAxis(); 73 float yOff = r->getCenter()->z - r->getAxis(); 74 this->offset->x = xOff; 75 this->offset->z = yOff; 76 77 this->maxIndex = (int)pow(2, this->treeDepth); 64 /* define some important and often used variables */ 65 this->quadLength = this->nodes[0]->getDimension()->getAxis() * 2.0f; 66 Rectangle* r = this->rootNode->getDimension(); 67 Vector* offset = new Vector(); 68 float xOff = r->getCenter()->x - r->getAxis(); 69 float yOff = r->getCenter()->z - r->getAxis(); 70 this->offset->x = xOff; 71 this->offset->z = yOff; 72 this->maxIndex = (int)pow(2, this->treeDepth); 78 73 } 79 74 … … 81 76 /** 82 77 * standard deconstructor 83 84 */ 78 */ 85 79 Quadtree::~Quadtree () 86 80 { … … 93 87 94 88 /** 95 \briefthis function rotates the array and mirrors it in the middle96 \param nodes: the nodes to translate89 * this function rotates the array and mirrors it in the middle 90 * @param nodes: the nodes to translate 97 91 98 92 since the original matrix is counted from the right upper edge to the right lower one, we have to reorganize the elements … … 123 117 } 124 118 119 125 120 /** 126 \brief sorts the hash table using their positions 127 \param nodes the nodes to use 128 121 * sorts the hash table using their positions 122 * @param nodes the nodes to use 129 123 */ 130 124 void Quadtree::sortHashTable(QuadtreeNode** nodes) … … 158 152 159 153 /** 160 \briefmaps a position to a quadtree161 \param position the position so look for162 \return the quadtree154 * maps a position to a quadtree 155 * @param position the position so look for 156 * @return the quadtree 163 157 164 158 this function will return the quadtree that contains the position
Note: See TracChangeset
for help on using the changeset viewer.