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