Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5718 in orxonox.OLD for branches/collision_detection/src


Ignore:
Timestamp:
Nov 23, 2005, 1:06:44 AM (19 years ago)
Author:
patrick
Message:

collision_detection: and again a heavy cleanup in the function arguments

Location:
branches/collision_detection/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/collision_detection/src/lib/collision_detection/bv_tree.h

    r5716 r5718  
    4343  virtual void flushTree() = 0;
    4444
    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;
    4746
    4847  /** @param depth: depth, @param drawMode: how to draw the Model */
  • branches/collision_detection/src/lib/collision_detection/bv_tree_node.h

    r5717 r5718  
    1919template<class T> class tList;
    2020
     21
    2122//! A class that represents a bounding volume tree
    2223class BVTreeNode : public BaseObject {
     24
    2325
    2426 public:
  • branches/collision_detection/src/lib/collision_detection/cd_engine.cc

    r5717 r5718  
    9494        if( likely(entity2 != this->terrain))
    9595        {
    96           printf("checking object %s against %s\n", entity1->getName(), entity2->getName());
     96          //printf("checking object %s against %s\n", entity1->getName(), entity2->getName());
    9797          tree = entity1->getOBBTree();
    9898
  • branches/collision_detection/src/lib/collision_detection/obb_tree.cc

    r5717 r5718  
    104104
    105105
    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 
    113106/**
    114107 * 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)
    116108 * @param nodeA: PNode of object A
    117109 * @param nodeB: Pnode of object B
    118110 */
    119 void OBBTree::collideWith(BVTree* tree, WorldEntity* nodeA, WorldEntity* nodeB)
     111void OBBTree::collideWith(const WorldEntity& entity1, const WorldEntity& entity2) const
    120112{
    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);
    122115}
     116
    123117
    124118
  • branches/collision_detection/src/lib/collision_detection/obb_tree.h

    r5717 r5718  
    2929    virtual void flushTree();
    3030
    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;
    3332
    3433    virtual void drawBV(int depth, int drawMode) const;
  • branches/collision_detection/src/lib/collision_detection/obb_tree_node.cc

    r5717 r5718  
    600600
    601601
    602 void OBBTreeNode::collideWith(BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB) const
     602void OBBTreeNode::collideWith(const BVTreeNode& treeNode, const WorldEntity& nodeA, const WorldEntity& nodeB) const
    603603{
    604604  PRINTF(3)("collideWith\n");
    605605  /* 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);
    612613
    613614    /* check if left node overlaps */
    614615    if( likely( this->nodeLeft != NULL))
    615616    {
    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))
    618619      {
    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);
    621622      }
    622623    }
     
    624625    if( likely( this->nodeRight != NULL))
    625626    {
    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))
    628629      {
    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);
    631632      }
    632633    }
    633634
    634635    /* 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 */
    635637    if( unlikely(this->nodeRight == NULL && this->nodeLeft == NULL))
    636638    {
    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) const
    648 {
    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
     649bool 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;
    651653
    652654  /* first check all axis */
     
    658660  Vector rotAxisB[3];
    659661
    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));
    670672
    671673//   printf("\n");
     
    686688    l = rotAxisA[j];
    687689
    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));
    695697
    696698    PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
     
    710712    l = rotAxisB[j];
    711713
    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));
    719721
    720722    PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
     
    738740      l = rotAxisA[j].cross(rotAxisB[k]);
    739741
    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));
    747749
    748750      PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
     
    756758  }
    757759
    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
    761765  PRINTF(3)("Kollision!\n");
    762766  return true;
  • branches/collision_detection/src/lib/collision_detection/obb_tree_node.h

    r5717 r5718  
    3434    virtual void spawnBVTree(const modelInfo& modelInf, const int* triangleIndexes, unsigned int length);
    3535
    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;
    3737    virtual void drawBV(int depth, int drawMode, const Vector& color = Vector(1,0,0), bool top = true) const;
    3838    void debug() const;
     
    4848    void forkBox(OBB& box);
    4949
    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;
    5151
    5252
  • branches/collision_detection/src/world_entities/world_entity.cc

    r5717 r5718  
    147147 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
    148148 */
    149 void WorldEntity::collidesWith(WorldEntity* entity, const Vector& location)
     149void WorldEntity::collidesWith(const WorldEntity& entity, const Vector& location) const
    150150{
    151151  /**
  • branches/collision_detection/src/world_entities/world_entity.h

    r5717 r5718  
    4343  virtual void tick (float time);
    4444  virtual void draw () const;
    45   virtual void collidesWith (WorldEntity* entity, const Vector& location);
     45  virtual void collidesWith (const WorldEntity& entity, const Vector& location) const;
    4646
    4747  void drawBVTree(unsigned int depth, int drawMode) const;
Note: See TracChangeset for help on using the changeset viewer.