Changeset 4922 in orxonox.OLD for orxonox/trunk/src
- Timestamp:
- Jul 21, 2005, 3:59:28 PM (19 years ago)
- Location:
- orxonox/trunk/src/lib/graphics/spatial_separation
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.cc
r4921 r4922 64 64 printf("node %i, %f, %f \n", i, this->nodes[i]->getDimension()->getCenter()->x, this->nodes[i]->getDimension()->getCenter()->z); 65 65 } 66 67 this->quadLength = this->nodes[0]->getDimension()->getAxis() * 2.0f; 68 Rectangle* r = this->rootNode->getDimension(); 69 70 Vector* offset = new Vector(); 71 float xOff = r->getCenter()->x - r->getAxis(); 72 float yOff = r->getCenter()->z - r->getAxis(); 73 this->offset->x = xOff; 74 this->offset->z = yOff; 75 76 this->maxIndex = (int)pow(2, this->treeDepth); 66 77 } 67 78 … … 76 87 delete [] this->nodes; 77 88 delete this->rootNode; 89 delete offset; 78 90 } 79 91 80 92 81 93 /** 94 \brief this function rotates the array and mirrors it in the middle 95 \param nodes: the nodes to translate 82 96 83 97 since the original matrix is counted from the right upper edge to the right lower one, we have to reorganize the elements … … 108 122 } 109 123 124 /** 125 \brief sorts the hash table using their positions 126 \param nodes the nodes to use 110 127 128 */ 111 129 void Quadtree::sortHashTable(QuadtreeNode** nodes) 112 130 { 113 131 int len = (int)pow(2, this->treeDepth); //!< the length of a quadtree side 114 float a,b; 115 QuadtreeNode* tmpNode; 132 float a; //!< temp place for float a 133 float b; //!< temp place for float b 134 QuadtreeNode* tmpNode; //!< tmp place for a QuadtreeNode 116 135 117 for( int i = 0; i < len; ++i)136 for( int i = 0; i < len; ++i) 118 137 { 119 for( int j = 0; j < len; ++j)138 for( int j = 0; j < len; ++j) 120 139 { 121 for( int k = j + 1; k < len; ++k)140 for( int k = j + 1; k < len; ++k) 122 141 { 123 142 a = this->nodes[i * len + j]->getDimension()->getCenter()->z; … … 131 150 } 132 151 } 152 } 153 } 133 154 134 }135 136 }137 155 } 138 156 139 157 158 /** 159 \brief maps a position to a quadtree 160 \param position the position so look for 161 \return the quadtree 140 162 163 this function will return the quadtree that contains the position 164 */ 141 165 QuadtreeNode* Quadtree::getQuadtreeFromPosition(const Vector& position) 142 166 { 143 Vector v = position; 144 Rectangle* r = this->rootNode->getDimension(); 145 float len = this->nodes[0]->getDimension()->getAxis() * 2.0f; 167 /* shift into model space */ 168 Vector v = position - *this->offset; 169 /* map */ 170 int i = (int)(v.x / quadLength); 171 int j = (int)(v.z / quadLength); 146 172 147 Vector edge; 148 float xOff = r->getCenter()->x - r->getAxis(); 149 float yOff = r->getCenter()->z - r->getAxis(); 150 edge.x = xOff, edge.z = yOff; 151 152 /* shift into model space */ 153 v = position - edge; 154 /* map */ 155 int i = (int)(v.x / len); 156 int j = (int)(v.z / len); 157 158 int max = (int)pow(2, this->treeDepth); 159 160 if( i < max && j < max) 161 { 162 printf("-----------\nthe array coordinates are: %i, %i\n", i, j); 163 printf("position: %f,%f, center %f, %f\n", position.x, position.z, this->nodes[i + j * max]->getDimension()->getCenter()->x, this->nodes[i + j * max]->getDimension()->getCenter()->z); 164 165 //this->nodes[i + j * max]->draw(); 166 this->nodes[i + j * max]->includesPoint(position); 167 } 173 /* check if object is still inside the terrain */ 174 if( i < this->maxIndex && j < this->maxIndex) 175 this->nodes[i + j * this->maxIndex]->includesPoint(position); 168 176 else 169 printf("object has left terrain\n");177 PRINTF(0)("Object has left terrain\n"); 170 178 } 171 179 … … 174 182 * draws the debug quadtree boxes around the model 175 183 */ 176 void Quadtree::drawTree( int depth, int drawMode) const184 void Quadtree::drawTree() const 177 185 { 178 //this->rootNode->drawTree(depth, drawMode); 179 for(int i = 0; i < (int)pow(4, this->treeDepth); ++i) 180 { 181 this->nodes[i]->draw(); 182 } 183 184 186 this->rootNode->drawTree(); 187 // for(int i = 0; i < (int)pow(4, this->treeDepth); ++i) 188 // { 189 // this->nodes[i]->draw(); 190 // } 185 191 } -
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.h
r4920 r4922 26 26 QuadtreeNode* getQuadtreeFromPosition(const Vector& position); 27 27 28 void drawTree( int depth, int drawMode) const;28 void drawTree() const; 29 29 inline Material* getMaterial(int indexNode) const { return this->materials[indexNode % 4]; } 30 30 … … 38 38 int treeDepth; //!< depth of the tree 39 39 40 float quadLength; //!< length of the leaf quadtree nodes 41 Vector* offset; //!< vector to the left lower corner of the root quadtree node 42 int maxIndex; //!< maximal index for the nodes array 43 40 44 Material** materials; //!< materials for debug drawing purposes 41 45 -
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.cc
r4921 r4922 135 135 136 136 137 /** 138 139 */ 137 140 void QuadtreeNode::buildHashTable(QuadtreeNode** nodeList, int* index) 138 141 { … … 362 365 Vector center = *this->pDimension->getCenter(); 363 366 float ax = this->pDimension->getAxis(); 367 364 368 if( v.x > center.x - ax && v.x < center.x + ax && 365 369 v.z > center.z - ax && v.z < center.z + ax ) 366 printf("THIS POINT IS INSIDE :) \n"); 367 else 368 printf("POINT IS NOT INSIEDE\n"); 369 this->bDraw = true; 370 } 370 { 371 this->bDraw = true; 372 return true; 373 } 374 return false; 375 } 376 371 377 372 378 /** 373 379 * draws the debug quadtree boxes around the model 374 380 */ 375 void QuadtreeNode::drawTree( int depth, int drawMode) const381 void QuadtreeNode::drawTree() const 376 382 { 377 383 if( this->treeDepth == this->maxDepth) … … 381 387 float h = 50.0f; 382 388 383 //printf("draw @ %f, %f to %f, %f", t1.x + ax, t1.z + ax, t1.x - ax, t1.z - ax);384 385 389 this->quadtree->getMaterial(this->indexNode)->select(); 386 390 glBegin(GL_QUADS); 387 glVertex3f(t1.x + ax, h - depth * 10.0f, t1.z + ax);388 glVertex3f(t1.x - ax, h - depth * 10.0f, t1.z + ax);389 glVertex3f(t1.x - ax, h - depth * 10.0f, t1.z - ax);390 glVertex3f(t1.x + ax, h - depth * 10.0f, t1.z - ax);391 glVertex3f(t1.x + ax, h - this->treeDepth * 10.0f, t1.z + ax); 392 glVertex3f(t1.x - ax, h - this->treeDepth * 10.0f, t1.z + ax); 393 glVertex3f(t1.x - ax, h - this->treeDepth * 10.0f, t1.z - ax); 394 glVertex3f(t1.x + ax, h - this->treeDepth * 10.0f, t1.z - ax); 391 395 glEnd(); 392 396 } … … 394 398 395 399 if( this->nodeA != NULL) 396 this->nodeA->drawTree( depth - 1, drawMode);400 this->nodeA->drawTree(); 397 401 if( this->nodeB != NULL) 398 this->nodeB->drawTree( depth - 1, drawMode);402 this->nodeB->drawTree(); 399 403 if( this->nodeC != NULL) 400 this->nodeC->drawTree( depth - 1, drawMode);404 this->nodeC->drawTree(); 401 405 if( this->nodeD != NULL) 402 this->nodeD->drawTree(depth - 1, drawMode); 403 } 406 this->nodeD->drawTree(); 407 } 408 404 409 405 410 void QuadtreeNode::draw() const … … 411 416 float h = 70.0f; 412 417 413 //printf("draw @ %f, %f to %f, %f", t1.x + ax, t1.z + ax, t1.x - ax, t1.z - ax);414 415 418 glBegin(GL_QUADS); 416 419 this->quadtree->getMaterial(this->indexNode)->select(); 417 // for( int i = 0; i < 50; ++i) 418 // { 419 int i = 0; 420 glVertex3f(t1.x + ax, h + 10.0f * i, t1.z + ax); 421 glVertex3f(t1.x - ax, h + 10.0f * i, t1.z + ax); 422 glVertex3f(t1.x - ax, h + 10.0f * i, t1.z - ax); 423 glVertex3f(t1.x + ax, h + 10.0f * i, t1.z - ax); 424 // } 420 421 glVertex3f(t1.x + ax, h, t1.z + ax); 422 glVertex3f(t1.x - ax, h, t1.z + ax); 423 glVertex3f(t1.x - ax, h, t1.z - ax); 424 glVertex3f(t1.x + ax, h, t1.z - ax); 425 425 426 glEnd(); 426 427 -
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.h
r4921 r4922 34 34 bool includesPoint(const Vector& v); 35 35 36 void drawTree( int depth, int drawMode) const;36 void drawTree() const; 37 37 void draw() const; 38 38 -
orxonox/trunk/src/lib/graphics/spatial_separation/spatial_separation.cc
r4921 r4922 99 99 Quadtree* SpatialSeparation::createQuadtree(AbstractModel* model) 100 100 { 101 this->quadtree = new Quadtree(model->getModelInfo(), 5);101 this->quadtree = new Quadtree(model->getModelInfo(), 4); 102 102 103 103 return this->quadtree; 104 104 } 105 106 107 108 109 110 105 111 106 … … 116 111 return; 117 112 118 this->quadtree->drawTree( 4, 0);113 this->quadtree->drawTree(); 119 114 } 120 115
Note: See TracChangeset
for help on using the changeset viewer.