Changeset 5825 in orxonox.OLD for branches/collision_detection/src/lib
- Timestamp:
- Nov 29, 2005, 6:01:26 PM (19 years ago)
- Location:
- branches/collision_detection/src/lib/collision_detection
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/collision_detection/src/lib/collision_detection/obb_tree_node.cc
r5718 r5825 43 43 */ 44 44 OBBTreeNode::OBBTreeNode (const OBBTree& tree, unsigned int depth) 45 : BVTreeNode()45 : BVTreeNode() 46 46 { 47 47 this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode"); … … 139 139 140 140 141 // if(this->tmpLen1 > 2)142 // {143 // OBBTreeNode* node1 = new OBBTreeNode();144 // this->nodeLeft = node1;145 // this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1);146 // }147 // else148 // {149 // PRINTF(3)("Aboarding tree walk: less than 3 vertices left\n");150 // }151 //152 // if( this->tmpLen2 > 2)153 // {154 // OBBTreeNode* node2 = new OBBTreeNode();155 // this->nodeRight = node2;156 // this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2);157 // }158 // else159 // {160 // PRINTF(3)("Abording tree walk: less than 3 vertices left\n");161 // }141 // if(this->tmpLen1 > 2) 142 // { 143 // OBBTreeNode* node1 = new OBBTreeNode(); 144 // this->nodeLeft = node1; 145 // this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1); 146 // } 147 // else 148 // { 149 // PRINTF(3)("Aboarding tree walk: less than 3 vertices left\n"); 150 // } 151 // 152 // if( this->tmpLen2 > 2) 153 // { 154 // OBBTreeNode* node2 = new OBBTreeNode(); 155 // this->nodeRight = node2; 156 // this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2); 157 // } 158 // else 159 // { 160 // PRINTF(3)("Abording tree walk: less than 3 vertices left\n"); 161 // } 162 162 163 163 } … … 174 174 void OBBTreeNode::spawnBVTree(const sVec3D *verticesList, unsigned int length) 175 175 { 176 // PRINTF(3)("\n");177 // PRINTF(3)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length);178 // this->depth = depth;179 //180 //181 // this->bvElement = new OBB();182 // this->bvElement->vertices = verticesList;183 // this->bvElement->numOfVertices = length;184 // PRINTF(3)("Created OBBox\n");185 // this->calculateBoxCovariance(this->bvElement, verticesList, length);186 // PRINTF(3)("Calculated attributes1\n");187 // this->calculateBoxEigenvectors(this->bvElement, verticesList, length);188 // PRINTF(3)("Calculated attributes2\n");189 // this->calculateBoxAxis(this->bvElement, verticesList, length);190 // PRINTF(3)("Calculated attributes3\n");191 //192 //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(this->obbTree);202 // this->nodeLeft = node1;203 // this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1);204 // }205 // else206 // {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(this->obbTree);213 // this->nodeRight = node2;214 // this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2);215 // }216 // else217 // {218 // PRINTF(3)("Abording tree walk: less than 3 vertices left\n");219 // }220 // }176 // PRINTF(3)("\n"); 177 // PRINTF(3)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length); 178 // this->depth = depth; 179 // 180 // 181 // this->bvElement = new OBB(); 182 // this->bvElement->vertices = verticesList; 183 // this->bvElement->numOfVertices = length; 184 // PRINTF(3)("Created OBBox\n"); 185 // this->calculateBoxCovariance(this->bvElement, verticesList, length); 186 // PRINTF(3)("Calculated attributes1\n"); 187 // this->calculateBoxEigenvectors(this->bvElement, verticesList, length); 188 // PRINTF(3)("Calculated attributes2\n"); 189 // this->calculateBoxAxis(this->bvElement, verticesList, length); 190 // PRINTF(3)("Calculated attributes3\n"); 191 // 192 // 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(this->obbTree); 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(this->obbTree); 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 221 } 222 222 223 223 224 224 void OBBTreeNode::calculateBoxCovariance(OBB& box, const modelInfo& modelInf, 225 const int* triangleIndexes, unsigned int length) 226 { 227 const sVec3D* verticesList; 225 const int* triangleIndexes, unsigned int length) 226 { 228 227 229 228 PRINTF(3)("Created OBBox\n"); … … 251 250 252 251 /* finding the facelet surface via cross-product */ 253 t1 = p - q; t2 = p - r; 252 t1 = p - q; 253 t2 = p - r; 254 254 facelet[i] = 0.5f * fabs( t1.cross(t2).len() ); 255 255 /* update the entire convex hull surface */ … … 263 263 /* take the average of the centroid sum */ 264 264 center /= face; 265 PRINTF(3)("-- Calculated Center\n");266 265 267 266 … … 282 281 283 282 covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j] * p[k] + 284 q[j] * q[k] + r[j] * r[k]) - center[j] * center[k];283 q[j] * q[k] + r[j] * r[k]) - center[j] * center[k]; 285 284 } 286 285 } 287 286 } 288 PRINTF(3)("-- Calculated Covariance\n"); 289 290 291 PRINTF(3)("\nVertex Data:\n"); 292 for(int i = 0; i < length; i++) 293 PRINTF(3)(" Vertex[%i]: %f, %f, %f\n", i, box.vertices[i][0], box.vertices[i][1], box.vertices[i][2]); 287 294 288 PRINTF(3)("\nOBB Covariance Matrix:\n"); 295 for(int j = 0; j < 3; ++j) { PRINTF(3)(" |"); for(int k = 0; k < 3; ++k) { PRINTF(3)(" \b%f ", covariance[j][k]); } PRINTF(3)(" |\n"); } 289 for(int j = 0; j < 3; ++j) 290 { 291 PRINTF(3)(" |"); 292 for(int k = 0; k < 3; ++k) 293 { 294 PRINTF(3)(" \b%f ", covariance[j][k]); 295 } 296 PRINTF(3)(" |\n"); 297 } 296 298 PRINTF(3)("OBB Center: %f, %f, %f\n", center.x, center.y, center.z); 297 299 298 300 /* write back the covariance matrix data to the object oriented bouning box */ 299 301 for(int i = 0; i < 3; ++i) 300 302 { … … 304 306 } 305 307 box.center = center; 306 307 PRINTF(3)("-- Written Result to OBB\n");308 308 } 309 309 310 310 311 311 void OBBTreeNode::calculateBoxEigenvectors(OBB& box, const modelInfo& modInfo, 312 const int* triangleIndexes, unsigned int length) 313 {} 314 315 void OBBTreeNode::calculateBoxEigenvectors(OBB& box, const sVec3D* verticesList, unsigned int length) 316 { 317 PRINTF(3)("Calculated attributes1\n"); 318 /* now getting spanning vectors of the sub-space: 312 const int* triangleIndexes, unsigned int length) 313 { 314 315 PRINTF(3)("Calculate the Box Eigenvectors\n"); 316 317 const sVec3D* verticesList; 318 Vector axis[3]; //!< the references to the obb axis 319 Matrix covMat( box.covarianceMatrix ); //!< covariance matrix (in the matrix dataform) 320 321 /* 322 now getting spanning vectors of the sub-space: 319 323 the eigenvectors of a symmertric matrix, such as the 320 324 covarience matrix are mutually orthogonal. … … 322 326 vectors 323 327 */ 324 Vector axis[3]; //!< the references to the obb axis 325 326 Matrix covMat( box.covarianceMatrix ); 328 329 /* calculate the axis */ 327 330 covMat.getEigenVectors(axis[0], axis[1], axis[2] ); 328 329 330 /* new jacobi tests */331 // JacobI(OBBTreeNode::coMat, OBBTreeNode::eigvlMat, OBBTreeNode::eigvMat, OBBTreeNode::rotCount);332 // PRINTF(3)("-- Done Jacobi Decomposition\n");333 334 335 // PRINTF(0)("Jacobi\n");336 // for(int j = 0; j < 3; ++j)337 // {338 // printf(" |");339 // for(int k = 0; k < 3; ++k)340 // {341 // printf(" \t%f ", OBBTreeNode::OBBTreeNode::eigvMat[j][k]);342 // }343 // printf(" |\n");344 // }345 346 /* axis[0].x = OBBTreeNode::eigvMat[0][0]; axis[0].y = OBBTreeNode::eigvMat[1][0]; axis[0].z = OBBTreeNode::eigvMat[2][0];347 axis[1].x = OBBTreeNode::eigvMat[0][1]; axis[1].y = OBBTreeNode::eigvMat[1][1]; axis[1].z = OBBTreeNode::eigvMat[2][1];348 axis[2].x = OBBTreeNode::eigvMat[0][2]; axis[2].y = OBBTreeNode::eigvMat[1][2]; axis[2].z = OBBTreeNode::eigvMat[2][2];349 axis[0].normalize();350 axis[1].normalize();351 axis[2].normalize();*/352 331 box.axis[0] = axis[0]; 353 332 box.axis[1] = axis[1]; 354 333 box.axis[2] = axis[2]; 355 334 356 // PRINTF(0)("-- Got Axis\n"); 357 // 358 // PRINTF(0)("eigenvector: %f, %f, %f\n", box.axis[0].x, box.axis[0].y, box.axis[0].z); 359 // PRINTF(0)("eigenvector: %f, %f, %f\n", box.axis[1].x, box.axis[1].y, box.axis[1].z); 360 // PRINTF(0)("eigenvector: %f, %f, %f\n", box.axis[2].x, box.axis[2].y, box.axis[2].z); 335 PRINTF(0)("-- Got Axis\n"); 336 PRINTF(0)("Eigenvector: %f, %f, %f\n", box.axis[0].x, box.axis[0].y, box.axis[0].z); 337 PRINTF(0)("Eigenvector: %f, %f, %f\n", box.axis[1].x, box.axis[1].y, box.axis[1].z); 338 PRINTF(0)("Eigenvector: %f, %f, %f\n", box.axis[2].x, box.axis[2].y, box.axis[2].z); 361 339 } 362 340 … … 386 364 halfLength[0] = -1.0f; 387 365 for(int j = 0; j < length; ++j) 388 389 390 391 392 366 { 367 tmpLength = fabs(p0.distancePoint(vertices[j])); 368 if( tmpLength > halfLength[0]) 369 halfLength[0] = tmpLength; 370 } 393 371 394 372 halfLength[1] = -1.0f; 395 373 for(int j = 0; j < length; ++j) 396 397 398 399 400 374 { 375 tmpLength = fabs(p1.distancePoint(vertices[j])); 376 if( tmpLength > halfLength[1]) 377 halfLength[1] = tmpLength; 378 } 401 379 402 380 halfLength[2] = -1.0f; 403 381 for(int j = 0; j < length; ++j) 404 405 406 407 408 382 { 383 tmpLength = fabs(p2.distancePoint(vertices[j])); 384 if( tmpLength > halfLength[2]) 385 halfLength[2] = tmpLength; 386 } 409 387 410 388 411 389 412 390 /* get the maximal dimensions of the body in all directions */ 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 391 maxLength[0] = p0.distancePoint(vertices[0]); 392 minLength[0] = p0.distancePoint(vertices[0]); 393 for(int j = 0; j < length; ++j) 394 { 395 tmpLength = p0.distancePoint(vertices[j]); 396 if( tmpLength > maxLength[0]) 397 maxLength[0] = tmpLength; 398 else if( tmpLength < minLength[0]) 399 minLength[0] = tmpLength; 400 } 401 402 maxLength[1] = p1.distancePoint(vertices[0]); 403 minLength[1] = p1.distancePoint(vertices[0]); 404 for(int j = 0; j < length; ++j) 405 { 406 tmpLength = p1.distancePoint(vertices[j]); 407 if( tmpLength > maxLength[1]) 408 maxLength[1] = tmpLength; 409 else if( tmpLength < minLength[1]) 410 minLength[1] = tmpLength; 411 } 412 413 maxLength[2] = p2.distancePoint(vertices[0]); 414 minLength[2] = p2.distancePoint(vertices[0]); 415 for(int j = 0; j < length; ++j) 416 { 417 tmpLength = p2.distancePoint(vertices[j]); 418 if( tmpLength > maxLength[2]) 419 maxLength[2] = tmpLength; 420 else if( tmpLength < minLength[2]) 421 minLength[2] = tmpLength; 422 } 423 424 425 /* calculate the real centre of the body by using the axis length */ 426 float centerOffset[3]; 427 float newHalfLength[3]; 428 for(int i = 0; i < 3; ++i) 429 { 430 PRINTF(3)("max: %f, min: %f \n", maxLength[i], minLength[i]); 431 centerOffset[i] = (maxLength[i] + minLength[i]) / 2.0f; // min length is negatie 432 newHalfLength[i] = (maxLength[i] - minLength[i]) / 2.0f; // min length is negative 433 box.center += (box.axis[i] * centerOffset[i]); // update the new center vector 434 halfLength[i] = newHalfLength[i]; 435 } 458 436 459 437 … … 489 467 } 490 468 491 469 PRINTF(3)("longest axis is: nr %i with a half-length of: %f\n", axisIndex, aLength); 492 470 493 471 … … 526 504 for(int i = 0; i < box.numOfVertices; ++i) 527 505 { 528 if( i == vertexIndex) continue; 506 if( i == vertexIndex) 507 continue; 529 508 tmpDist = this->separationPlane.distancePoint(box.vertices[i]); 530 509 if( tmpDist > 0.0) … … 561 540 } 562 541 delete iterator; 563 // PRINTF(0)("\npartition 1:\n");564 // for(int i = 0; i < partition1.getSize(); ++i)565 // {566 // 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]);567 // }542 // PRINTF(0)("\npartition 1:\n"); 543 // for(int i = 0; i < partition1.getSize(); ++i) 544 // { 545 // 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]); 546 // } 568 547 569 548 iterator = partition2.getIterator(); … … 590 569 delete iterator; 591 570 592 // PRINTF(0)("\npartition 2:\n");593 // for(int i = 0; i < partition2.getSize(); ++i)594 // {595 // 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]);596 // }571 // PRINTF(0)("\npartition 2:\n"); 572 // for(int i = 0; i < partition2.getSize(); ++i) 573 // { 574 // 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]); 575 // } 597 576 } 598 577 … … 605 584 /* if the obb overlap, make subtests: check which node is realy overlaping */ 606 585 PRINTF(3)("Checking OBB %i vs %i: ", this->getIndex(), treeNode.getIndex()); 607 // if( unlikely(treeNode == NULL)) return;586 // if( unlikely(treeNode == NULL)) return; 608 587 609 588 … … 649 628 bool OBBTreeNode::overlapTest(const OBB& boxA, const OBB& boxB, const WorldEntity& nodeA, const WorldEntity& nodeB) const 650 629 { 651 // if( boxB == NULL || boxA == NULL)652 // return false;630 // if( boxB == NULL || boxA == NULL) 631 // return false; 653 632 654 633 /* first check all axis */ … … 671 650 t = nodeA.getAbsCoor() + nodeA.getAbsDir().apply(boxA.center) - ( nodeB.getAbsCoor() + nodeB.getAbsDir().apply(boxB.center)); 672 651 673 // printf("\n");674 // 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);675 // 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);676 // 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);677 //678 // 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);679 // 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);680 // 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);652 // printf("\n"); 653 // 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); 654 // 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); 655 // 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); 656 // 657 // 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); 658 // 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); 659 // 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); 681 660 682 661 … … 759 738 760 739 /* FIXME: there is no collision mark set now */ 761 // boxA.bCollided = true; /* use this ONLY(!!!!) for drawing operations */762 // boxB.bCollided = true;740 // boxA.bCollided = true; /* use this ONLY(!!!!) for drawing operations */ 741 // boxB.bCollided = true; 763 742 764 743 … … 865 844 if( !(drawMode & DRAW_SINGLE && depth != 0)) 866 845 { 867 Vector cen = this->bvElement->center; 868 Vector* axis = this->bvElement->axis; 869 float* len = this->bvElement->halfLength; 870 871 if( this->bvElement->bCollided) 872 { 873 glColor4f(1.0, 1.0, 1.0, .5); // COLLISION COLOR 874 } 875 else if( drawMode & DRAW_BV_BLENDED) 876 { 877 glColor4f(color.x, color.y, color.z, .5); 878 } 879 880 /* draw bounding box */ 881 if( drawMode & DRAW_BV_BLENDED) 882 glBegin(GL_QUADS); 883 else 884 glBegin(GL_LINE_LOOP); 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]); 888 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 889 cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 890 cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 891 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], 892 cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 893 cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 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 glEnd(); 898 899 if( drawMode & DRAW_BV_BLENDED) 900 glBegin(GL_QUADS); 901 else 902 glBegin(GL_LINE_LOOP); 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 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], 907 cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 908 cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 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 glEnd(); 916 917 if( drawMode & DRAW_BV_BLENDED) 918 glBegin(GL_QUADS); 919 else 920 glBegin(GL_LINE_LOOP); 921 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 922 cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 923 cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 924 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], 925 cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 926 cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 927 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 928 cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 929 cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 930 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], 931 cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], 932 cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); 933 glEnd(); 934 935 if( drawMode & DRAW_BV_BLENDED) 936 glBegin(GL_QUADS); 937 else 938 glBegin(GL_LINE_LOOP); 939 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 940 cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 941 cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 942 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], 943 cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], 944 cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); 945 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], 946 cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], 947 cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); 948 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 949 cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 950 cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 951 glEnd(); 952 953 954 if( drawMode & DRAW_BV_BLENDED) 955 { 956 glBegin(GL_QUADS); 957 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 958 cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 959 cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 846 Vector cen = this->bvElement->center; 847 Vector* axis = this->bvElement->axis; 848 float* len = this->bvElement->halfLength; 849 850 if( this->bvElement->bCollided) 851 { 852 glColor4f(1.0, 1.0, 1.0, .5); // COLLISION COLOR 853 } 854 else if( drawMode & DRAW_BV_BLENDED) 855 { 856 glColor4f(color.x, color.y, color.z, .5); 857 } 858 859 /* draw bounding box */ 860 if( drawMode & DRAW_BV_BLENDED) 861 glBegin(GL_QUADS); 862 else 863 glBegin(GL_LINE_LOOP); 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]); 960 867 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 961 868 cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], … … 964 871 cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 965 872 cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 873 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 874 cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 875 cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 876 glEnd(); 877 878 if( drawMode & DRAW_BV_BLENDED) 879 glBegin(GL_QUADS); 880 else 881 glBegin(GL_LINE_LOOP); 882 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 883 cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 884 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]); 966 888 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], 967 889 cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 968 890 cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 891 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 892 cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 893 cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 969 894 glEnd(); 970 895 971 glBegin(GL_QUADS); 896 if( drawMode & DRAW_BV_BLENDED) 897 glBegin(GL_QUADS); 898 else 899 glBegin(GL_LINE_LOOP); 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 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 907 cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 908 cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 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 glEnd(); 913 914 if( drawMode & DRAW_BV_BLENDED) 915 glBegin(GL_QUADS); 916 else 917 glBegin(GL_LINE_LOOP); 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]); 972 921 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], 973 922 cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], … … 976 925 cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], 977 926 cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); 978 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 979 cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 980 cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 981 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 982 cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 983 cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 927 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 928 cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 929 cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 984 930 glEnd(); 985 } 986 987 988 if( drawMode & DRAW_BV_BLENDED) 989 glColor3f(color.x, color.y, color.z); 931 932 933 if( drawMode & DRAW_BV_BLENDED) 934 { 935 glBegin(GL_QUADS); 936 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 937 cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 938 cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 939 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], 940 cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], 941 cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); 942 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], 943 cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 944 cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 945 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], 946 cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], 947 cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); 948 glEnd(); 949 950 glBegin(GL_QUADS); 951 glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], 952 cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], 953 cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); 954 glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], 955 cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], 956 cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); 957 glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 958 cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 959 cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 960 glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], 961 cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], 962 cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); 963 glEnd(); 964 } 965 966 967 if( drawMode & DRAW_BV_BLENDED) 968 glColor3f(color.x, color.y, color.z); 990 969 } 991 970 … … 1000 979 glColor4f(color.x, color.y, color.z, .6); 1001 980 1002 /* now draw the separation plane */1003 Vector a1 = this->bvElement->axis[(this->longestAxisIndex + 1)%3];1004 Vector a2 = this->bvElement->axis[(this->longestAxisIndex + 2)%3];1005 Vector c = this->bvElement->center;1006 float l1 = this->bvElement->halfLength[(this->longestAxisIndex + 1)%3];1007 float l2 = this->bvElement->halfLength[(this->longestAxisIndex + 2)%3];1008 glBegin(GL_QUADS);1009 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);1010 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);1011 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);1012 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);1013 glEnd();1014 1015 if( drawMode & DRAW_BV_BLENDED)1016 glColor4f(color.x, color.y, color.z, 1.0);981 /* now draw the separation plane */ 982 Vector a1 = this->bvElement->axis[(this->longestAxisIndex + 1)%3]; 983 Vector a2 = this->bvElement->axis[(this->longestAxisIndex + 2)%3]; 984 Vector c = this->bvElement->center; 985 float l1 = this->bvElement->halfLength[(this->longestAxisIndex + 1)%3]; 986 float l2 = this->bvElement->halfLength[(this->longestAxisIndex + 2)%3]; 987 glBegin(GL_QUADS); 988 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); 989 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); 990 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); 991 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); 992 glEnd(); 993 994 if( drawMode & DRAW_BV_BLENDED) 995 glColor4f(color.x, color.y, color.z, 1.0); 1017 996 1018 997 } … … 1038 1017 void OBBTreeNode::debug() const 1039 1018 { 1040 1041 /* 1042 for(int i = 0; i < length; i++) 1043 { 1044 PRINTF(3)("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]); 1045 } 1046 */ 1047 } 1019 PRINT(0)("========OBBTreeNode::debug()=====\n"); 1020 PRINT(0)(" Current depth: %i", this->depth); 1021 PRINT(0)(" "); 1022 PRINT(0)("=================================\n"); 1023 } -
branches/collision_detection/src/lib/collision_detection/obb_tree_node.h
r5718 r5825 21 21 22 22 //! A class that represents a bounding volume tree 23 class OBBTreeNode : public BVTreeNode { 23 class OBBTreeNode : public BVTreeNode 24 { 24 25 25 26 … … 29 30 30 31 /* this function returns the bounding volume of this tree node @return: returns the BV */ 31 virtual inline const BoundingVolume* getBV() const { return (BoundingVolume*)this->bvElement; } 32 virtual inline const BoundingVolume* getBV() const 33 { 34 return (BoundingVolume*)this->bvElement; 35 } 32 36 33 37 virtual void spawnBVTree(const sVec3D *verticesList, unsigned int length); … … 40 44 41 45 private: 42 void calculateBoxEigenvectors(OBB& box, const sVec3D* verticesList, unsigned int length);43 46 void calculateBoxAxis(OBB& box, const sVec3D* verticesList, unsigned int length); 44 47 … … 62 65 const OBBTree* obbTree; //!< reference to the obb tree 63 66 67 const modelInfo* modelInf; //!< pointer to the models modelInfo object 68 const int* triangleIndexes; //!< indexes to the used model triangles 69 64 70 const sVec3D* vertices; //!< pointer to the vertices data 65 71 int numOfVertices; //!< number of vertices in vertices data
Note: See TracChangeset
for help on using the changeset viewer.