Changeset 5718 in orxonox.OLD for branches/collision_detection
- Timestamp:
- Nov 23, 2005, 1:06:44 AM (19 years ago)
- Location:
- branches/collision_detection/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/collision_detection/src/lib/collision_detection/bv_tree.h
r5716 r5718 43 43 virtual void flushTree() = 0; 44 44 45 virtual void collideWith(BVTree* tree, WorldEntity* nodeA, WorldEntity* nodeB) = 0; 46 virtual void collideWith(WorldEntity* entity1, WorldEntity* entity2) = 0; 45 virtual void collideWith(const WorldEntity& entity1, const WorldEntity& entity2) const = 0; 47 46 48 47 /** @param depth: depth, @param drawMode: how to draw the Model */ -
branches/collision_detection/src/lib/collision_detection/bv_tree_node.h
r5717 r5718 19 19 template<class T> class tList; 20 20 21 21 22 //! A class that represents a bounding volume tree 22 23 class BVTreeNode : public BaseObject { 24 23 25 24 26 public: -
branches/collision_detection/src/lib/collision_detection/cd_engine.cc
r5717 r5718 94 94 if( likely(entity2 != this->terrain)) 95 95 { 96 printf("checking object %s against %s\n", entity1->getName(), entity2->getName());96 //printf("checking object %s against %s\n", entity1->getName(), entity2->getName()); 97 97 tree = entity1->getOBBTree(); 98 98 -
branches/collision_detection/src/lib/collision_detection/obb_tree.cc
r5717 r5718 104 104 105 105 106 void OBBTree::collideWith(WorldEntity* entity1, WorldEntity* entity2)107 {108 if( likely(entity2->getOBBTree() != NULL) )109 this->rootNode->collideWith(((OBBTree*)entity2->getOBBTree())->getRootNode(), entity1, entity2);110 }111 112 113 106 /** 114 107 * this collides two bvtrees together. the trees are attached to pnodes Objects A and B 115 * @param tree: the other tree to collide with (Object B)116 108 * @param nodeA: PNode of object A 117 109 * @param nodeB: Pnode of object B 118 110 */ 119 void OBBTree::collideWith( BVTree* tree, WorldEntity* nodeA, WorldEntity* nodeB)111 void OBBTree::collideWith(const WorldEntity& entity1, const WorldEntity& entity2) const 120 112 { 121 this->rootNode->collideWith(((OBBTree*)tree)->getRootNode(), nodeA, nodeB); 113 if( likely(entity2.getOBBTree() != NULL) ) 114 this->rootNode->collideWith(*(((OBBTree*)entity2.getOBBTree())->getRootNode()), entity1, entity2); 122 115 } 116 123 117 124 118 -
branches/collision_detection/src/lib/collision_detection/obb_tree.h
r5717 r5718 29 29 virtual void flushTree(); 30 30 31 virtual void collideWith(BVTree* tree, WorldEntity* nodeA, WorldEntity* nodeB); 32 virtual void collideWith(WorldEntity* entity1, WorldEntity* entity2); 31 virtual void collideWith(const WorldEntity& entity1, const WorldEntity& entity2) const; 33 32 34 33 virtual void drawBV(int depth, int drawMode) const; -
branches/collision_detection/src/lib/collision_detection/obb_tree_node.cc
r5717 r5718 600 600 601 601 602 void OBBTreeNode::collideWith( BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity*nodeB) const602 void OBBTreeNode::collideWith(const BVTreeNode& treeNode, const WorldEntity& nodeA, const WorldEntity& nodeB) const 603 603 { 604 604 PRINTF(3)("collideWith\n"); 605 605 /* if the obb overlap, make subtests: check which node is realy overlaping */ 606 PRINTF(3)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex()); 607 if( unlikely(treeNode == NULL)) return; 608 609 if( this->overlapTest(this->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB)) 610 { 611 PRINTF(3)("collision @ lvl %i, object %s vs. %s, (%p, %p)\n", this->depth, nodeA->getClassName(), nodeB->getClassName(), this->nodeLeft, this->nodeRight); 606 PRINTF(3)("Checking OBB %i vs %i: ", this->getIndex(), treeNode.getIndex()); 607 // if( unlikely(treeNode == NULL)) return; 608 609 610 if( this->overlapTest(*this->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB)) 611 { 612 PRINTF(3)("collision @ lvl %i, object %s vs. %s, (%p, %p)\n", this->depth, nodeA.getClassName(), nodeB.getClassName(), this->nodeLeft, this->nodeRight); 612 613 613 614 /* check if left node overlaps */ 614 615 if( likely( this->nodeLeft != NULL)) 615 616 { 616 PRINTF(3)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode ->getIndex());617 if( this->overlapTest( this->nodeLeft->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))617 PRINTF(3)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode.getIndex()); 618 if( this->overlapTest(*this->nodeLeft->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB)) 618 619 { 619 this->nodeLeft->collideWith( ((OBBTreeNode*)treeNode)->nodeLeft, nodeA, nodeB);620 this->nodeLeft->collideWith( ((OBBTreeNode*)treeNode)->nodeRight, nodeA, nodeB);620 this->nodeLeft->collideWith(*(((const OBBTreeNode*)&treeNode)->nodeLeft), nodeA, nodeB); 621 this->nodeLeft->collideWith(*(((const OBBTreeNode*)&treeNode)->nodeRight), nodeA, nodeB); 621 622 } 622 623 } … … 624 625 if( likely( this->nodeRight != NULL)) 625 626 { 626 PRINTF(3)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode ->getIndex());627 if(this->overlapTest( this->nodeRight->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))627 PRINTF(3)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode.getIndex()); 628 if(this->overlapTest(*this->nodeRight->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB)) 628 629 { 629 this->nodeRight->collideWith(((OBBTreeNode*)treeNode)->nodeLeft, nodeA, nodeB);630 this->nodeRight->collideWith(((OBBTreeNode*)treeNode)->nodeRight, nodeA, nodeB);630 this->nodeRight->collideWith(*(((const OBBTreeNode*)&treeNode)->nodeLeft), nodeA, nodeB); 631 this->nodeRight->collideWith(*(((const OBBTreeNode*)&treeNode)->nodeRight), nodeA, nodeB); 631 632 } 632 633 } 633 634 634 635 /* so there is a collision and this is the last box in the tree (i.e. leaf) */ 636 /* FIXME: If we would choose || insead of && there would also be asymmetrical cases supported */ 635 637 if( unlikely(this->nodeRight == NULL && this->nodeLeft == NULL)) 636 638 { 637 nodeA ->collidesWith(nodeB, ((OBBTreeNode*)treeNode)->bvElement->center);638 639 nodeB ->collidesWith(nodeA, this->bvElement->center);640 } 641 642 } 643 } 644 645 646 647 bool OBBTreeNode::overlapTest( OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity*nodeB) const648 { 649 if( boxB == NULL || boxA == NULL)650 return false;639 nodeA.collidesWith(nodeB, (((const OBBTreeNode*)&treeNode)->bvElement->center)); 640 641 nodeB.collidesWith(nodeA, this->bvElement->center); 642 } 643 644 } 645 } 646 647 648 649 bool OBBTreeNode::overlapTest(const OBB& boxA, const OBB& boxB, const WorldEntity& nodeA, const WorldEntity& nodeB) const 650 { 651 // if( boxB == NULL || boxA == NULL) 652 // return false; 651 653 652 654 /* first check all axis */ … … 658 660 Vector rotAxisB[3]; 659 661 660 rotAxisA[0] = nodeA ->getAbsDir().apply(boxA->axis[0]);661 rotAxisA[1] = nodeA ->getAbsDir().apply(boxA->axis[1]);662 rotAxisA[2] = nodeA ->getAbsDir().apply(boxA->axis[2]);663 664 rotAxisB[0] = nodeB ->getAbsDir().apply(boxB->axis[0]);665 rotAxisB[1] = nodeB ->getAbsDir().apply(boxB->axis[1]);666 rotAxisB[2] = nodeB ->getAbsDir().apply(boxB->axis[2]);667 668 669 t = nodeA ->getAbsCoor() + nodeA->getAbsDir().apply(boxA->center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(boxB->center));662 rotAxisA[0] = nodeA.getAbsDir().apply(boxA.axis[0]); 663 rotAxisA[1] = nodeA.getAbsDir().apply(boxA.axis[1]); 664 rotAxisA[2] = nodeA.getAbsDir().apply(boxA.axis[2]); 665 666 rotAxisB[0] = nodeB.getAbsDir().apply(boxB.axis[0]); 667 rotAxisB[1] = nodeB.getAbsDir().apply(boxB.axis[1]); 668 rotAxisB[2] = nodeB.getAbsDir().apply(boxB.axis[2]); 669 670 671 t = nodeA.getAbsCoor() + nodeA.getAbsDir().apply(boxA.center) - ( nodeB.getAbsCoor() + nodeB.getAbsDir().apply(boxB.center)); 670 672 671 673 // printf("\n"); … … 686 688 l = rotAxisA[j]; 687 689 688 rA += fabs(boxA ->halfLength[0] * rotAxisA[0].dot(l));689 rA += fabs(boxA ->halfLength[1] * rotAxisA[1].dot(l));690 rA += fabs(boxA ->halfLength[2] * rotAxisA[2].dot(l));691 692 rB += fabs(boxB ->halfLength[0] * rotAxisB[0].dot(l));693 rB += fabs(boxB ->halfLength[1] * rotAxisB[1].dot(l));694 rB += fabs(boxB ->halfLength[2] * rotAxisB[2].dot(l));690 rA += fabs(boxA.halfLength[0] * rotAxisA[0].dot(l)); 691 rA += fabs(boxA.halfLength[1] * rotAxisA[1].dot(l)); 692 rA += fabs(boxA.halfLength[2] * rotAxisA[2].dot(l)); 693 694 rB += fabs(boxB.halfLength[0] * rotAxisB[0].dot(l)); 695 rB += fabs(boxB.halfLength[1] * rotAxisB[1].dot(l)); 696 rB += fabs(boxB.halfLength[2] * rotAxisB[2].dot(l)); 695 697 696 698 PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); … … 710 712 l = rotAxisB[j]; 711 713 712 rA += fabs(boxA ->halfLength[0] * rotAxisA[0].dot(l));713 rA += fabs(boxA ->halfLength[1] * rotAxisA[1].dot(l));714 rA += fabs(boxA ->halfLength[2] * rotAxisA[2].dot(l));715 716 rB += fabs(boxB ->halfLength[0] * rotAxisB[0].dot(l));717 rB += fabs(boxB ->halfLength[1] * rotAxisB[1].dot(l));718 rB += fabs(boxB ->halfLength[2] * rotAxisB[2].dot(l));714 rA += fabs(boxA.halfLength[0] * rotAxisA[0].dot(l)); 715 rA += fabs(boxA.halfLength[1] * rotAxisA[1].dot(l)); 716 rA += fabs(boxA.halfLength[2] * rotAxisA[2].dot(l)); 717 718 rB += fabs(boxB.halfLength[0] * rotAxisB[0].dot(l)); 719 rB += fabs(boxB.halfLength[1] * rotAxisB[1].dot(l)); 720 rB += fabs(boxB.halfLength[2] * rotAxisB[2].dot(l)); 719 721 720 722 PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); … … 738 740 l = rotAxisA[j].cross(rotAxisB[k]); 739 741 740 rA += fabs(boxA ->halfLength[0] * rotAxisA[0].dot(l));741 rA += fabs(boxA ->halfLength[1] * rotAxisA[1].dot(l));742 rA += fabs(boxA ->halfLength[2] * rotAxisA[2].dot(l));743 744 rB += fabs(boxB ->halfLength[0] * rotAxisB[0].dot(l));745 rB += fabs(boxB ->halfLength[1] * rotAxisB[1].dot(l));746 rB += fabs(boxB ->halfLength[2] * rotAxisB[2].dot(l));742 rA += fabs(boxA.halfLength[0] * rotAxisA[0].dot(l)); 743 rA += fabs(boxA.halfLength[1] * rotAxisA[1].dot(l)); 744 rA += fabs(boxA.halfLength[2] * rotAxisA[2].dot(l)); 745 746 rB += fabs(boxB.halfLength[0] * rotAxisB[0].dot(l)); 747 rB += fabs(boxB.halfLength[1] * rotAxisB[1].dot(l)); 748 rB += fabs(boxB.halfLength[2] * rotAxisB[2].dot(l)); 747 749 748 750 PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); … … 756 758 } 757 759 758 759 boxA->bCollided = true; /* use this ONLY(!!!!) for drawing operations */ 760 boxB->bCollided = true; 760 /* FIXME: there is no collision mark set now */ 761 // boxA.bCollided = true; /* use this ONLY(!!!!) for drawing operations */ 762 // boxB.bCollided = true; 763 764 761 765 PRINTF(3)("Kollision!\n"); 762 766 return true; -
branches/collision_detection/src/lib/collision_detection/obb_tree_node.h
r5717 r5718 34 34 virtual void spawnBVTree(const modelInfo& modelInf, const int* triangleIndexes, unsigned int length); 35 35 36 virtual void collideWith( BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity*nodeB) const;36 virtual void collideWith(const BVTreeNode& treeNode, const WorldEntity& nodeA, const WorldEntity& nodeB) const; 37 37 virtual void drawBV(int depth, int drawMode, const Vector& color = Vector(1,0,0), bool top = true) const; 38 38 void debug() const; … … 48 48 void forkBox(OBB& box); 49 49 50 bool overlapTest( OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity*nodeB) const;50 bool overlapTest(const OBB& boxA, const OBB& boxB, const WorldEntity& nodeA, const WorldEntity& nodeB) const; 51 51 52 52 -
branches/collision_detection/src/world_entities/world_entity.cc
r5717 r5718 147 147 * Implement behaviour like damage application or other miscellaneous collision stuff in this function 148 148 */ 149 void WorldEntity::collidesWith( WorldEntity* entity, const Vector& location)149 void WorldEntity::collidesWith(const WorldEntity& entity, const Vector& location) const 150 150 { 151 151 /** -
branches/collision_detection/src/world_entities/world_entity.h
r5717 r5718 43 43 virtual void tick (float time); 44 44 virtual void draw () const; 45 virtual void collidesWith ( WorldEntity* entity, const Vector& location);45 virtual void collidesWith (const WorldEntity& entity, const Vector& location) const; 46 46 47 47 void drawBVTree(unsigned int depth, int drawMode) const;
Note: See TracChangeset
for help on using the changeset viewer.