Changeset 7732 in orxonox.OLD for trunk/src/lib/collision_detection
- Timestamp:
- May 19, 2006, 4:32:27 PM (19 years ago)
- Location:
- trunk/src/lib/collision_detection
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/collision_detection/bv_tree_node.h
r7711 r7732 39 39 40 40 41 41 42 private: 42 43 unsigned int treeIndex; //!< Index number of the BV in the tree 44 43 45 44 46 }; -
trunk/src/lib/collision_detection/obb_tree_node.cc
r7713 r7732 483 483 484 484 485 485 /** 486 * collides one tree with an other 487 * @param treeNode the other bv tree node 488 * @param nodeA the worldentity belonging to this bv 489 * @param nodeB the worldentity belonging to treeNode 490 */ 486 491 void OBBTreeNode::collideWith(BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB) 487 492 { 488 if( unlikely(treeNode == NULL)) 493 if( unlikely(treeNode == NULL || nodeA == NULL || nodeB == NULL)) 494 { 495 assert(false); 489 496 return; 497 } 490 498 491 499 PRINTF(4)("collideWith\n"); 492 /* if the obb overlap, make subtests: check which node is realy overlaping */ 493 PRINTF(4)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex()); 494 // if( unlikely(treeNode == NULL)) return; 495 496 497 if( this->overlapTest(*this->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB)) 498 { 499 PRINTF(4)("collision @ lvl %i, object %s vs. %s, (%p, %p)\n", this->depth, nodeA->getClassName(), nodeB->getClassName(), this->nodeLeft, this->nodeRight); 500 PRINTF(5)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex()); 501 502 // for now only collide with OBBTreeNodes 503 this->collideWithOBB((OBBTreeNode*)treeNode, nodeA, nodeB); 504 } 505 506 507 508 /** 509 * collides one obb tree with an other 510 * @param treeNode the other bv tree node 511 * @param nodeA the worldentity belonging to this bv 512 * @param nodeB the worldentity belonging to treeNode 513 */ 514 void OBBTreeNode::collideWithOBB(OBBTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB) 515 { 516 if( this->overlapTest(this->bvElement, (OBB*)treeNode->bvElement, nodeA, nodeB)) 517 { 518 PRINTF(5)("collision @ lvl %i, object %s vs. %s, (%p, %p)\n", this->depth, nodeA->getClassName(), nodeB->getClassName(), this->nodeLeft, this->nodeRight); 500 519 501 520 /* check if left node overlaps */ 502 521 if( likely( this->nodeLeft != NULL)) 503 522 { 504 PRINTF( 4)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode->getIndex());505 if( this->overlapTest( *this->nodeLeft->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB))523 PRINTF(5)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode->getIndex()); 524 if( this->overlapTest(this->nodeLeft->bvElement, treeNode->bvElement, nodeA, nodeB)) 506 525 { 507 this->nodeLeft->collideWith( (((const OBBTreeNode*)treeNode)->nodeLeft), nodeA, nodeB);508 this->nodeLeft->collideWith( (((const OBBTreeNode*)treeNode)->nodeRight), nodeA, nodeB);526 this->nodeLeft->collideWith(treeNode->nodeLeft, nodeA, nodeB); 527 this->nodeLeft->collideWith(treeNode->nodeRight, nodeA, nodeB); 509 528 } 510 529 } … … 512 531 if( likely( this->nodeRight != NULL)) 513 532 { 514 PRINTF( 4)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode->getIndex());515 if(this->overlapTest( *this->nodeRight->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB))533 PRINTF(5)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode->getIndex()); 534 if(this->overlapTest(this->nodeRight->bvElement, treeNode->bvElement, nodeA, nodeB)) 516 535 { 517 this->nodeRight->collideWith( (((const OBBTreeNode*)treeNode)->nodeLeft), nodeA, nodeB);518 this->nodeRight->collideWith( (((const OBBTreeNode*)treeNode)->nodeRight), nodeA, nodeB);536 this->nodeRight->collideWith(treeNode->nodeLeft, nodeA, nodeB); 537 this->nodeRight->collideWith(treeNode->nodeRight, nodeA, nodeB); 519 538 } 520 539 } … … 524 543 if( unlikely(this->nodeRight == NULL || this->nodeLeft == NULL)) 525 544 { 526 nodeA->collidesWith(nodeB, (((const OBBTreeNode*)&treeNode)->bvElement->center)); 527 545 nodeA->collidesWith(nodeB, treeNode->bvElement->center); 528 546 nodeB->collidesWith(nodeA, this->bvElement->center); 529 547 } … … 533 551 534 552 535 536 bool OBBTreeNode::overlapTest(OBB& boxA, OBB& boxB, WorldEntity* nodeA, WorldEntity* nodeB) 553 /** 554 * this actualy checks if one obb box touches the other 555 * @param boxA the box from nodeA 556 * @param boxB the box from nodeB 557 * @param nodeA the node itself 558 * @param nodeB the node itself 559 */ 560 bool OBBTreeNode::overlapTest(OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB) 537 561 { 538 562 //HACK remove this again … … 549 573 Vector rotAxisB[3]; 550 574 551 rotAxisA[0] = nodeA->getAbsDir().apply(boxA.axis[0]); 552 rotAxisA[1] = nodeA->getAbsDir().apply(boxA.axis[1]); 553 rotAxisA[2] = nodeA->getAbsDir().apply(boxA.axis[2]); 554 555 rotAxisB[0] = nodeB->getAbsDir().apply(boxB.axis[0]); 556 rotAxisB[1] = nodeB->getAbsDir().apply(boxB.axis[1]); 557 rotAxisB[2] = nodeB->getAbsDir().apply(boxB.axis[2]); 558 559 560 t = nodeA->getAbsCoor() + nodeA->getAbsDir().apply(boxA.center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(boxB.center)); 561 562 // printf("\n"); 563 // 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); 564 // 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); 565 // 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); 566 // 567 // 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); 568 // 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); 569 // 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); 570 575 rotAxisA[0] = nodeA->getAbsDir().apply(boxA->axis[0]); 576 rotAxisA[1] = nodeA->getAbsDir().apply(boxA->axis[1]); 577 rotAxisA[2] = nodeA->getAbsDir().apply(boxA->axis[2]); 578 579 rotAxisB[0] = nodeB->getAbsDir().apply(boxB->axis[0]); 580 rotAxisB[1] = nodeB->getAbsDir().apply(boxB->axis[1]); 581 rotAxisB[2] = nodeB->getAbsDir().apply(boxB->axis[2]); 582 583 t = nodeA->getAbsCoor() + nodeA->getAbsDir().apply(boxA->center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(boxB->center)); 571 584 572 585 /* All 3 axis of the object A */ … … 577 590 l = rotAxisA[j]; 578 591 579 rA += fabs(boxA .halfLength[0] * rotAxisA[0].dot(l));580 rA += fabs(boxA .halfLength[1] * rotAxisA[1].dot(l));581 rA += fabs(boxA .halfLength[2] * rotAxisA[2].dot(l));582 583 rB += fabs(boxB .halfLength[0] * rotAxisB[0].dot(l));584 rB += fabs(boxB .halfLength[1] * rotAxisB[1].dot(l));585 rB += fabs(boxB .halfLength[2] * rotAxisB[2].dot(l));592 rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l)); 593 rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l)); 594 rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l)); 595 596 rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l)); 597 rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l)); 598 rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l)); 586 599 587 600 PRINTF(5)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); … … 601 614 l = rotAxisB[j]; 602 615 603 rA += fabs(boxA .halfLength[0] * rotAxisA[0].dot(l));604 rA += fabs(boxA .halfLength[1] * rotAxisA[1].dot(l));605 rA += fabs(boxA .halfLength[2] * rotAxisA[2].dot(l));606 607 rB += fabs(boxB .halfLength[0] * rotAxisB[0].dot(l));608 rB += fabs(boxB .halfLength[1] * rotAxisB[1].dot(l));609 rB += fabs(boxB .halfLength[2] * rotAxisB[2].dot(l));616 rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l)); 617 rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l)); 618 rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l)); 619 620 rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l)); 621 rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l)); 622 rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l)); 610 623 611 624 PRINTF(5)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); … … 629 642 l = rotAxisA[j].cross(rotAxisB[k]); 630 643 631 rA += fabs(boxA .halfLength[0] * rotAxisA[0].dot(l));632 rA += fabs(boxA .halfLength[1] * rotAxisA[1].dot(l));633 rA += fabs(boxA .halfLength[2] * rotAxisA[2].dot(l));634 635 rB += fabs(boxB .halfLength[0] * rotAxisB[0].dot(l));636 rB += fabs(boxB .halfLength[1] * rotAxisB[1].dot(l));637 rB += fabs(boxB .halfLength[2] * rotAxisB[2].dot(l));644 rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l)); 645 rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l)); 646 rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l)); 647 648 rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l)); 649 rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l)); 650 rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l)); 638 651 639 652 PRINTF(5)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); … … 648 661 649 662 /* FIXME: there is no collision mark set now */ 650 boxA .bCollided = true; /* use this ONLY(!!!!) for drawing operations */651 boxB .bCollided = true;663 boxA->bCollided = true; /* use this ONLY(!!!!) for drawing operations */ 664 boxB->bCollided = true; 652 665 653 666 … … 655 668 return true; 656 669 } 657 658 659 660 661 662 663 664 665 670 666 671 -
trunk/src/lib/collision_detection/obb_tree_node.h
r7711 r7732 48 48 void forkBox(OBB& box); 49 49 50 bool overlapTest(OBB& boxA, OBB& boxB, WorldEntity* nodeA, WorldEntity* nodeB); 50 void collideWithOBB(OBBTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB); 51 bool overlapTest(OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB); 51 52 52 53
Note: See TracChangeset
for help on using the changeset viewer.