Changeset 4700 in orxonox.OLD for orxonox/trunk/src/lib/collision_detection
- Timestamp:
- Jun 26, 2005, 12:37:38 PM (19 years ago)
- Location:
- orxonox/trunk/src/lib/collision_detection
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/collision_detection/bv_tree.h
r4695 r4700 15 15 class BoundingVolume; 16 16 class BVTreeNode; 17 class PNode; 17 18 18 19 typedef enum DrawMode … … 39 40 virtual void flushTree() = NULL; 40 41 41 virtual void collideWith(BVTree* tree ) = NULL;42 virtual void collideWith(BVTree* tree, PNode* nodeA, PNode* nodeB) = NULL; 42 43 43 44 virtual void drawBV(int depth, int drawMode) const = NULL; -
orxonox/trunk/src/lib/collision_detection/bv_tree_node.h
r4695 r4700 14 14 class BoundingVolume; 15 15 class BVTree; 16 //struct sVec3D;16 class PNode; 17 17 template<class T> class tList; 18 18 … … 29 29 inline const int getIndex() { return this->treeIndex; } 30 30 31 virtual void collideWith(BVTreeNode* treeNode ) = NULL;31 virtual void collideWith(BVTreeNode* treeNode, PNode* nodeA, PNode* nodeB) = NULL; 32 32 33 33 virtual void drawBV(int depth, int drawMode) const = NULL; -
orxonox/trunk/src/lib/collision_detection/obb_tree.cc
r4696 r4700 22 22 #include "compiler.h" 23 23 #include "material.h" 24 #include "p_node.h" 24 25 25 26 using namespace std; … … 103 104 104 105 105 void OBBTree::collideWith(BVTree* tree )106 void OBBTree::collideWith(BVTree* tree, PNode* nodeA, PNode* nodeB) 106 107 { 107 this->rootNode->collideWith(((OBBTree*)tree)->getRootNode() );108 this->rootNode->collideWith(((OBBTree*)tree)->getRootNode(), nodeA, nodeB); 108 109 } 109 110 -
orxonox/trunk/src/lib/collision_detection/obb_tree.h
r4696 r4700 14 14 class Material; 15 15 class OBBTreeNode; 16 class PNode; 16 17 17 18 //! A class for representing an obb tree … … 27 28 virtual void flushTree(); 28 29 29 virtual void collideWith(BVTree* tree );30 virtual void collideWith(BVTree* tree, PNode* nodeA, PNode* nodeB); 30 31 31 32 virtual void drawBV(int depth, int drawMode) const; -
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 -
orxonox/trunk/src/lib/collision_detection/obb_tree_node.h
r4695 r4700 17 17 class OBBTree; 18 18 class Plane; 19 class PNode; 19 20 //struct sVec3D; 20 21 … … 33 34 inline void setTreeRef(OBBTree* tree) { this->obbTree = tree;} 34 35 35 virtual void collideWith(BVTreeNode* treeNode );36 virtual void collideWith(BVTreeNode* treeNode, PNode* nodeA, PNode* nodeB); 36 37 37 38 virtual void drawBV(int depth, int drawMode) const; … … 45 46 void forkBox(OBB* box); 46 47 47 bool overlapTest(OBB* boxA, OBB* boxB );48 bool overlapTest(OBB* boxA, OBB* boxB, PNode* nodeA, PNode* nodeB); 48 49 49 50 protected:
Note: See TracChangeset
for help on using the changeset viewer.