- Timestamp:
- Jul 19, 2005, 10:44:16 PM (19 years ago)
- Location:
- orxonox/trunk/src/lib/graphics/spatial_separation
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.cc
r4901 r4902 34 34 35 35 this->materials = new Material*[4]; 36 37 36 for(int i = 0; i < 4; ++i) 38 37 { … … 46 45 47 46 48 this->rootNode = new QuadtreeNode(this->pModelInfo, this ->treeDepth);47 this->rootNode = new QuadtreeNode(this->pModelInfo, this, this->treeDepth); 49 48 } 50 49 -
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.h
r4901 r4902 25 25 void drawTree(int depth, int drawMode) const; 26 26 27 Material* getMaterial(int indexNode) { return this->materials[indexNode%4]; }27 inline Material* getMaterial(int indexNode) const { return this->materials[indexNode % 4]; } 28 28 29 29 private: … … 32 32 int treeDepth; //!< depth of the tree 33 33 34 Material** materials;//!< materials for debug drawing purposes34 Material** materials; //!< materials for debug drawing purposes 35 35 }; 36 36 -
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.cc
r4900 r4902 17 17 18 18 #include "quadtree_node.h" 19 #include "quadtree.h" 20 #include "material.h" 19 21 #include "abstract_model.h" 20 22 #include "list.h" … … 64 66 * standard constructor 65 67 */ 66 QuadtreeNode::QuadtreeNode(modelInfo* pModelInfo, const int maxDepth)68 QuadtreeNode::QuadtreeNode(modelInfo* pModelInfo, Quadtree* quadtree, const int maxDepth) 67 69 { 68 70 this->pModelInfo = pModelInfo; 71 this->quadtree = quadtree; 69 72 70 73 /* create an array of triangle references */ … … 279 282 280 283 284 /** 285 \brief gets the maximal dimension of a model 286 \return the dimension of the AbstractModel as a Rectangle 287 288 The rectangle is x-z axis aligned. ATTENTION: if there are any vertices in the model, that exceed the 289 size of 999999.0, there probably will be some errors in the dimensions calculations. Write an email to 290 patrick@orxonox.ethz.ch if you will ever encounter a model bigger than 999999.0 units, I will realy be 291 happy to see orxonox used to extensivly :) 292 */ 293 Rectangle* QuadtreeNode::getDimFromModel() 294 { 295 float maxX, maxY; //!< the maximal coordinates axis 296 float minX, minY; //!< minimal axis coorindates 297 const float* pVertices; //!< pointer to the current vertices 298 299 maxX = -999999; maxY = -999999; 300 minX = 999999; minY = 999999; 301 /* get maximal/minimal x/y */ 302 for( int i = 0; i < this->numTriangles; ++i) 303 { 304 for( int j = 0; j < 3; ++j) 305 { 306 307 pVertices = &this->pVertices[this->pTriangles[i]->indexToVertices[j]]; 308 if( pVertices[0] > maxX) 309 maxX = pVertices[0]; 310 if( pVertices[2] > maxY) 311 maxY = pVertices[2]; 312 313 if( pVertices[0] < minX) 314 minX = pVertices[0]; 315 if( pVertices[2] < minY) 316 minY = pVertices[2]; 317 } 318 } 319 320 Rectangle* rect = new Rectangle(); 321 rect->setCenter((maxX + minX) / 2.0f, 0.0f, (maxY + minY) / 2.0f); /* this is little strange, since y is in opengl the up vector */ 322 rect->setAxis(fmax(((fabs(maxX) + fabs(minX)) / 2.0f), ((fabs(maxY) + fabs(minY)) / 2.0f))); 323 324 for( int i = 0; i < this->treeDepth; ++i) 325 PRINT(3)(" |"); 326 PRINT(3)(" | +-| (II) Rectangle Dimension (%5.2f, %5.2f) to (%5.2f, %5.2f), Center (%5.2f, %5.2f)\n", minX, minY, maxX, maxY, rect->getCenter()->x, rect->getCenter()->z, rect->getAxis()); 327 return rect; 328 } 329 281 330 282 331 /** … … 291 340 292 341 glBegin(GL_QUADS); 342 this->quadtree->getMaterial(this->indexNode)->select(); 293 343 glVertex3f(t1.x + ax, h - depth * 10.0f, t1.z + ax); 294 344 glVertex3f(t1.x - ax, h - depth * 10.0f, t1.z + ax); … … 306 356 this->nodeD->drawTree(depth - 1, drawMode); 307 357 } 308 309 310 311 /**312 \brief gets the maximal dimension of a model313 \return the dimension of the AbstractModel as a Rectangle314 315 The rectangle is x-z axis aligned. ATTENTION: if there are any vertices in the model, that exceed the316 size of 999999.0, there probably will be some errors in the dimensions calculations. Write an email to317 patrick@orxonox.ethz.ch if you will ever encounter a model bigger than 999999.0 units, I will realy be318 happy to see orxonox used to extensivly :)319 */320 Rectangle* QuadtreeNode::getDimFromModel()321 {322 float maxX, maxY; //!< the maximal coordinates axis323 float minX, minY; //!< minimal axis coorindates324 const float* pVertices; //!< pointer to the current vertices325 326 maxX = -999999; maxY = -999999;327 minX = 999999; minY = 999999;328 /* get maximal/minimal x/y */329 for( int i = 0; i < this->numTriangles; ++i)330 {331 for( int j = 0; j < 3; ++j)332 {333 334 pVertices = &this->pVertices[this->pTriangles[i]->indexToVertices[j]];335 if( pVertices[0] > maxX)336 maxX = pVertices[0];337 if( pVertices[2] > maxY)338 maxY = pVertices[2];339 340 if( pVertices[0] < minX)341 minX = pVertices[0];342 if( pVertices[2] < minY)343 minY = pVertices[2];344 }345 }346 347 Rectangle* rect = new Rectangle();348 rect->setCenter((maxX + minX) / 2.0f, 0.0f, (maxY + minY) / 2.0f); /* this is little strange, since y is in opengl the up vector */349 rect->setAxis(fmax(((fabs(maxX) + fabs(minX)) / 2.0f), ((fabs(maxY) + fabs(minY)) / 2.0f)));350 351 for( int i = 0; i < this->treeDepth; ++i)352 PRINT(3)(" |");353 PRINT(3)(" | +-| (II) Rectangle Dimension (%5.2f, %5.2f) to (%5.2f, %5.2f), Center (%5.2f, %5.2f)\n", minX, minY, maxX, maxY, rect->getCenter()->x, rect->getCenter()->z, rect->getAxis());354 return rect;355 }356 -
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.h
r4900 r4902 24 24 Quadtree* quadtree, QuadtreeNode* parent, 25 25 Rectangle* rect, int treeDepth, const int maxDepth, int index); 26 QuadtreeNode(modelInfo* pModelInfo, const int maxDepth);26 QuadtreeNode(modelInfo* pModelInfo, Quadtree* quadtree, const int maxDepth); 27 27 virtual ~QuadtreeNode(); 28 28
Note: See TracChangeset
for help on using the changeset viewer.