Changeset 4845 in orxonox.OLD for orxonox/trunk/src/lib/graphics/spatial_separation
- Timestamp:
- Jul 12, 2005, 11:48:39 PM (19 years ago)
- Location:
- orxonox/trunk/src/lib/graphics/spatial_separation
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.cc
r4836 r4845 17 17 18 18 #include "quadtree.h" 19 #include "quadtree_node.h" 19 20 20 21 using namespace std; … … 29 30 this->setClassID(CL_QUADTREE, "Quadtree"); 30 31 this->pModelInfo = pModelInfo; 32 33 this->rootNode = new QuadtreeNode(this->pModelInfo); 31 34 } 32 35 -
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.h
r4836 r4845 10 10 11 11 #include "base_object.h" 12 #include " vector.h"12 #include "abstract_model.h" 13 13 14 14 class QuadtreeNode; -
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.cc
r4836 r4845 27 27 { 28 28 this->setClassID(CL_QUADTREE_NODE, "QuadtreeNode"); 29 } 30 31 32 /** 33 * standard constructor 34 */ 35 QuadtreeNode::QuadtreeNode(modelInfo* pModelInfo) 36 { 37 this->pModelInfo = pModelInfo; 38 this->getDimension(this->pModelInfo); 29 39 } 30 40 … … 61 71 void QuadtreeNode::drawTree(int depth, int drawMode) const 62 72 {} 73 74 75 76 /** 77 \brief gets the maximal dimension of a model 78 * @param playerModel the model that this measurement is based on 79 \return the dimension of the AbstractModel as a Rectangle 80 81 The rectangle is x-z axis aligned. ATTENTION: if there are any vertices in the model, that exceed the 82 size of 999999.0, there probably will be some errors in the dimensions calculations. 83 */ 84 Rectangle* QuadtreeNode::getDimension(modelInfo* pModelInfo) 85 { 86 float maxX, maxY; //!< the maximal coordinates axis 87 float minX, minY; //!< minimal axis coorindates 88 const float* pVertices; //!< pointer to the current vertices 89 90 maxX = -999999; maxY = -999999; 91 minX = 999999; minY = 999999; 92 /* get maximal/minimal x/y */ 93 for( int i = 0; i < pModelInfo->numVertices; ++i) 94 { 95 pVertices = &pModelInfo->pVertices[i * 3]; 96 if( pVertices[0] > maxX) 97 maxX = pVertices[0]; 98 if( pVertices[2] > maxY) 99 maxY = pVertices[2]; 100 101 if( pVertices[0] < minX) 102 minX = pVertices[0]; 103 if( pVertices[2] < minY) 104 minY = pVertices[2]; 105 } 106 107 Rectangle* rect = new Rectangle(); 108 rect->setCenter((maxX + minX) / 2.0f, 0.0f, (maxY + minY) / 2.0f); /* this is little strange, since y is in opengl the up vector */ 109 rect->setAxis(fmax(((fabs(maxX) + fabs(minX)) / 2.0f), ((fabs(maxY) + fabs(minY)) / 2.0f))); 110 111 PRINTF(0)("Dimension Informationation: X: min/max %f/%f Y: min/max %f/%f\n", minX, maxX, minY, maxY); 112 return rect; 113 } 114 -
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.h
r4836 r4845 1 1 /*! 2 2 \file proto_class.h 3 3 * Definition of ... 4 4 5 */5 */ 6 6 7 7 #ifndef _QUADTREE_NODE_H … … 10 10 #include "base_object.h" 11 11 #include "vector.h" 12 #include "abstract_model.h" 12 13 13 14 // FORWARD DEFINITION … … 18 19 class QuadtreeNode : public BaseObject { 19 20 20 public: 21 QuadtreeNode(sTriangleExt* triangles, int numTriangles, Quadtree* quadtree); 22 virtual ~QuadtreeNode(); 21 public: 22 QuadtreeNode(sTriangleExt* triangles, int numTriangles, Quadtree* quadtree); 23 QuadtreeNode(modelInfo* pModelInfo); 24 virtual ~QuadtreeNode(); 23 25 24 void separateNode(int treeDepth);25 void separateNode(float minLength);26 void separateNode(int treeDepth); 27 void separateNode(float minLength); 26 28 27 void drawTree(int depth, int drawMode) const;29 void drawTree(int depth, int drawMode) const; 28 30 29 31 30 private: 31 Quadtree* quadtree; //!< reference to the quadtree 32 Vector center; //!< center coordinate of the quadtree node - relative coordinates in model space(!) 33 float axisLength; //!< axis length of the quadtree 34 float maxHeigth; //!< max height of the model in the quadtree 32 private: 33 Rectangle* getDimension(modelInfo* pModelInfo); 35 34 36 sTriangleExt* triangles; //!< reference to the triangles of the node 37 unsigned int numTriangles; //!< number of triangles of the Node 38 modelInfo* pModelInfo; //!< reference to the modelInfo of the object 35 private: 36 Quadtree* quadtree; //!< reference to the quadtree 37 Vector center; //!< center coordinate of the quadtree node - relative coordinates in model space(!) 38 float axisLength; //!< axis length of the quadtree 39 float maxHeigth; //!< max height of the model in the quadtree 39 40 40 QuadtreeNode* nodeA; //!< reference to the node A 41 QuadtreeNode* nodeB; //!< reference to the node B 42 QuadtreeNode* nodeC; //!< reference to the node C 43 QuadtreeNode* nodeD; //!< reference to the node D 41 sTriangleExt* triangles; //!< reference to the triangles of the node 42 unsigned int numTriangles; //!< number of triangles of the Node 43 modelInfo* pModelInfo; //!< reference to the modelInfo of the object 44 45 QuadtreeNode* nodeA; //!< reference to the node A 46 QuadtreeNode* nodeB; //!< reference to the node B 47 QuadtreeNode* nodeC; //!< reference to the node C 48 QuadtreeNode* nodeD; //!< reference to the node D 44 49 45 50 }; -
orxonox/trunk/src/lib/graphics/spatial_separation/spatial_separation.cc
r4844 r4845 34 34 { 35 35 this->setClassID(CL_SPATIAL_SEPARATION, "SpatialSeparation"); 36 this-> getDimension(model);36 this->createQuadtree(model); 37 37 } 38 38 … … 97 97 this->quadtree->separate(); 98 98 99 99 100 return this->quadtree; 100 }101 102 103 /**104 \brief gets the maximal dimension of a model105 * @param playerModel the model that this measurement is based on106 \return the dimension of the AbstractModel as a Rectangle107 108 The rectangle is x-z axis aligned. ATTENTION: if there are any vertices in the model, that exceed the109 size of 999999.0, there probably will be some errors in the dimensions calculations.110 */111 Rectangle* SpatialSeparation::getDimension(AbstractModel* playerModel)112 {113 float maxX, maxY; //!< the maximal coordinates axis114 float minX, minY; //!< minimal axis coorindates115 const float* pVertices; //!< pointer to the current vertices116 117 maxX = -999999; maxY = -999999;118 minX = 999999; minY = 999999;119 /* get maximal/minimal x/y */120 for( int i = 0; i < playerModel->getModelInfo()->numVertices; ++i)121 {122 pVertices = &playerModel->getModelInfo()->pVertices[i * 3];123 if( pVertices[0] > maxX)124 maxX = pVertices[0];125 if( pVertices[2] > maxY)126 maxY = pVertices[2];127 128 if( pVertices[0] < minX)129 minX = pVertices[0];130 if( pVertices[2] < minY)131 minY = pVertices[2];132 }133 Rectangle* rect = new Rectangle();134 135 rect->setCenter((maxX + minX) / 2.0f, 0.0f, (maxY + minY) / 2.0f);136 137 138 PRINTF(0)("Dimension Informationation: X: min/max %f/%f Y: min/max %f/%f\n", minX, maxX, minY, maxY);139 101 } 140 102 -
orxonox/trunk/src/lib/graphics/spatial_separation/spatial_separation.h
r4844 r4845 16 16 #define SEC_OFFSET 1.0 //!< the offset added to the overlapSize to ensure that there are no problems in 17 17 18 19 //! A class that represents a rectangle, this is needed for SpatialSeparation20 class Rectangle21 {22 23 public:24 Rectangle() {}25 virtual ~Rectangle() {}26 27 /** \brief sets the center of the rectangle to a defined vector @param center the new center */28 inline void setCenter(const Vector ¢er) { this->center = center;}29 /** \brief sets the center of the rectangle to a defined vector @param x coord of the center @param y coord of the center @param z coord of the center */30 inline void setCenter(float x, float y, float z) { this->center.x = x; this->center.y = y; this->center.z = z; }31 /** \brief returns the center of the rectangle to a defined vector @returns center the new center */32 inline const Vector* getCenter() const { return &this->center; }33 34 /** \brief sets both axis of the rectangle to a defined vector @param unityLength the new center */35 inline void setAxis(float unityLength) { this->axis[0] = unityLength; this->axis[1] = unityLength; }36 /** \brief sets both axis of the rectangle to a defined vector @param v1 the length of the x axis @param v2 the length of the z axis*/37 inline void setAxis(float v1, float v2) { this->axis[0] = v1; this->axis[1] = v2; }38 39 private:40 Vector center;41 float axis[2];42 };43 18 44 19 … … 61 36 private: 62 37 void separateZone(); 63 Rectangle* getDimension(AbstractModel* playerModel);64 38 65 39
Note: See TracChangeset
for help on using the changeset viewer.