Changeset 4922 in orxonox.OLD for orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.cc
- Timestamp:
- Jul 21, 2005, 3:59:28 PM (19 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.