Changeset 4700 in orxonox.OLD for orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc
- Timestamp:
- Jun 26, 2005, 12:37:38 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc
r4696 r4700 22 22 #include "vector.h" 23 23 #include "abstract_model.h" 24 #include "p_node.h" 24 25 25 26 #include <math.h> … … 604 605 605 606 606 void OBBTreeNode::collideWith(BVTreeNode* treeNode )607 { 608 PRINTF(0)("collideWith ");607 void OBBTreeNode::collideWith(BVTreeNode* treeNode, PNode* nodeA, PNode* nodeB) 608 { 609 PRINTF(0)("collideWith\n"); 609 610 /* if the obb overlap, make subtests: check which node is realy overlaping */ 610 if( this->overlapTest(this->bvElement, ((OBBTreeNode*)treeNode)->bvElement ))611 if( this->overlapTest(this->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB)) 611 612 { 612 613 /* check if left node overlaps */ 613 614 if( unlikely( this->nodeLeft != NULL)) 614 if( this->overlapTest(this->nodeLeft->bvElement, ((OBBTreeNode*)treeNode)->bvElement ))615 this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeLeft );615 if( this->overlapTest(this->nodeLeft->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB)) 616 this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeLeft, nodeA, nodeB); 616 617 /* check if right node overlaps */ 617 618 if( unlikely( this->nodeRight != NULL)) 618 if(this->overlapTest(this->nodeRight->bvElement, ((OBBTreeNode*)treeNode)->bvElement)) 619 this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeRight); 620 } 621 } 622 623 624 625 bool OBBTreeNode::overlapTest(OBB* boxA, OBB* boxB) 626 { 619 if(this->overlapTest(this->nodeRight->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB)) 620 this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeRight, nodeA, nodeB); 621 } 622 } 623 624 625 626 bool OBBTreeNode::overlapTest(OBB* boxA, OBB* boxB, PNode* nodeA, PNode* nodeB) 627 { 628 629 627 630 /* first check all axis */ 628 float r = 0.0f; 629 Vector l = boxA->axis[0]; 630 for(int i = 0; i < 3; ++i) 631 { 632 r += boxA->halfLength[i] * boxA->axis[i].dot(l); 633 } 634 635 printf("r = %f\n", r); 636 /* now check all orthogonals from the axis */ 631 Vector t = nodeA->getAbsCoor() + *boxA->center - ( nodeB->getAbsCoor() + *boxB->center); 632 float rA = 0.0f; 633 float rB = 0.0f; 634 Vector l; 635 636 for(int j = 0; j < 3; ++j) 637 { 638 rA = 0.0f; 639 rB = 0.0f; 640 l = boxA->axis[j]; 641 642 for(int i = 0; i < 3; ++i) 643 { 644 rA += fabs(boxA->halfLength[i] * boxA->axis[i].dot(l)); 645 } 646 647 for(int i = 0; i < 3; ++i) 648 { 649 rB += fabs(boxB->halfLength[i] * boxB->axis[i].dot(l)); 650 } 651 652 PRINTF(0)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); 653 654 if( (rA + rB) < fabs(t.dot(l))) 655 PRINTF(0)(" - The Boxes are disjoint!\n"); 656 else 657 PRINTF(0)(" - The Boxes are not disjoint\n"); 658 659 PRINTF(0)("rA = %f, rB = %f\n", rA, rB); 660 661 662 /* now check all orthogonals from the axis */ 663 664 } 665 return false; 637 666 } 638 667
Note: See TracChangeset
for help on using the changeset viewer.