Changeset 6890 in orxonox.OLD for branches/cd_merge/src/lib
- Timestamp:
- Jan 31, 2006, 1:55:42 PM (19 years ago)
- Location:
- branches/cd_merge/src/lib/collision_detection
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/cd_merge/src/lib/collision_detection/bv_tree.h
r6657 r6890 44 44 virtual void flushTree() = 0; 45 45 46 virtual void collideWith( const WorldEntity& entity1, const WorldEntity&entity2) const = 0;46 virtual void collideWith(WorldEntity* entity1, WorldEntity* entity2) const = 0; 47 47 48 48 virtual void drawBV(int depth, int drawMode) const = 0; -
branches/cd_merge/src/lib/collision_detection/bv_tree_node.h
r6657 r6890 35 35 36 36 virtual void spawnBVTree(const modelInfo& modInfo, const int* triangleIndexes, int length) = 0; 37 virtual void collideWith(const BVTreeNode & treeNode, const WorldEntity& nodeA, const WorldEntity& nodeB) const= 0;37 virtual void collideWith(const BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB) = 0; 38 38 virtual void drawBV(int depth, int drawMode, const Vector& color = Vector(1,0,0), bool top = true) const = 0; 39 39 -
branches/cd_merge/src/lib/collision_detection/obb_tree.cc
r6657 r6890 31 31 * standard constructor 32 32 */ 33 OBBTree::OBBTree(int depth, const modelInfo &modelInf)33 OBBTree::OBBTree(int depth, const modelInfo* modelInf) 34 34 : BVTree() 35 35 { 36 36 this->depth = depth; 37 37 this->init(); 38 this->spawnBVTree( modelInf);38 this->spawnBVTree(*modelInf); 39 39 } 40 40 … … 92 92 * @param nodeB: Pnode of object B 93 93 */ 94 void OBBTree::collideWith( const WorldEntity& entity1, const WorldEntity&entity2) const94 void OBBTree::collideWith(WorldEntity* entity1, WorldEntity* entity2) const 95 95 { 96 if( likely(entity2 .getOBBTree() != NULL) )97 this->rootNode->collideWith( *(((OBBTree*)entity2.getOBBTree())->getRootNode()), entity1, entity2);96 if( likely(entity2->getOBBTree() != NULL) ) 97 this->rootNode->collideWith(((OBBTree*)entity2->getOBBTree())->getRootNode(), entity1, entity2); 98 98 } 99 99 -
branches/cd_merge/src/lib/collision_detection/obb_tree.h
r6657 r6890 21 21 22 22 public: 23 OBBTree(int depth, const modelInfo &modInfo);23 OBBTree(int depth, const modelInfo* modInfo); 24 24 virtual ~OBBTree(); 25 25 void init(); … … 28 28 virtual void flushTree(); 29 29 30 virtual void collideWith( const WorldEntity& entity1, const WorldEntity&entity2) const;30 virtual void collideWith(WorldEntity* entity1, WorldEntity* entity2) const; 31 31 virtual void drawBV(int depth, int drawMode) const; 32 32 -
branches/cd_merge/src/lib/collision_detection/obb_tree_node.cc
r6657 r6890 515 515 516 516 517 void OBBTreeNode::collideWith(const BVTreeNode & treeNode, const WorldEntity& nodeA, const WorldEntity& nodeB) const517 void OBBTreeNode::collideWith(const BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB) 518 518 { 519 519 PRINTF(3)("collideWith\n"); 520 520 /* if the obb overlap, make subtests: check which node is realy overlaping */ 521 PRINTF(3)("Checking OBB %i vs %i: ", this->getIndex(), treeNode .getIndex());521 PRINTF(3)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex()); 522 522 // if( unlikely(treeNode == NULL)) return; 523 523 524 524 525 if( this->overlapTest( *this->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB))526 { 527 PRINTF(3)("collision @ lvl %i, object %s vs. %s, (%p, %p)\n", this->depth, nodeA .getClassName(), nodeB.getClassName(), this->nodeLeft, this->nodeRight);525 if( this->overlapTest(this->bvElement, ((const OBBTreeNode*)&treeNode)->bvElement, nodeA, nodeB)) 526 { 527 PRINTF(3)("collision @ lvl %i, object %s vs. %s, (%p, %p)\n", this->depth, nodeA->getClassName(), nodeB->getClassName(), this->nodeLeft, this->nodeRight); 528 528 529 529 /* check if left node overlaps */ 530 530 if( likely( this->nodeLeft != NULL)) 531 531 { 532 PRINTF(3)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode .getIndex());533 if( this->overlapTest( *this->nodeLeft->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA,nodeB))532 PRINTF(3)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode->getIndex()); 533 if( this->overlapTest(this->nodeLeft->bvElement, ((const OBBTreeNode*)&treeNode)->bvElement, nodeA,nodeB)) 534 534 { 535 this->nodeLeft->collideWith( *(((const OBBTreeNode*)&treeNode)->nodeLeft), nodeA, nodeB);536 this->nodeLeft->collideWith( *(((const OBBTreeNode*)&treeNode)->nodeRight), nodeA, nodeB);535 this->nodeLeft->collideWith(((const OBBTreeNode*)&treeNode)->nodeLeft, nodeA, nodeB); 536 this->nodeLeft->collideWith(((const OBBTreeNode*)&treeNode)->nodeRight, nodeA, nodeB); 537 537 } 538 538 } … … 540 540 if( likely( this->nodeRight != NULL)) 541 541 { 542 PRINTF(3)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode .getIndex());543 if(this->overlapTest( *this->nodeRight->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB))542 PRINTF(3)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode->getIndex()); 543 if(this->overlapTest(this->nodeRight->bvElement, ((const OBBTreeNode*)&treeNode)->bvElement, nodeA, nodeB)) 544 544 { 545 this->nodeRight->collideWith( *(((const OBBTreeNode*)&treeNode)->nodeLeft), nodeA, nodeB);546 this->nodeRight->collideWith( *(((const OBBTreeNode*)&treeNode)->nodeRight), nodeA, nodeB);545 this->nodeRight->collideWith(((const OBBTreeNode*)&treeNode)->nodeLeft, nodeA, nodeB); 546 this->nodeRight->collideWith(((const OBBTreeNode*)&treeNode)->nodeRight, nodeA, nodeB); 547 547 } 548 548 } … … 552 552 if( unlikely(this->nodeRight == NULL && this->nodeLeft == NULL)) 553 553 { 554 nodeA .collidesWith(nodeB, (((const OBBTreeNode*)&treeNode)->bvElement->center));555 556 nodeB .collidesWith(nodeA, this->bvElement->center);557 } 558 559 } 560 } 561 562 563 564 bool OBBTreeNode::overlapTest(const OBB & boxA, const OBB& boxB, const WorldEntity& nodeA, const WorldEntity& nodeB) const554 nodeA->collidesWith(nodeB, ((const OBBTreeNode*)&treeNode)->bvElement->center); 555 556 nodeB->collidesWith(nodeA, this->bvElement->center); 557 } 558 559 } 560 } 561 562 563 564 bool OBBTreeNode::overlapTest(const OBB* boxA, const OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB) 565 565 { 566 566 // if( boxB == NULL || boxA == NULL) … … 575 575 Vector rotAxisB[3]; 576 576 577 rotAxisA[0] = nodeA .getAbsDir().apply(boxA.axis[0]);578 rotAxisA[1] = nodeA .getAbsDir().apply(boxA.axis[1]);579 rotAxisA[2] = nodeA .getAbsDir().apply(boxA.axis[2]);580 581 rotAxisB[0] = nodeB .getAbsDir().apply(boxB.axis[0]);582 rotAxisB[1] = nodeB .getAbsDir().apply(boxB.axis[1]);583 rotAxisB[2] = nodeB .getAbsDir().apply(boxB.axis[2]);584 585 586 t = nodeA .getAbsCoor() + nodeA.getAbsDir().apply(boxA.center) - ( nodeB.getAbsCoor() + nodeB.getAbsDir().apply(boxB.center));577 rotAxisA[0] = nodeA->getAbsDir().apply(boxA->axis[0]); 578 rotAxisA[1] = nodeA->getAbsDir().apply(boxA->axis[1]); 579 rotAxisA[2] = nodeA->getAbsDir().apply(boxA->axis[2]); 580 581 rotAxisB[0] = nodeB->getAbsDir().apply(boxB->axis[0]); 582 rotAxisB[1] = nodeB->getAbsDir().apply(boxB->axis[1]); 583 rotAxisB[2] = nodeB->getAbsDir().apply(boxB->axis[2]); 584 585 586 t = nodeA->getAbsCoor() + nodeA->getAbsDir().apply(boxA->center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(boxB->center)); 587 587 588 588 // printf("\n"); … … 603 603 l = rotAxisA[j]; 604 604 605 rA += fabs(boxA .halfLength[0] * rotAxisA[0].dot(l));606 rA += fabs(boxA .halfLength[1] * rotAxisA[1].dot(l));607 rA += fabs(boxA .halfLength[2] * rotAxisA[2].dot(l));608 609 rB += fabs(boxB .halfLength[0] * rotAxisB[0].dot(l));610 rB += fabs(boxB .halfLength[1] * rotAxisB[1].dot(l));611 rB += fabs(boxB .halfLength[2] * rotAxisB[2].dot(l));605 rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l)); 606 rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l)); 607 rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l)); 608 609 rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l)); 610 rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l)); 611 rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l)); 612 612 613 613 PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); … … 627 627 l = rotAxisB[j]; 628 628 629 rA += fabs(boxA .halfLength[0] * rotAxisA[0].dot(l));630 rA += fabs(boxA .halfLength[1] * rotAxisA[1].dot(l));631 rA += fabs(boxA .halfLength[2] * rotAxisA[2].dot(l));632 633 rB += fabs(boxB .halfLength[0] * rotAxisB[0].dot(l));634 rB += fabs(boxB .halfLength[1] * rotAxisB[1].dot(l));635 rB += fabs(boxB .halfLength[2] * rotAxisB[2].dot(l));629 rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l)); 630 rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l)); 631 rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l)); 632 633 rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l)); 634 rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l)); 635 rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l)); 636 636 637 637 PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); … … 655 655 l = rotAxisA[j].cross(rotAxisB[k]); 656 656 657 rA += fabs(boxA .halfLength[0] * rotAxisA[0].dot(l));658 rA += fabs(boxA .halfLength[1] * rotAxisA[1].dot(l));659 rA += fabs(boxA .halfLength[2] * rotAxisA[2].dot(l));660 661 rB += fabs(boxB .halfLength[0] * rotAxisB[0].dot(l));662 rB += fabs(boxB .halfLength[1] * rotAxisB[1].dot(l));663 rB += fabs(boxB .halfLength[2] * rotAxisB[2].dot(l));657 rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l)); 658 rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l)); 659 rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l)); 660 661 rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l)); 662 rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l)); 663 rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l)); 664 664 665 665 PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); … … 674 674 675 675 /* FIXME: there is no collision mark set now */ 676 // boxA .bCollided = true; /* use this ONLY(!!!!) for drawing operations */677 // boxB .bCollided = true;676 // boxA->bCollided = true; /* use this ONLY(!!!!) for drawing operations */ 677 // boxB->bCollided = true; 678 678 679 679 -
branches/cd_merge/src/lib/collision_detection/obb_tree_node.h
r6657 r6890 9 9 10 10 #include "bv_tree_node.h" 11 #include "plane.h" 11 12 12 13 … … 32 33 virtual void spawnBVTree(const modelInfo& modelInf, const int* triangleIndexes, int length); 33 34 34 virtual void collideWith(const BVTreeNode & treeNode, const WorldEntity& nodeA, const WorldEntity& nodeB) const;35 virtual void collideWith(const BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB); 35 36 virtual void drawBV(int depth, int drawMode, const Vector& color = Vector(1,0,0), bool top = true) const; 36 37 void debug() const; … … 48 49 void forkBox(OBB& box); 49 50 50 bool overlapTest(const OBB & boxA, const OBB& boxB, const WorldEntity& nodeA, const WorldEntity& nodeB) const;51 bool overlapTest(const OBB* boxA, const OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB); 51 52 52 53
Note: See TracChangeset
for help on using the changeset viewer.