Changeset 4920 in orxonox.OLD for orxonox/trunk/src/lib/graphics
- Timestamp:
- Jul 21, 2005, 2:33:32 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
r4917 r4920 57 57 this->rootNode->buildHashTable(this->nodes, index); 58 58 } 59 this->sortHashTable(this->nodes); 59 60 this->revertHashTable(this->nodes); 61 62 for(int i = 0; i < (int)pow(4, treeDepth); ++i) 63 { 64 printf("node %i, %f, %f \n", i, this->nodes[i]->getDimension()->getCenter()->x, this->nodes[i]->getDimension()->getCenter()->z); 65 } 60 66 } 61 67 … … 103 109 104 110 111 void Quadtree::sortHashTable(QuadtreeNode** nodes) 112 { 113 int len = (int)pow(2, this->treeDepth); //!< the length of a quadtree side 114 float a,b; 115 QuadtreeNode* tmpNode; 116 117 for(int i = 0; i < len; ++i) 118 { 119 for(int j = 0; j < len; ++j) 120 { 121 for(int k = j + 1; k < len; ++k) 122 { 123 a = this->nodes[i * len + j]->getDimension()->getCenter()->z; 124 b = this->nodes[i * len + k]->getDimension()->getCenter()->z; 125 126 if( b > a) 127 { 128 tmpNode = this->nodes[i * len + j]; 129 this->nodes[i * len + j] = this->nodes[i * len + k]; 130 this->nodes[i * len + k] = tmpNode; 131 } 132 } 133 134 } 135 136 } 137 } 138 139 140 105 141 QuadtreeNode* Quadtree::getQuadtreeFromPosition(const Vector& position) 106 142 { … … 108 144 Rectangle* r = this->rootNode->getDimension(); 109 145 float len = this->nodes[0]->getDimension()->getAxis() * 2.0f; 146 147 Vector edge; 110 148 float xOff = r->getCenter()->x - r->getAxis(); 111 149 float yOff = r->getCenter()->z - r->getAxis(); 150 edge.x = xOff, edge.z = yOff; 112 151 113 int i = (int)(( position.x - xOff) / len) + 1; 114 int j = (int)(( position.z - yOff) / len) + 1; 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); 115 157 116 printf("the array coordinates are: %i, %i\n", i, j); 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 this->nodes[i + j * max]->drawTree(0,0); 165 this->nodes[i + j * max]->includesPoint(position); 166 } 167 else 168 printf("object has left terrain\n"); 169 117 170 } 118 171 … … 126 179 for(int i = 0; i < (int)pow(4, this->treeDepth); ++i) 127 180 { 128 this->nodes[i]->drawTree(0, 0);181 //this->nodes[i]->drawTree(0, 0); 129 182 } 130 183 -
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.h
r4915 r4920 31 31 private: 32 32 void revertHashTable(QuadtreeNode** nodes); 33 void sortHashTable(QuadtreeNode** nodes); 33 34 34 35 private: -
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.cc
r4918 r4920 357 357 358 358 359 bool QuadtreeNode::includesPoint(const Vector& v) 360 { 361 Vector center = *this->pDimension->getCenter(); 362 float ax = this->pDimension->getAxis(); 363 if( v.x > center.x - ax && v.x < center.x + ax && 364 v.z > center.z - ax && v.z < center.z + ax ) 365 printf("THIS POINT IS INSIDE :) \n"); 366 else 367 printf("POINT IS NOT INSIEDE\n"); 368 } 369 359 370 /** 360 371 * draws the debug quadtree boxes around the model -
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.h
r4917 r4920 31 31 float getHeight(const Vector& position); 32 32 Rectangle* getDimension() { return this->pDimension; } 33 34 bool includesPoint(const Vector& v); 33 35 34 36 void drawTree(int depth, int drawMode) const;
Note: See TracChangeset
for help on using the changeset viewer.