Changeset 7365 in orxonox.OLD for branches/cd/src/lib/collision_detection/obb_tree_node.cc
- Timestamp:
- Apr 25, 2006, 3:17:20 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/cd/src/lib/collision_detection/obb_tree_node.cc
r6617 r7365 11 11 ### File Specific: 12 12 main-programmer: Patrick Boenzli 13 co-programmer: ...14 13 */ 15 14 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION 15 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION 17 16 18 17 #include "obb_tree_node.h" 19 #include " list.h"18 #include "obb_tree.h" 20 19 #include "obb.h" 21 #include "obb_tree.h" 20 22 21 #include "matrix.h" 23 22 #include "model.h" … … 26 25 27 26 #include "color.h" 28 27 #include "glincl.h" 28 29 #include <list> 30 #include <vector> 29 31 #include "debug.h" 30 #include "glincl.h"31 32 32 33 … … 34 35 using namespace std; 35 36 36 OBBTree* OBBTreeNode::obbTree = NULL; 37 38 float** OBBTreeNode::coMat = NULL; 39 float** OBBTreeNode::eigvMat = NULL; 40 float* OBBTreeNode::eigvlMat = NULL; 41 int* OBBTreeNode::rotCount = NULL; 37 42 38 GLUquadricObj* OBBTreeNode_sphereObj = NULL; 39 43 40 44 41 /** 45 42 * standard constructor 43 * @param tree: reference to the obb tree 44 * @param depth: the depth of the obb tree to generate 46 45 */ 47 OBBTreeNode::OBBTreeNode () 46 OBBTreeNode::OBBTreeNode (const OBBTree& tree, OBBTreeNode* prev, int depth) 47 : BVTreeNode() 48 48 { 49 49 this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode"); 50 51 this->obbTree = &tree; 52 this->nodePrev = prev; 53 this->depth = depth; 54 this->nextID = 0; 55 50 56 this->nodeLeft = NULL; 51 57 this->nodeRight = NULL; 52 58 this->bvElement = NULL; 53 59 54 if( OBBTreeNode::coMat == NULL) 55 { 56 OBBTreeNode::coMat = new float*[4]; 57 for(int i = 0; i < 4; i++) 58 OBBTreeNode::coMat[i] = new float[4]; 59 } 60 if( OBBTreeNode::eigvMat == NULL) 61 { 62 OBBTreeNode::eigvMat = new float*[4]; 63 for( int i = 0; i < 4; i++) 64 OBBTreeNode::eigvMat[i] = new float[4]; 65 } 66 if( OBBTreeNode::eigvlMat == NULL) 67 { 68 OBBTreeNode::eigvlMat = new float[4]; 69 } 70 if( OBBTreeNode::rotCount == NULL) 71 OBBTreeNode::rotCount = new int; 60 this->triangleIndexList1 = NULL; 61 this->triangleIndexList2 = NULL; 62 63 this->modelInf = NULL; 64 this->triangleIndexes = NULL; 72 65 73 66 if( OBBTreeNode_sphereObj == NULL) 74 67 OBBTreeNode_sphereObj = gluNewQuadric(); 68 69 this->owner = NULL; 70 71 /* debug ids */ 72 if( this->nodePrev) 73 this->treeIndex = 100 * this->depth + this->nodePrev->getID(); 74 else 75 this->treeIndex = 0; 75 76 } 76 77 … … 82 83 { 83 84 if( this->nodeLeft) 84 {85 85 delete this->nodeLeft; 86 this->nodeLeft = NULL;87 }88 86 if( this->nodeRight) 89 {90 87 delete this->nodeRight; 91 this->nodeRight = NULL; 92 } 88 93 89 if( this->bvElement) 94 90 delete this->bvElement; 95 this->bvElement = NULL; 91 92 // if( this->triangleIndexList1 != NULL) 93 // delete [] this->triangleIndexList1; 94 // if( this->triangleIndexList2 != NULL) 95 // delete [] this->triangleIndexList2; 96 96 } 97 97 … … 105 105 * on the triangle informations (triangle soup not polygon soup) 106 106 */ 107 void OBBTreeNode::spawnBVTree(const int depth, const modelInfo& modInfo) 108 { 109 int length = 0; 110 sVec3D* verticesList; 111 112 PRINT(3)("\n"); 113 this->treeIndex = this->obbTree->getID(); 114 PRINTF(3)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length); 107 void OBBTreeNode::spawnBVTree(const modelInfo& modelInf, const int* triangleIndexes, int length) 108 { 109 PRINTF(3)("\n==============================Creating OBB Tree Node==================\n"); 110 PRINT(3)(" OBB Tree Infos: \n"); 111 PRINT(3)("\tDepth: %i \n\tTree Index: %i \n\tNumber of Triangles: %i\n", depth, this->treeIndex, length); 115 112 this->depth = depth; 116 113 117 118 114 this->bvElement = new OBB(); 119 this->bvElement->vertices = verticesList; 120 this->bvElement->numOfVertices = length; 121 PRINTF(3)("Created OBBox\n"); 122 this->calculateBoxCovariance(this->bvElement, modInfo); 123 PRINTF(3)("Calculated attributes1\n"); 124 this->calculateBoxEigenvectors(this->bvElement, modInfo); 125 PRINTF(3)("Calculated attributes2\n"); 126 this->calculateBoxAxis(this->bvElement,modInfo); 127 PRINTF(3)("Calculated attributes3\n"); 128 129 /* if this is the first node, the vertices data are the original ones of the model itself, so dont delete them in cleanup */ 130 if( this->treeIndex == 1) 131 this->bvElement->bOrigVertices = true; 132 115 this->bvElement->modelInf = &modelInf; 116 this->bvElement->triangleIndexes = triangleIndexes; 117 this->bvElement->triangleIndexesLength = length; 118 119 /* create the bounding boxes in three steps */ 120 this->calculateBoxCovariance(*this->bvElement, modelInf, triangleIndexes, length); 121 this->calculateBoxEigenvectors(*this->bvElement, modelInf, triangleIndexes, length); 122 this->calculateBoxAxis(*this->bvElement, modelInf, triangleIndexes, length); 123 124 /* do we need to descent further in the obb tree?*/ 133 125 if( likely( this->depth > 0)) 134 126 { 135 this->forkBox(this->bvElement); 136 137 138 // if(this->tmpLen1 > 2) 139 // { 140 // OBBTreeNode* node1 = new OBBTreeNode(); 141 // this->nodeLeft = node1; 142 // this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1); 143 // } 144 // else 145 // { 146 // PRINTF(3)("Aboarding tree walk: less than 3 vertices left\n"); 147 // } 148 // 149 // if( this->tmpLen2 > 2) 150 // { 151 // OBBTreeNode* node2 = new OBBTreeNode(); 152 // this->nodeRight = node2; 153 // this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2); 154 // } 155 // else 156 // { 157 // PRINTF(3)("Abording tree walk: less than 3 vertices left\n"); 158 // } 159 160 } 161 } 127 this->forkBox(*this->bvElement); 128 129 if( this->triangleIndexLength1 >= 3) 130 { 131 this->nodeLeft = new OBBTreeNode(*this->obbTree, this, depth - 1); 132 this->nodeLeft->spawnBVTree(modelInf, this->triangleIndexList1, this->triangleIndexLength1); 133 } 134 if( this->triangleIndexLength2 >= 3) 135 { 136 this->nodeRight = new OBBTreeNode(*this->obbTree, this, depth - 1); 137 this->nodeRight->spawnBVTree(modelInf, this->triangleIndexList2, this->triangleIndexLength2); 138 } 139 } 140 } 141 162 142 163 143 164 144 /** 165 * c reates a new BVTree or BVTree partition166 * @param depth: how much more depth-steps to go: if == 1 don't go any deeper!167 * @param verticesList: the list of vertices of the object - each vertices triple is interpreted as a triangle168 * 169 * this function creates an Bounding Volume tree from a vertices soup (no triangle data)145 * calculate the box covariance matrix 146 * @param box: reference to the box 147 * @param modelInf: the model info structure of the model 148 * @param tirangleIndexes: an array with the indexes of the triangles inside this 149 * @param length: the length of the indexes array 170 150 */ 171 void OBBTreeNode::spawnBVTree(const int depth, const sVec3D *verticesList, unsigned int length) 172 { 173 PRINT(3)("\n"); 174 this->treeIndex = this->obbTree->getID(); 175 PRINTF(3)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length); 176 this->depth = depth; 177 178 179 this->bvElement = new OBB(); 180 this->bvElement->vertices = verticesList; 181 this->bvElement->numOfVertices = length; 182 PRINTF(3)("Created OBBox\n"); 183 this->calculateBoxCovariance(this->bvElement, verticesList, length); 184 PRINTF(3)("Calculated attributes1\n"); 185 this->calculateBoxEigenvectors(this->bvElement, verticesList, length); 186 PRINTF(3)("Calculated attributes2\n"); 187 this->calculateBoxAxis(this->bvElement, verticesList, length); 188 PRINTF(3)("Calculated attributes3\n"); 189 190 /* if this is the first node, the vertices data are the original ones of the model itself, so dont delete them in cleanup */ 191 if( this->treeIndex == 1) 192 this->bvElement->bOrigVertices = true; 193 194 if( likely( this->depth > 0)) 195 { 196 this->forkBox(this->bvElement); 197 198 199 if(this->tmpLen1 > 2) 200 { 201 OBBTreeNode* node1 = new OBBTreeNode(); 202 this->nodeLeft = node1; 203 this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1); 204 } 205 else 206 { 207 PRINTF(3)("Aboarding tree walk: less than 3 vertices left\n"); 208 } 209 210 if( this->tmpLen2 > 2) 211 { 212 OBBTreeNode* node2 = new OBBTreeNode(); 213 this->nodeRight = node2; 214 this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2); 215 } 216 else 217 { 218 PRINTF(3)("Abording tree walk: less than 3 vertices left\n"); 219 } 220 } 221 } 222 223 224 void OBBTreeNode::calculateBoxCovariance(OBB* box, const modelInfo& modInfo) 225 {} 226 227 228 void OBBTreeNode::calculateBoxCovariance(OBB* box, const sVec3D* verticesList, unsigned int length) 151 void OBBTreeNode::calculateBoxCovariance(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, int length) 229 152 { 230 153 float facelet[length]; //!< surface area of the i'th triangle of the convex hull … … 235 158 Vector t1, t2; //!< temporary values 236 159 float covariance[3][3] = {0,0,0, 0,0,0, 0,0,0};//!< the covariance matrix 237 int mode = 0; //!< mode = 0: vertex soup, no connections, mode = 1: 3 following verteces build a triangle 238 239 this->numOfVertices = length; 240 this->vertices = verticesList; 241 242 243 if( likely(mode == 0)) 244 { 245 /* fist compute all the convex hull face/facelets and centroids */ 246 for( int i = 0; i+3 < length ; i+=3) /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/ 247 { 248 p = verticesList[i]; 249 q = verticesList[i + 1]; 250 r = verticesList[i + 2]; 251 252 t1 = p - q; t2 = p - r; 253 254 /* finding the facelet surface via cross-product */ 255 facelet[i] = 0.5f * fabs( t1.cross(t2).len() ); 256 /* update the entire convex hull surface */ 257 face += facelet[i]; 258 259 /* calculate the cetroid of the hull triangles */ 260 centroid[i] = (p + q + r) * 1/3; 261 /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */ 262 center += centroid[i] * facelet[i]; 263 } 264 /* take the average of the centroid sum */ 265 center /= face; 266 PRINTF(3)("-- Calculated Center\n"); 267 268 269 /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */ 270 for( int j = 0; j < 3; ++j) 271 { 272 for( int k = 0; k < 3; ++k) 160 sVec3D* tmpVec = NULL; //!< a temp saving place for sVec3Ds 161 162 163 /* fist compute all the convex hull face/facelets and centroids */ 164 for( int i = 0; i < length ; ++i) 165 { 166 tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[0]]); 167 p = *tmpVec; 168 tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[1]]); 169 q = *tmpVec; 170 tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[2]]); 171 r = *tmpVec; 172 173 /* finding the facelet surface via cross-product */ 174 t1 = p - q; 175 t2 = p - r; 176 facelet[i] = 0.5f * fabs( t1.cross(t2).len() ); 177 /* update the entire convex hull surface */ 178 face += facelet[i]; 179 180 /* calculate the cetroid of the hull triangles */ 181 centroid[i] = (p + q + r) / 3.0f; 182 /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */ 183 center += centroid[i] * facelet[i]; 184 /* the arithmetical center */ 185 } 186 /* take the average of the centroid sum */ 187 center /= face; 188 189 190 /* now calculate the covariance matrix - if not written in three for-loops, 191 it would compute faster: minor */ 192 for( int j = 0; j < 3; ++j) 193 { 194 for( int k = 0; k < 3; ++k) 195 { 196 for( int i = 0; i < length; ++i) 273 197 { 274 for( int i = 0; i + 3 < length; i+=3)275 {276 p = verticesList[i];277 q = verticesList[i + 1];278 r = verticesList[i + 2];279 280 covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j] * p[k] + 281 q[j] * q[k] + r[j] * r[k]) - center[j] * center[k];282 }198 tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[0]]); 199 p = *tmpVec; 200 tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[1]]); 201 q = *tmpVec; 202 tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[2]]); 203 r = *tmpVec; 204 205 covariance[j][k] = facelet[i] * (9.0f * centroid[i][j] * centroid[i][k] + p[j] * p[k] + 206 q[j] * q[k] + r[j] * r[k]); 283 207 } 284 } 285 PRINTF(3)("-- Calculated Covariance\n"); 286 } 287 else if( mode == 1) 288 { 289 for( int i = 0; i + 3 < length; i+=3) /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/ 290 { 291 p = verticesList[i]; 292 q = verticesList[i + 1]; 293 r = verticesList[i + 2]; 294 295 centroid[i] = (p + q + r) / 3.0f; 296 center += centroid[i]; 297 } 298 center /= length; 299 300 for( int j = 0; j < 3; ++j) 301 { 302 for( int k = 0; k < 3; ++k) 303 { 304 for( int i = 0; i + 3 < length; i+=3) 305 { 306 p = verticesList[i]; 307 q = verticesList[i +1]; 308 r = verticesList[i + 2]; 309 310 covariance[j][k] = p[j] * p[k] + q[j] * q[k] + r[j] + r[k]; 311 } 312 covariance[j][k] /= (3.0f * length); 313 } 314 } 315 PRINTF(3)("-- Calculated Covariance\n"); 316 } 317 else if( mode == 2) 318 { 319 /* fist compute all the convex hull face/facelets and centroids */ 320 for(int i = 0; i + 3 < length; i+=3) /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/ 321 { 322 p = verticesList[i]; 323 q = verticesList[i + 1]; 324 r = verticesList[i + 2]; 325 326 t1 = p - q; t2 = p - r; 327 328 /* finding the facelet surface via cross-product */ 329 facelet[i] = 0.5f * fabs( t1.cross(t2).len() ); 330 /* update the entire convex hull surface */ 331 face += facelet[i]; 332 333 /* calculate the cetroid of the hull triangles */ 334 centroid[i] = (p + q + r) * 1/3; 335 /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */ 336 center += centroid[i] * facelet[i]; 337 } 338 /* take the average of the centroid sum */ 339 center /= face; 340 PRINTF(3)("-- Calculated Center\n"); 341 342 for( int j = 0; j < 3; ++j) 343 { 344 for( int k = 0; k < 3; ++k) 345 { 346 for( int i = 0; i + 3 < length; i+=3) 347 { 348 p = verticesList[i]; 349 q = verticesList[i +1]; 350 r = verticesList[i + 2]; 351 352 covariance[j][k] = p[j] * p[k] + q[j] * q[k] + r[j] + r[k]; 353 } 354 covariance[j][k] /= (3.0f * length); 355 } 356 } 357 PRINTF(3)("-- Calculated Covariance\n"); 358 } 359 else 360 { 361 for( int i = 0; i < length; ++i) /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/ 362 { 363 center += verticesList[i]; 364 } 365 center /= length; 366 367 for( int j = 0; j < 3; ++j) 368 { 369 for( int k = 0; k < 3; ++k) 370 { 371 for( int i = 0; i + 3 < length; i+=3) 372 { 373 p = verticesList[i]; 374 q = verticesList[i +1]; 375 r = verticesList[i + 2]; 376 377 covariance[j][k] = p[j] * p[k] + q[j] * q[k] + r[j] + r[k]; 378 } 379 covariance[j][k] /= (3.0f * length); 380 } 381 } 382 PRINTF(3)("-- Calculated Covariance\n"); 383 } 384 385 PRINTF(3)("\nVertex Data:\n"); 386 for(int i = 0; i < length; i++) 387 { 388 PRINTF(3)("vertex %i: %f, %f, %f\n", i, box->vertices[i][0], box->vertices[i][1], box->vertices[i][2]); 389 } 390 391 392 PRINTF(3)("\nCovariance Matrix:\n"); 208 covariance[j][k] = covariance[j][k] / (12.0f * face) - center[j] * center[k]; 209 } 210 } 211 for( int i = 0; i < 3; ++i) 212 { 213 box.covarianceMatrix[i][0] = covariance[i][0]; 214 box.covarianceMatrix[i][1] = covariance[i][1]; 215 box.covarianceMatrix[i][2] = covariance[i][2]; 216 } 217 box.center = center; 218 219 220 std::vector<int> vertIndexVector; //!< vertex indexes list 221 int vertIndex; //!< index to vertex 222 bool vertexFound; //!< vertex found flag 223 Vector arithCenter; //!< aritmetical center 224 225 /* calculate the arithmetical center of the box */ 226 227 /* go thourgh all vertices, add only the used vertices indexes */ 228 // for( int i = 0; i < length; ++i) 229 // { 230 // for(int j = 0; j < 3; ++j) 231 // { 232 // vertIndex = modelInf.pTriangles[triangleIndexes[i]].indexToVertices[j]; 233 // 234 // vertexFound = false; 235 // for( int i = 0; i < vertIndexVector.size(); i++) 236 // { 237 // if( vertIndexVector[i] == vertIndex) 238 // vertexFound = true; 239 // } 240 // if( !vertexFound) 241 // vertIndexVector.push_back(vertIndex); 242 // } 243 // } 244 // /* now realy calculate the center */ 245 // for( int i = 0; i < vertIndexVector.size(); ++i) 246 // { 247 // tmpVec = (sVec3D*)(&modelInf.pVertices[vertIndexVector[i]]); 248 // arithCenter += *tmpVec; 249 // } 250 // box.arithCenter = arithCenter / vertIndexVector.size(); 251 252 253 254 /* debug output section*/ 255 PRINTF(3)("\nOBB Covariance Matrix:\n"); 393 256 for(int j = 0; j < 3; ++j) 394 257 { 395 PRINT(3)(" |");258 PRINT(3)("\t\t"); 396 259 for(int k = 0; k < 3; ++k) 397 260 { 398 PRINT(3)(" \b%f ", covariance[j][k]); 399 } 400 PRINT(3)(" |\n"); 401 } 402 403 PRINTF(3)("center: %f, %f, %f\n", center.x, center.y, center.z); 404 405 406 for(int i = 0; i < 3; ++i) 407 { 408 box->covarianceMatrix[i][0] = covariance[i][0]; 409 box->covarianceMatrix[i][1] = covariance[i][1]; 410 box->covarianceMatrix[i][2] = covariance[i][2]; 411 } 412 *box->center = center; 413 PRINTF(3)("-- Written Result to obb\n"); 414 } 415 416 417 void OBBTreeNode::calculateBoxEigenvectors(OBB* box, const modelInfo& modInfo) 418 {} 419 420 void OBBTreeNode::calculateBoxEigenvectors(OBB* box, const sVec3D* verticesList, unsigned int length) 421 { 422 423 /* now getting spanning vectors of the sub-space: 261 PRINT(3)("%11.4f\t", covariance[j][k]); 262 } 263 PRINT(3)("\n"); 264 } 265 PRINTF(3)("\nWeighteed OBB Center:\n\t\t%11.4f\t %11.4f\t %11.4f\n", center.x, center.y, center.z); 266 // PRINTF(3)("\nArithmetical OBB Center:\n\t\t%11.4f\t %11.4f\t %11.4f\n", box.arithCenter.x, box.arithCenter.y, box.arithCenter.z); 267 268 /* write back the covariance matrix data to the object oriented bouning box */ 269 } 270 271 272 273 /** 274 * calculate the eigenvectors for the object oriented box 275 * @param box: reference to the box 276 * @param modelInf: the model info structure of the model 277 * @param tirangleIndexes: an array with the indexes of the triangles inside this 278 * @param length: the length of the indexes array 279 */ 280 void OBBTreeNode::calculateBoxEigenvectors(OBB& box, const modelInfo& modelInf, 281 const int* triangleIndexes, int length) 282 { 283 284 Vector axis[3]; //!< the references to the obb axis 285 Matrix covMat( box.covarianceMatrix ); //!< covariance matrix (in the matrix dataform) 286 287 /* 288 now getting spanning vectors of the sub-space: 424 289 the eigenvectors of a symmertric matrix, such as the 425 290 covarience matrix are mutually orthogonal. … … 427 292 vectors 428 293 */ 429 Vector* axis = new Vector[3]; //!< the references to the obb axis 430 431 Matrix covMat( box->covarianceMatrix ); 294 295 /* calculate the axis */ 432 296 covMat.getEigenVectors(axis[0], axis[1], axis[2] ); 433 434 435 /* new jacobi tests */ 436 // JacobI(OBBTreeNode::coMat, OBBTreeNode::eigvlMat, OBBTreeNode::eigvMat, OBBTreeNode::rotCount); 437 // PRINTF(3)("-- Done Jacobi Decomposition\n"); 438 439 440 // PRINTF(0)("Jacobi\n"); 441 // for(int j = 0; j < 3; ++j) 442 // { 443 // printf(" |"); 444 // for(int k = 0; k < 3; ++k) 445 // { 446 // printf(" \t%f ", OBBTreeNode::OBBTreeNode::eigvMat[j][k]); 447 // } 448 // printf(" |\n"); 449 // } 450 451 /* axis[0].x = OBBTreeNode::eigvMat[0][0]; axis[0].y = OBBTreeNode::eigvMat[1][0]; axis[0].z = OBBTreeNode::eigvMat[2][0]; 452 axis[1].x = OBBTreeNode::eigvMat[0][1]; axis[1].y = OBBTreeNode::eigvMat[1][1]; axis[1].z = OBBTreeNode::eigvMat[2][1]; 453 axis[2].x = OBBTreeNode::eigvMat[0][2]; axis[2].y = OBBTreeNode::eigvMat[1][2]; axis[2].z = OBBTreeNode::eigvMat[2][2]; 454 axis[0].normalize(); 455 axis[1].normalize(); 456 axis[2].normalize();*/ 457 box->axis = axis; 458 459 // PRINTF(0)("-- Got Axis\n"); 460 // 461 // PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[0].x, box->axis[0].y, box->axis[0].z); 462 // PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[1].x, box->axis[1].y, box->axis[1].z); 463 // PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[2].x, box->axis[2].y, box->axis[2].z); 464 } 465 466 467 void OBBTreeNode::calculateBoxAxis(OBB* box, const modelInfo& modInfo) 468 { 469 this->calculateBoxAxis(box, (const sVec3D*)modInfo.pVertices, modInfo.numVertices); 470 } 471 472 473 474 void OBBTreeNode::calculateBoxAxis(OBB* box, const sVec3D* verticesList, unsigned int length) 475 { 476 297 box.axis[0] = axis[0]; 298 box.axis[1] = axis[1]; 299 box.axis[2] = axis[2]; 300 301 PRINTF(3)("Eigenvectors:\n"); 302 PRINT(3)("\t\t%11.2f \t%11.2f \t%11.2f\n", box.axis[0].x, box.axis[0].y, box.axis[0].z); 303 PRINT(3)("\t\t%11.2f \t%11.2f \t%11.2f\n", box.axis[1].x, box.axis[1].y, box.axis[1].z); 304 PRINT(3)("\t\t%11.2f \t%11.2f \t%11.2f\n", box.axis[2].x, box.axis[2].y, box.axis[2].z); 305 } 306 307 308 309 310 /** 311 * calculate the eigenvectors for the object oriented box 312 * @param box: reference to the box 313 * @param modelInf: the model info structure of the model 314 * @param tirangleIndexes: an array with the indexes of the triangles inside this 315 * @param length: the length of the indexes array 316 */ 317 void OBBTreeNode::calculateBoxAxis(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, int length) 318 { 319 320 PRINTF(3)("Calculate Box Axis\n"); 477 321 /* now get the axis length */ 478 322 Line ax[3]; //!< the axis 479 float * halfLength = new float[3];//!< half length of the axis323 float halfLength[3]; //!< half length of the axis 480 324 float tmpLength; //!< tmp save point for the length 481 Plane p0(box->axis[0], *box->center); //!< the axis planes 482 Plane p1(box->axis[1], *box->center); 483 Plane p2(box->axis[2], *box->center); 484 float maxLength[3]; 485 float minLength[3]; 486 487 488 /* get a bad bounding box */ 489 halfLength[0] = -1.0f; 490 for(int j = 0; j < length; ++j) 491 { 492 tmpLength = fabs(p0.distancePoint(vertices[j])); 493 if( tmpLength > halfLength[0]) 494 halfLength[0] = tmpLength; 495 } 496 497 halfLength[1] = -1.0f; 498 for(int j = 0; j < length; ++j) 499 { 500 tmpLength = fabs(p1.distancePoint(vertices[j])); 501 if( tmpLength > halfLength[1]) 502 halfLength[1] = tmpLength; 503 } 504 505 halfLength[2] = -1.0f; 506 for(int j = 0; j < length; ++j) 507 { 508 tmpLength = fabs(p2.distancePoint(vertices[j])); 509 if( tmpLength > halfLength[2]) 510 halfLength[2] = tmpLength; 511 } 512 325 Plane p0(box.axis[0], box.center); //!< the axis planes 326 Plane p1(box.axis[1], box.center); //!< the axis planes 327 Plane p2(box.axis[2], box.center); //!< the axis planes 328 float maxLength[3]; //!< maximal lenth of the axis 329 float minLength[3]; //!< minimal length of the axis 330 const sVec3D* tmpVec; //!< variable taking tmp vectors 513 331 514 332 515 333 /* get the maximal dimensions of the body in all directions */ 516 maxLength[0] = p0.distancePoint(vertices[0]); 517 minLength[0] = p0.distancePoint(vertices[0]); 518 for(int j = 0; j < length; ++j) 519 { 520 tmpLength = p0.distancePoint(vertices[j]); 521 if( tmpLength > maxLength[0]) 522 maxLength[0] = tmpLength; 523 else if( tmpLength < minLength[0]) 524 minLength[0] = tmpLength; 525 } 526 527 maxLength[1] = p1.distancePoint(vertices[0]); 528 minLength[1] = p1.distancePoint(vertices[0]); 529 for(int j = 0; j < length; ++j) 530 { 531 tmpLength = p1.distancePoint(vertices[j]); 532 if( tmpLength > maxLength[1]) 533 maxLength[1] = tmpLength; 534 else if( tmpLength < minLength[1]) 535 minLength[1] = tmpLength; 536 } 537 538 maxLength[2] = p2.distancePoint(vertices[0]); 539 minLength[2] = p2.distancePoint(vertices[0]); 540 for(int j = 0; j < length; ++j) 541 { 542 tmpLength = p2.distancePoint(vertices[j]); 543 if( tmpLength > maxLength[2]) 544 maxLength[2] = tmpLength; 545 else if( tmpLength < minLength[2]) 546 minLength[2] = tmpLength; 547 } 548 549 550 /* calculate the real centre of the body by using the axis length */ 551 float centerOffset[3]; 552 float newHalfLength[3]; 553 for(int i = 0; i < 3; ++i) 554 { 555 PRINTF(3)("max: %f, min: %f \n", maxLength[i], minLength[i]); 556 centerOffset[i] = (maxLength[i] + minLength[i]) / 2.0f; // min length is negatie 557 newHalfLength[i] = (maxLength[i] - minLength[i]) / 2.0f; // min length is negative 558 *box->center += (box->axis[i] * centerOffset[i]); // update the new center vector 559 halfLength[i] = newHalfLength[i]; 560 } 561 562 563 564 box->halfLength = halfLength; 565 PRINTF(3)("-- Written Axis to obb\n"); 566 PRINTF(3)("-- Finished Calculating Attributes\n"); 334 /* for the initialisation the value just has to be inside of the polygon soup -> first vertices (rand) */ 335 tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[0]].indexToVertices[0]]); 336 maxLength[0] = p0.distancePoint(*tmpVec); 337 minLength[0] = p0.distancePoint(*tmpVec); 338 for( int j = 0; j < length; ++j) 339 { 340 for( int i = 0; i < 3; ++i) 341 { 342 tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[j]].indexToVertices[i]]); 343 tmpLength = p0.distancePoint(*tmpVec); 344 if( tmpLength > maxLength[0]) 345 maxLength[0] = tmpLength; 346 else if( tmpLength < minLength[0]) 347 minLength[0] = tmpLength; 348 } 349 } 350 351 /* for the initialisation the value just has to be inside of the polygon soup -> first vertices (rand) */ 352 tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[0]].indexToVertices[0]]); 353 maxLength[1] = p1.distancePoint(*tmpVec); 354 minLength[1] = p1.distancePoint(*tmpVec); 355 for( int j = 0; j < length; ++j) 356 { 357 for( int i = 0; i < 3; ++i) 358 { 359 tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[j]].indexToVertices[i]]); 360 tmpLength = p1.distancePoint(*tmpVec); 361 if( tmpLength > maxLength[1]) 362 maxLength[1] = tmpLength; 363 else if( tmpLength < minLength[1]) 364 minLength[1] = tmpLength; 365 } 366 } 367 368 /* for the initialisation the value just has to be inside of the polygon soup -> first vertices (rand) */ 369 tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[0]].indexToVertices[0]]); 370 maxLength[2] = p2.distancePoint(*tmpVec); 371 minLength[2] = p2.distancePoint(*tmpVec); 372 for( int j = 0; j < length; ++j) 373 { 374 for( int i = 0; i < 3; ++i) 375 { 376 tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[j]].indexToVertices[i]]); 377 tmpLength = p2.distancePoint(*tmpVec); 378 if( tmpLength > maxLength[2]) 379 maxLength[2] = tmpLength; 380 else if( tmpLength < minLength[2]) 381 minLength[2] = tmpLength; 382 } 383 } 384 385 386 /* calculate the real centre of the body by using the axis length */ 387 float centerOffset[3]; 388 389 for( int i = 0; i < 3; ++i) 390 { 391 centerOffset[i] = (maxLength[i] + minLength[i]) / 2.0f; // min length is negatie 392 box.halfLength[i] = (maxLength[i] - minLength[i]) / 2.0f; // min length is negative 393 } 394 box.center.x += centerOffset[0]; 395 box.center.y += centerOffset[1]; 396 box.center.z += centerOffset[2]; 397 398 PRINTF(3)("\n"); 399 PRINT(3)("\tAxis Length x: %f (max: %11.2f, \tmin: %11.2f)\n", halfLength[0], maxLength[0], minLength[0]); 400 PRINT(3)("\tAxis Length x: %f (max: %11.2f, \tmin: %11.2f)\n", halfLength[1], maxLength[1], minLength[1]); 401 PRINT(3)("\tAxis Length x: %f (max: %11.2f, \tmin: %11.2f)\n", halfLength[2], maxLength[2], minLength[2]); 402 403 404 // box.halfLength[0] = halfLength[0]; 405 // box.halfLength[1] = halfLength[1]; 406 // box.halfLength[2] = halfLength[2]; 567 407 } 568 408 … … 570 410 571 411 /** 572 \briefthis separates an ob-box in the middle573 * @param box: the box to separate574 575 this will separate the box into to smaller boxes. the separation is done along the middle of the longest axis412 * this separates an ob-box in the middle 413 * @param box: the box to separate 414 * 415 * this will separate the box into to smaller boxes. the separation is done along the middle of the longest axis 576 416 */ 577 void OBBTreeNode::forkBox(OBB* box) 578 { 417 void OBBTreeNode::forkBox(OBB& box) 418 { 419 420 PRINTF(3)("Fork Box\n"); 421 PRINTF(4)("Calculating the longest Axis\n"); 579 422 /* get the longest axis of the box */ 580 float aLength = -1.0f; //!< the length of the longest axis 581 int axisIndex = 0; //!< this is the nr of the longest axis 582 583 for(int i = 0; i < 3; ++i) 584 { 585 if( aLength < box->halfLength[i]) 586 { 587 aLength = box->halfLength[i]; 588 axisIndex = i; 589 } 590 } 591 592 PRINTF(3)("longest axis is: nr %i with a half-length of: %f\n", axisIndex, aLength); 593 594 423 float longestAxis = -1.0f; //!< the length of the longest axis 424 int longestAxisIndex = 0; //!< this is the nr of the longest axis 425 426 427 /* now get the longest axis of the three exiting */ 428 for( int i = 0; i < 3; ++i) 429 { 430 if( longestAxis < box.halfLength[i]) 431 { 432 longestAxis = box.halfLength[i]; 433 longestAxisIndex = i; 434 } 435 } 436 PRINTF(3)("\nLongest Axis is: Nr %i with a half-length of:%11.2f\n", longestAxisIndex, longestAxis); 437 438 439 PRINTF(4)("Separating along the longest axis\n"); 595 440 /* get the closest vertex near the center */ 596 441 float dist = 999999.0f; //!< the smallest distance to each vertex 597 float tmpDist; //!< temporary distance 598 int vertexIndex; 599 Plane middlePlane(box->axis[axisIndex], *box->center); //!< the middle plane 600 601 vertexIndex = 0; 602 for(int i = 0; i < box->numOfVertices; ++i) 603 { 604 tmpDist = fabs(middlePlane.distancePoint(box->vertices[i])); 605 if( tmpDist < dist) 606 { 607 dist = tmpDist; 608 vertexIndex = i; 609 } 610 } 611 612 PRINTF(3)("\nthe clostest vertex is nr: %i, with a dist of: %f\n", vertexIndex ,dist); 442 float tmpDist; //!< variable to save diverse distances temporarily 443 int vertexIndex; //!< index of the vertex near the center 444 Plane middlePlane(box.axis[longestAxisIndex], box.center); //!< the middle plane 445 const sVec3D* tmpVec; //!< temp simple 3D vector 613 446 614 447 … … 616 449 the points depending on which side they are located 617 450 */ 618 tList<const sVec3D> partition1; //!< the vertex partition 1 619 tList<const sVec3D> partition2; //!< the vertex partition 2 620 621 622 PRINTF(3)("vertex index: %i, of %i\n", vertexIndex, box->numOfVertices); 623 this->separationPlane = new Plane(box->axis[axisIndex], box->vertices[vertexIndex]); //!< separation plane 624 this->sepPlaneCenter = &box->vertices[vertexIndex]; 625 this->longestAxisIndex = axisIndex; 626 627 for(int i = 0; i < box->numOfVertices; ++i) 628 { 629 if( i == vertexIndex) continue; 630 tmpDist = this->separationPlane->distancePoint(box->vertices[i]); 631 if( tmpDist > 0.0) 632 partition1.add(&box->vertices[i]); /* positive numbers plus zero */ 633 else 634 partition2.add(&box->vertices[i]); /* negatice numbers */ 635 } 636 partition1.add(&box->vertices[vertexIndex]); 637 partition2.add(&box->vertices[vertexIndex]); 638 639 PRINTF(3)("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.getSize(), partition2.getSize()); 451 std::list<int> partition1; //!< the vertex partition 1 452 std::list<int> partition2; //!< the vertex partition 2 453 float* triangleCenter = new float[3]; //!< the center of the triangle 454 const float* a; //!< triangle edge a 455 const float* b; //!< triangle edge b 456 const float* c; //!< triangle edge c 457 458 459 /* find the center of the box */ 460 this->separationPlane = Plane(box.axis[longestAxisIndex], box.center); 461 this->sepPlaneCenter[0] = box.center.x; 462 this->sepPlaneCenter[1] = box.center.y; 463 this->sepPlaneCenter[2] = box.center.z; 464 this->longestAxisIndex = longestAxisIndex; 465 466 for( int i = 0; i < box.triangleIndexesLength; ++i) 467 { 468 /* first calculate the middle of the triangle */ 469 a = &box.modelInf->pVertices[box.modelInf->pTriangles[box.triangleIndexes[i]].indexToVertices[0]]; 470 b = &box.modelInf->pVertices[box.modelInf->pTriangles[box.triangleIndexes[i]].indexToVertices[1]]; 471 c = &box.modelInf->pVertices[box.modelInf->pTriangles[box.triangleIndexes[i]].indexToVertices[2]]; 472 473 triangleCenter[0] = (a[0] + b[0] + c[0]) / 3.0f; 474 triangleCenter[1] = (a[1] + b[1] + c[1]) / 3.0f; 475 triangleCenter[2] = (a[2] + b[2] + c[2]) / 3.0f; 476 tmpDist = this->separationPlane.distancePoint(*((sVec3D*)triangleCenter)); 477 478 if( tmpDist > 0.0f) 479 partition1.push_back(box.triangleIndexes[i]); /* positive numbers plus zero */ 480 else if( tmpDist < 0.0f) 481 partition2.push_back(box.triangleIndexes[i]); /* negatice numbers */ 482 else { 483 partition1.push_back(box.triangleIndexes[i]); /* 0.0f? unprobable... */ 484 partition2.push_back(box.triangleIndexes[i]); 485 } 486 } 487 PRINTF(3)("\nPartition1: got \t%i Vertices \nPartition2: got \t%i Vertices\n", partition1.size(), partition2.size()); 640 488 641 489 642 490 /* now comes the separation into two different sVec3D arrays */ 643 tIterator<const sVec3D>* iterator; //!< the iterator to go through the lists644 const sVec3D* element; //!< the elements645 491 int index; //!< index storage place 646 sVec3D* vertList1; //!< the vertex list 1 647 sVec3D* vertList2; //!< the vertex list 2 648 649 vertList1 = new sVec3D[partition1.getSize()]; 650 vertList2 = new sVec3D[partition2.getSize()]; 651 652 iterator = partition1.getIterator(); 653 element = iterator->firstElement(); 654 index = 0; 655 while( element != NULL) 656 { 657 vertList1[index][0] = element[0][0]; 658 vertList1[index][1] = element[0][1]; 659 vertList1[index][2] = element[0][2]; 660 ++index; 661 element = iterator->nextElement(); 662 } 663 664 // PRINTF(0)("\npartition 1:\n"); 665 // for(int i = 0; i < partition1.getSize(); ++i) 666 // { 667 // PRINTF(0)("v[%i][0] = %f,\tv[%i][1] = %f,\tv[%i][1] = %f\n", i, vertList1[i][0], i, vertList1[i][1], i, vertList1[i][2]); 668 // } 669 670 iterator = partition2.getIterator(); 671 element = iterator->firstElement(); 672 index = 0; 673 while( element != NULL) 674 { 675 vertList2[index][0] = element[0][0]; 676 vertList2[index][1] = element[0][1]; 677 vertList2[index][2] = element[0][2]; 678 ++index; 679 element = iterator->nextElement(); 680 } 681 682 this->tmpVert1 = vertList1; 683 this->tmpVert2 = vertList2; 684 this->tmpLen1 = partition1.getSize(); 685 this->tmpLen2 = partition2.getSize(); 686 687 delete iterator; 688 689 // PRINTF(0)("\npartition 2:\n"); 690 // for(int i = 0; i < partition2.getSize(); ++i) 691 // { 692 // PRINTF(0)("v[%i][0] = %f,\tv[%i][1] = %f,\tv[%i][1] = %f\n", i, vertList2[i][0], i, vertList2[i][1], i, vertList2[i][2]); 693 // } 492 int* triangleIndexList1; //!< the vertex list 1 493 int* triangleIndexList2; //!< the vertex list 2 494 std::list<int>::iterator element; //!< the list iterator 495 496 triangleIndexList1 = new int[partition1.size()]; 497 triangleIndexList2 = new int[partition2.size()]; 498 499 for( element = partition1.begin(), index = 0; element != partition1.end(); element++, index++) 500 triangleIndexList1[index] = (*element); 501 502 for( element = partition2.begin(), index = 0; element != partition2.end(); element++, index++) 503 triangleIndexList2[index] = (*element); 504 505 if( this->triangleIndexList1!= NULL) 506 delete[] this->triangleIndexList1; 507 this->triangleIndexList1 = triangleIndexList1; 508 this->triangleIndexLength1 = partition1.size(); 509 510 if( this->triangleIndexList2 != NULL) 511 delete[] this->triangleIndexList2; 512 this->triangleIndexList2 = triangleIndexList2; 513 this->triangleIndexLength2 = partition2.size(); 694 514 } 695 515 … … 699 519 void OBBTreeNode::collideWith(BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB) 700 520 { 521 if( unlikely(treeNode == NULL)) 522 return; 523 701 524 PRINTF(3)("collideWith\n"); 702 525 /* if the obb overlap, make subtests: check which node is realy overlaping */ 703 PRINT(3)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex()); 704 if( unlikely(treeNode == NULL)) return; 705 706 if( this->overlapTest(this->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB)) 526 PRINTF(3)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex()); 527 // if( unlikely(treeNode == NULL)) return; 528 529 530 if( this->overlapTest(*this->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB)) 707 531 { 708 532 PRINTF(3)("collision @ lvl %i, object %s vs. %s, (%p, %p)\n", this->depth, nodeA->getClassName(), nodeB->getClassName(), this->nodeLeft, this->nodeRight); … … 711 535 if( likely( this->nodeLeft != NULL)) 712 536 { 713 PRINT (3)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode->getIndex());714 if( this->overlapTest( this->nodeLeft->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))537 PRINTF(3)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode->getIndex()); 538 if( this->overlapTest(*this->nodeLeft->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB)) 715 539 { 716 this->nodeLeft->collideWith((( OBBTreeNode*)treeNode)->nodeLeft, nodeA, nodeB);717 this->nodeLeft->collideWith((( OBBTreeNode*)treeNode)->nodeRight, nodeA, nodeB);540 this->nodeLeft->collideWith((((const OBBTreeNode*)treeNode)->nodeLeft), nodeA, nodeB); 541 this->nodeLeft->collideWith((((const OBBTreeNode*)treeNode)->nodeRight), nodeA, nodeB); 718 542 } 719 543 } … … 721 545 if( likely( this->nodeRight != NULL)) 722 546 { 723 PRINT (3)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode->getIndex());724 if(this->overlapTest( this->nodeRight->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))547 PRINTF(3)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode->getIndex()); 548 if(this->overlapTest(*this->nodeRight->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB)) 725 549 { 726 this->nodeRight->collideWith(((OBBTreeNode*)treeNode)->nodeLeft, nodeA, nodeB);727 this->nodeRight->collideWith(((OBBTreeNode*)treeNode)->nodeRight, nodeA, nodeB);550 this->nodeRight->collideWith((((const OBBTreeNode*)treeNode)->nodeLeft), nodeA, nodeB); 551 this->nodeRight->collideWith((((const OBBTreeNode*)treeNode)->nodeRight), nodeA, nodeB); 728 552 } 729 553 } 730 554 731 555 /* so there is a collision and this is the last box in the tree (i.e. leaf) */ 556 /* FIXME: If we would choose || insead of && there would also be asymmetrical cases supported */ 732 557 if( unlikely(this->nodeRight == NULL && this->nodeLeft == NULL)) 733 558 { 734 nodeA->collidesWith(nodeB, *((OBBTreeNode*)treeNode)->bvElement->center); 735 736 nodeB->collidesWith(nodeA, *this->bvElement->center); 737 } 738 739 } 740 } 741 742 743 744 bool OBBTreeNode::overlapTest(OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB) 745 { 559 nodeA->collidesWith(nodeB, (((const OBBTreeNode*)&treeNode)->bvElement->center)); 560 561 nodeB->collidesWith(nodeA, this->bvElement->center); 562 } 563 564 } 565 } 566 567 568 569 bool OBBTreeNode::overlapTest(OBB& boxA, OBB& boxB, WorldEntity* nodeA, WorldEntity* nodeB) 570 { 571 //HACK remove this again 572 this->owner = nodeA; 573 // if( boxB == NULL || boxA == NULL) 574 // return false; 575 746 576 /* first check all axis */ 747 577 Vector t; … … 752 582 Vector rotAxisB[3]; 753 583 754 rotAxisA[0] = nodeA->getAbsDir().apply(boxA->axis[0]); 755 rotAxisA[1] = nodeA->getAbsDir().apply(boxA->axis[1]); 756 rotAxisA[2] = nodeA->getAbsDir().apply(boxA->axis[2]); 757 758 rotAxisB[0] = nodeB->getAbsDir().apply(boxB->axis[0]); 759 rotAxisB[1] = nodeB->getAbsDir().apply(boxB->axis[1]); 760 rotAxisB[2] = nodeB->getAbsDir().apply(boxB->axis[2]); 761 762 t = nodeA->getAbsCoor() + nodeA->getAbsDir().apply(*boxA->center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(*boxB->center)); 763 764 // printf("\n"); 765 // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[0].x, boxA->axis[0].y, boxA->axis[0].z, rotAxisA[0].x, rotAxisA[0].y, rotAxisA[0].z); 766 // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[1].x, boxA->axis[1].y, boxA->axis[1].z, rotAxisA[1].x, rotAxisA[1].y, rotAxisA[1].z); 767 // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[2].x, boxA->axis[2].y, boxA->axis[2].z, rotAxisA[2].x, rotAxisA[2].y, rotAxisA[2].z); 768 // 769 // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[0].x, boxB->axis[0].y, boxB->axis[0].z, rotAxisB[0].x, rotAxisB[0].y, rotAxisB[0].z); 770 // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[1].x, boxB->axis[1].y, boxB->axis[1].z, rotAxisB[1].x, rotAxisB[1].y, rotAxisB[1].z); 771 // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[2].x, boxB->axis[2].y, boxB->axis[2].z, rotAxisB[2].x, rotAxisB[2].y, rotAxisB[2].z); 584 rotAxisA[0] = nodeA->getAbsDir().apply(boxA.axis[0]); 585 rotAxisA[1] = nodeA->getAbsDir().apply(boxA.axis[1]); 586 rotAxisA[2] = nodeA->getAbsDir().apply(boxA.axis[2]); 587 588 rotAxisB[0] = nodeB->getAbsDir().apply(boxB.axis[0]); 589 rotAxisB[1] = nodeB->getAbsDir().apply(boxB.axis[1]); 590 rotAxisB[2] = nodeB->getAbsDir().apply(boxB.axis[2]); 591 592 593 t = nodeA->getAbsCoor() + nodeA->getAbsDir().apply(boxA.center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(boxB.center)); 594 595 // printf("\n"); 596 // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[0].x, boxA->axis[0].y, boxA->axis[0].z, rotAxisA[0].x, rotAxisA[0].y, rotAxisA[0].z); 597 // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[1].x, boxA->axis[1].y, boxA->axis[1].z, rotAxisA[1].x, rotAxisA[1].y, rotAxisA[1].z); 598 // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[2].x, boxA->axis[2].y, boxA->axis[2].z, rotAxisA[2].x, rotAxisA[2].y, rotAxisA[2].z); 599 // 600 // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[0].x, boxB->axis[0].y, boxB->axis[0].z, rotAxisB[0].x, rotAxisB[0].y, rotAxisB[0].z); 601 // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[1].x, boxB->axis[1].y, boxB->axis[1].z, rotAxisB[1].x, rotAxisB[1].y, rotAxisB[1].z); 602 // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[2].x, boxB->axis[2].y, boxB->axis[2].z, rotAxisB[2].x, rotAxisB[2].y, rotAxisB[2].z); 772 603 773 604 … … 779 610 l = rotAxisA[j]; 780 611 781 rA += fabs(boxA ->halfLength[0] * rotAxisA[0].dot(l));782 rA += fabs(boxA ->halfLength[1] * rotAxisA[1].dot(l));783 rA += fabs(boxA ->halfLength[2] * rotAxisA[2].dot(l));784 785 rB += fabs(boxB ->halfLength[0] * rotAxisB[0].dot(l));786 rB += fabs(boxB ->halfLength[1] * rotAxisB[1].dot(l));787 rB += fabs(boxB ->halfLength[2] * rotAxisB[2].dot(l));612 rA += fabs(boxA.halfLength[0] * rotAxisA[0].dot(l)); 613 rA += fabs(boxA.halfLength[1] * rotAxisA[1].dot(l)); 614 rA += fabs(boxA.halfLength[2] * rotAxisA[2].dot(l)); 615 616 rB += fabs(boxB.halfLength[0] * rotAxisB[0].dot(l)); 617 rB += fabs(boxB.halfLength[1] * rotAxisB[1].dot(l)); 618 rB += fabs(boxB.halfLength[2] * rotAxisB[2].dot(l)); 788 619 789 620 PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); … … 791 622 if( (rA + rB) < fabs(t.dot(l))) 792 623 { 793 PRINT (3)("no Collision\n");624 PRINTF(3)("no Collision\n"); 794 625 return false; 795 626 } … … 803 634 l = rotAxisB[j]; 804 635 805 rA += fabs(boxA ->halfLength[0] * rotAxisA[0].dot(l));806 rA += fabs(boxA ->halfLength[1] * rotAxisA[1].dot(l));807 rA += fabs(boxA ->halfLength[2] * rotAxisA[2].dot(l));808 809 rB += fabs(boxB ->halfLength[0] * rotAxisB[0].dot(l));810 rB += fabs(boxB ->halfLength[1] * rotAxisB[1].dot(l));811 rB += fabs(boxB ->halfLength[2] * rotAxisB[2].dot(l));636 rA += fabs(boxA.halfLength[0] * rotAxisA[0].dot(l)); 637 rA += fabs(boxA.halfLength[1] * rotAxisA[1].dot(l)); 638 rA += fabs(boxA.halfLength[2] * rotAxisA[2].dot(l)); 639 640 rB += fabs(boxB.halfLength[0] * rotAxisB[0].dot(l)); 641 rB += fabs(boxB.halfLength[1] * rotAxisB[1].dot(l)); 642 rB += fabs(boxB.halfLength[2] * rotAxisB[2].dot(l)); 812 643 813 644 PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); … … 815 646 if( (rA + rB) < fabs(t.dot(l))) 816 647 { 817 PRINT (3)("no Collision\n");648 PRINTF(3)("no Collision\n"); 818 649 return false; 819 650 } … … 831 662 l = rotAxisA[j].cross(rotAxisB[k]); 832 663 833 rA += fabs(boxA ->halfLength[0] * rotAxisA[0].dot(l));834 rA += fabs(boxA ->halfLength[1] * rotAxisA[1].dot(l));835 rA += fabs(boxA ->halfLength[2] * rotAxisA[2].dot(l));836 837 rB += fabs(boxB ->halfLength[0] * rotAxisB[0].dot(l));838 rB += fabs(boxB ->halfLength[1] * rotAxisB[1].dot(l));839 rB += fabs(boxB ->halfLength[2] * rotAxisB[2].dot(l));664 rA += fabs(boxA.halfLength[0] * rotAxisA[0].dot(l)); 665 rA += fabs(boxA.halfLength[1] * rotAxisA[1].dot(l)); 666 rA += fabs(boxA.halfLength[2] * rotAxisA[2].dot(l)); 667 668 rB += fabs(boxB.halfLength[0] * rotAxisB[0].dot(l)); 669 rB += fabs(boxB.halfLength[1] * rotAxisB[1].dot(l)); 670 rB += fabs(boxB.halfLength[2] * rotAxisB[2].dot(l)); 840 671 841 672 PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); … … 843 674 if( (rA + rB) < fabs(t.dot(l))) 844 675 { 845 PRINT (3)("keine Kollision\n");676 PRINTF(3)("keine Kollision\n"); 846 677 return false; 847 678 } … … 849 680 } 850 681 851 852 boxA->bCollided = true; /* use this ONLY(!!!!) for drawing operations */ 853 boxB->bCollided = true; 854 PRINT(3)("Kollision!\n"); 682 /* FIXME: there is no collision mark set now */ 683 boxA.bCollided = true; /* use this ONLY(!!!!) for drawing operations */ 684 boxB.bCollided = true; 685 686 687 PRINTF(3)("Kollision!\n"); 855 688 return true; 856 689 } … … 860 693 861 694 695 696 697 698 699 700 /** 701 * 702 * draw the BV tree - debug mode 703 */ 862 704 void OBBTreeNode::drawBV(int depth, int drawMode, const Vector& color, bool top) const 863 705 { 864 865 /* draw the model itself, there is some problem concerning this: the vertices are drawn multiple times */ 706 /* this function can be used to draw the triangles and/or the points only */ 866 707 if( drawMode & DRAW_MODEL || drawMode & DRAW_ALL) 867 708 { … … 869 710 { 870 711 if( drawMode & DRAW_POINTS) 712 { 871 713 glBegin(GL_POINTS); 872 for(int i = 0; i < this->bvElement->numOfVertices; ++i) 873 { 874 if( drawMode & DRAW_POINTS) 875 glVertex3f(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]); 876 else 877 { 878 glPushMatrix(); 879 glTranslatef(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]); 880 gluSphere(OBBTreeNode_sphereObj, 0.1, 10, 10); 881 glPopMatrix(); 882 } 714 for( int i = 0; i < this->bvElement->modelInf->numVertices*3; i+=3) 715 glVertex3f(this->bvElement->modelInf->pVertices[i], 716 this->bvElement->modelInf->pVertices[i+1], 717 this->bvElement->modelInf->pVertices[i+2]); 718 glEnd(); 883 719 } 884 if( drawMode & DRAW_POINTS)885 glEnd();886 720 } 887 721 } … … 917 751 if( drawMode & DRAW_BV_AXIS || drawMode & DRAW_ALL) 918 752 { 919 if( !(drawMode & DRAW_SINGLE && depth != 0))753 if( drawMode & DRAW_SINGLE && depth != 0) 920 754 { 921 755 /* draw the obb axes */ 922 756 glBegin(GL_LINES); 923 glColor3f(0.0, 0.4, 0.3); 924 glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z); 925 glVertex3f(this->bvElement->center->x + this->bvElement->axis[0].x * this->bvElement->halfLength[0], 926 this->bvElement->center->y + this->bvElement->axis[0].y * this->bvElement->halfLength[0], 927 this->bvElement->center->z + this->bvElement->axis[0].z * this->bvElement->halfLength[0]); 928 929 glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z); 930 glVertex3f(this->bvElement->center->x + this->bvElement->axis[1].x * this->bvElement->halfLength[1], 931 this->bvElement->center->y + this->bvElement->axis[1].y * this->bvElement->halfLength[1], 932 this->bvElement->center->z + this->bvElement->axis[1].z * this->bvElement->halfLength[1]); 933 934 glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z); 935 glVertex3f(this->bvElement->center->x + this->bvElement->axis[2].x * this->bvElement->halfLength[2], 936 this->bvElement->center->y + this->bvElement->axis[2].y * this->bvElement->halfLength[2], 937 this->bvElement->center->z + this->bvElement->axis[2].z * this->bvElement->halfLength[2]); 757 glColor3f(1.0, 0.0, 0.0); 758 glVertex3f(this->bvElement->center.x, this->bvElement->center.y, this->bvElement->center.z); 759 glVertex3f(this->bvElement->center.x + this->bvElement->axis[0].x * this->bvElement->halfLength[0], 760 this->bvElement->center.y + this->bvElement->axis[0].y * this->bvElement->halfLength[0], 761 this->bvElement->center.z + this->bvElement->axis[0].z * this->bvElement->halfLength[0]); 762 763 glColor3f(0.0, 1.0, 0.0); 764 glVertex3f(this->bvElement->center.x, this->bvElement->center.y, this->bvElement->center.z); 765 glVertex3f(this->bvElement->center.x + this->bvElement->axis[1].x * this->bvElement->halfLength[1], 766 this->bvElement->center.y + this->bvElement->axis[1].y * this->bvElement->halfLength[1], 767 this->bvElement->center.z + this->bvElement->axis[1].z * this->bvElement->halfLength[1]); 768 769 glColor3f(0.0, 0.0, 1.0); 770 glVertex3f(this->bvElement->center.x, this->bvElement->center.y, this->bvElement->center.z); 771 glVertex3f(this->bvElement->center.x + this->bvElement->axis[2].x * this->bvElement->halfLength[2], 772 this->bvElement->center.y + this->bvElement->axis[2].y * this->bvElement->halfLength[2], 773 this->bvElement->center.z + this->bvElement->axis[2].z * this->bvElement->halfLength[2]); 938 774 glEnd(); 939 775 } … … 950 786 } 951 787 952 if( this->nodeLeft == NULL ||this->nodeRight == NULL)788 if( this->nodeLeft == NULL && this->nodeRight == NULL) 953 789 depth = 0; 954 if( !(drawMode & DRAW_SINGLE && depth != 0)) 955 { 956 Vector cen = *this->bvElement->center; 957 Vector* axis = this->bvElement->axis; 958 float* len = this->bvElement->halfLength; 959 960 if( this->bvElement->bCollided) 961 { 962 glColor4f(1.0, 1.0, 1.0, .5); // COLLISION COLOR 963 } 964 else if( drawMode & DRAW_BV_BLENDED) 965 { 966 glColor4f(color.x, color.y, color.z, .5); 967 } 968 969 /* draw bounding box */ 970 if( drawMode & DRAW_BV_BLENDED) 971 glBegin(GL_QUADS); 972 else 973 glBegin(GL_LINE_LOOP); 974 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], 975 cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], 976 cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); 977 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 978 cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 979 cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 980 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], 981 cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 982 cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 983 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 984 cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 985 cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 986 glEnd(); 987 988 if( drawMode & DRAW_BV_BLENDED) 989 glBegin(GL_QUADS); 990 else 991 glBegin(GL_LINE_LOOP); 992 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 993 cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 994 cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 995 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], 996 cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 997 cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 998 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], 999 cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 1000 cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 1001 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 1002 cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 1003 cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 1004 glEnd(); 1005 1006 if( drawMode & DRAW_BV_BLENDED) 1007 glBegin(GL_QUADS); 1008 else 1009 glBegin(GL_LINE_LOOP); 1010 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 1011 cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 1012 cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 1013 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], 1014 cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 1015 cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 1016 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 1017 cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 1018 cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 1019 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], 1020 cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], 1021 cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); 1022 glEnd(); 1023 1024 if( drawMode & DRAW_BV_BLENDED) 1025 glBegin(GL_QUADS); 1026 else 1027 glBegin(GL_LINE_LOOP); 1028 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 1029 cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 1030 cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 1031 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], 1032 cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], 1033 cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); 1034 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], 1035 cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], 1036 cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); 1037 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 1038 cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 1039 cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 1040 glEnd(); 1041 1042 1043 if( drawMode & DRAW_BV_BLENDED) 1044 { 1045 glBegin(GL_QUADS); 1046 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 1047 cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 1048 cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 790 791 if( depth == 0 /*!(drawMode & DRAW_SINGLE && depth != 0)*/) 792 { 793 794 795 Vector cen = this->bvElement->center; 796 Vector* axis = this->bvElement->axis; 797 float* len = this->bvElement->halfLength; 798 799 if( this->bvElement->bCollided) 800 { 801 glColor4f(1.0, 1.0, 1.0, .5); // COLLISION COLOR 802 } 803 else if( drawMode & DRAW_BV_BLENDED) 804 { 805 glColor4f(color.x, color.y, color.z, .5); 806 } 807 808 // debug out 809 if( this->obbTree->getOwner() != NULL) 810 { 811 PRINTF(0)("debug poly draw: depth: %i, mode: %i, entity-name: %s, class: %s\n", depth, drawMode, this->obbTree->getOwner()->getName(), this->obbTree->getOwner()->getClassName()); 812 } 813 else 814 PRINTF(0)("debug poly draw: depth: %i, mode: %i\n", depth, drawMode); 815 816 817 /* draw bounding box */ 818 if( drawMode & DRAW_BV_BLENDED) 819 glBegin(GL_QUADS); 820 else 821 glBegin(GL_LINE_LOOP); 822 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], 823 cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], 824 cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); 1049 825 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 1050 826 cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], … … 1053 829 cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 1054 830 cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 831 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 832 cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 833 cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 834 glEnd(); 835 836 if( drawMode & DRAW_BV_BLENDED) 837 glBegin(GL_QUADS); 838 else 839 glBegin(GL_LINE_LOOP); 840 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 841 cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 842 cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 843 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], 844 cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 845 cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 1055 846 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], 1056 847 cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 1057 848 cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 849 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 850 cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 851 cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 1058 852 glEnd(); 1059 853 1060 glBegin(GL_QUADS); 854 if( drawMode & DRAW_BV_BLENDED) 855 glBegin(GL_QUADS); 856 else 857 glBegin(GL_LINE_LOOP); 858 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 859 cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 860 cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 861 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], 862 cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 863 cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 864 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 865 cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 866 cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 867 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], 868 cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], 869 cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); 870 glEnd(); 871 872 if( drawMode & DRAW_BV_BLENDED) 873 glBegin(GL_QUADS); 874 else 875 glBegin(GL_LINE_LOOP); 876 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 877 cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 878 cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 1061 879 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], 1062 880 cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], … … 1065 883 cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], 1066 884 cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); 1067 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 1068 cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 1069 cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 1070 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 1071 cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 1072 cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 885 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 886 cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 887 cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 1073 888 glEnd(); 1074 } 1075 1076 1077 if( drawMode & DRAW_BV_BLENDED) 1078 glColor3f(color.x, color.y, color.z); 1079 } 1080 889 890 891 if( drawMode & DRAW_BV_BLENDED) 892 { 893 glBegin(GL_QUADS); 894 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 895 cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 896 cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 897 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 898 cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 899 cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 900 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], 901 cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 902 cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 903 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], 904 cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 905 cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 906 glEnd(); 907 908 glBegin(GL_QUADS); 909 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], 910 cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], 911 cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); 912 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], 913 cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], 914 cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); 915 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 916 cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 917 cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 918 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 919 cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 920 cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 921 glEnd(); 922 } 923 924 if( drawMode & DRAW_BV_BLENDED) 925 glColor3f(color.x, color.y, color.z); 926 } 1081 927 } 1082 928 … … 1089 935 glColor4f(color.x, color.y, color.z, .6); 1090 936 1091 /* now draw the separation plane */1092 Vector a1 = this->bvElement->axis[(this->longestAxisIndex + 1)%3];1093 Vector a2 = this->bvElement->axis[(this->longestAxisIndex + 2)%3];1094 Vector c = *this->bvElement->center;1095 float l1 = this->bvElement->halfLength[(this->longestAxisIndex + 1)%3];1096 float l2 = this->bvElement->halfLength[(this->longestAxisIndex + 2)%3];1097 glBegin(GL_QUADS);1098 glVertex3f(c.x + a1.x * l1 + a2.x * l2, c.y + a1.y * l1+ a2.y * l2, c.z + a1.z * l1 + a2.z * l2);1099 glVertex3f(c.x - a1.x * l1 + a2.x * l2, c.y - a1.y * l1+ a2.y * l2, c.z - a1.z * l1 + a2.z * l2);1100 glVertex3f(c.x - a1.x * l1 - a2.x * l2, c.y - a1.y * l1- a2.y * l2, c.z - a1.z * l1 - a2.z * l2);1101 glVertex3f(c.x + a1.x * l1 - a2.x * l2, c.y + a1.y * l1- a2.y * l2, c.z + a1.z * l1 - a2.z * l2);1102 glEnd();1103 1104 if( drawMode & DRAW_BV_BLENDED)1105 glColor4f(color.x, color.y, color.z, 1.0);937 /* now draw the separation plane */ 938 Vector a1 = this->bvElement->axis[(this->longestAxisIndex + 1)%3]; 939 Vector a2 = this->bvElement->axis[(this->longestAxisIndex + 2)%3]; 940 Vector c = this->bvElement->center; 941 float l1 = this->bvElement->halfLength[(this->longestAxisIndex + 1)%3]; 942 float l2 = this->bvElement->halfLength[(this->longestAxisIndex + 2)%3]; 943 glBegin(GL_QUADS); 944 glVertex3f(c.x + a1.x * l1 + a2.x * l2, c.y + a1.y * l1+ a2.y * l2, c.z + a1.z * l1 + a2.z * l2); 945 glVertex3f(c.x - a1.x * l1 + a2.x * l2, c.y - a1.y * l1+ a2.y * l2, c.z - a1.z * l1 + a2.z * l2); 946 glVertex3f(c.x - a1.x * l1 - a2.x * l2, c.y - a1.y * l1- a2.y * l2, c.z - a1.z * l1 - a2.z * l2); 947 glVertex3f(c.x + a1.x * l1 - a2.x * l2, c.y + a1.y * l1- a2.y * l2, c.z + a1.z * l1 - a2.z * l2); 948 glEnd(); 949 950 if( drawMode & DRAW_BV_BLENDED) 951 glColor4f(color.x, color.y, color.z, 1.0); 1106 952 1107 953 } … … 1127 973 void OBBTreeNode::debug() const 1128 974 { 1129 1130 /* 1131 for(int i = 0; i < length; i++) 1132 { 1133 PRINTF(3)("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]); 1134 } 1135 */ 1136 } 975 PRINT(0)("========OBBTreeNode::debug()=====\n"); 976 PRINT(0)(" Current depth: %i", this->depth); 977 PRINT(0)(" "); 978 PRINT(0)("=================================\n"); 979 }
Note: See TracChangeset
for help on using the changeset viewer.