Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7732 in orxonox.OLD for trunk/src/lib/collision_detection


Ignore:
Timestamp:
May 19, 2006, 4:32:27 PM (19 years ago)
Author:
patrick
Message:

orxonox: removed a memory leak

Location:
trunk/src/lib/collision_detection
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/collision_detection/bv_tree_node.h

    r7711 r7732  
    3939
    4040
     41
    4142 private:
    4243  unsigned int        treeIndex;                  //!< Index number of the BV in the tree
     44
    4345
    4446};
  • trunk/src/lib/collision_detection/obb_tree_node.cc

    r7713 r7732  
    483483
    484484
    485 
     485/**
     486 * collides one tree with an other
     487 *  @param treeNode the other bv tree node
     488 *  @param nodeA  the worldentity belonging to this bv
     489 *  @param nodeB the worldentity belonging to treeNode
     490 */
    486491void OBBTreeNode::collideWith(BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB)
    487492{
    488   if( unlikely(treeNode == NULL))
     493  if( unlikely(treeNode == NULL || nodeA == NULL || nodeB == NULL))
     494  {
     495    assert(false);
    489496    return;
     497  }
    490498
    491499  PRINTF(4)("collideWith\n");
    492   /* if the obb overlap, make subtests: check which node is realy overlaping  */
    493   PRINTF(4)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex());
    494   //   if( unlikely(treeNode == NULL)) return;
    495 
    496 
    497   if( this->overlapTest(*this->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB))
    498   {
    499     PRINTF(4)("collision @ lvl %i, object %s vs. %s, (%p, %p)\n", this->depth, nodeA->getClassName(), nodeB->getClassName(), this->nodeLeft, this->nodeRight);
     500  PRINTF(5)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex());
     501
     502  // for now only collide with OBBTreeNodes
     503  this->collideWithOBB((OBBTreeNode*)treeNode, nodeA, nodeB);
     504}
     505
     506
     507
     508/**
     509 * collides one obb tree with an other
     510 *  @param treeNode the other bv tree node
     511 *  @param nodeA  the worldentity belonging to this bv
     512 *  @param nodeB the worldentity belonging to treeNode
     513 */
     514void OBBTreeNode::collideWithOBB(OBBTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB)
     515{
     516  if( this->overlapTest(this->bvElement, (OBB*)treeNode->bvElement, nodeA, nodeB))
     517  {
     518    PRINTF(5)("collision @ lvl %i, object %s vs. %s, (%p, %p)\n", this->depth, nodeA->getClassName(), nodeB->getClassName(), this->nodeLeft, this->nodeRight);
    500519
    501520    /* check if left node overlaps */
    502521    if( likely( this->nodeLeft != NULL))
    503522    {
    504       PRINTF(4)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode->getIndex());
    505       if( this->overlapTest(*this->nodeLeft->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB))
     523      PRINTF(5)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode->getIndex());
     524      if( this->overlapTest(this->nodeLeft->bvElement, treeNode->bvElement, nodeA, nodeB))
    506525      {
    507         this->nodeLeft->collideWith((((const OBBTreeNode*)treeNode)->nodeLeft), nodeA, nodeB);
    508         this->nodeLeft->collideWith((((const OBBTreeNode*)treeNode)->nodeRight), nodeA, nodeB);
     526        this->nodeLeft->collideWith(treeNode->nodeLeft, nodeA, nodeB);
     527        this->nodeLeft->collideWith(treeNode->nodeRight, nodeA, nodeB);
    509528      }
    510529    }
     
    512531    if( likely( this->nodeRight != NULL))
    513532    {
    514       PRINTF(4)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode->getIndex());
    515       if(this->overlapTest(*this->nodeRight->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB))
     533      PRINTF(5)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode->getIndex());
     534      if(this->overlapTest(this->nodeRight->bvElement, treeNode->bvElement, nodeA, nodeB))
    516535      {
    517         this->nodeRight->collideWith((((const OBBTreeNode*)treeNode)->nodeLeft), nodeA, nodeB);
    518         this->nodeRight->collideWith((((const OBBTreeNode*)treeNode)->nodeRight), nodeA, nodeB);
     536        this->nodeRight->collideWith(treeNode->nodeLeft, nodeA, nodeB);
     537        this->nodeRight->collideWith(treeNode->nodeRight, nodeA, nodeB);
    519538      }
    520539    }
     
    524543    if( unlikely(this->nodeRight == NULL || this->nodeLeft == NULL))
    525544    {
    526       nodeA->collidesWith(nodeB, (((const OBBTreeNode*)&treeNode)->bvElement->center));
    527 
     545      nodeA->collidesWith(nodeB, treeNode->bvElement->center);
    528546      nodeB->collidesWith(nodeA, this->bvElement->center);
    529547    }
     
    533551
    534552
    535 
    536 bool OBBTreeNode::overlapTest(OBB& boxA, OBB& boxB, WorldEntity* nodeA, WorldEntity* nodeB)
     553/**
     554 * this actualy checks if one obb box touches the other
     555 * @param boxA the box from nodeA
     556 * @param boxB the box from nodeB
     557 * @param nodeA the node itself
     558 * @param nodeB the node itself
     559 */
     560bool OBBTreeNode::overlapTest(OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB)
    537561{
    538562  //HACK remove this again
     
    549573  Vector      rotAxisB[3];
    550574
    551   rotAxisA[0] =  nodeA->getAbsDir().apply(boxA.axis[0]);
    552   rotAxisA[1] =  nodeA->getAbsDir().apply(boxA.axis[1]);
    553   rotAxisA[2] =  nodeA->getAbsDir().apply(boxA.axis[2]);
    554 
    555   rotAxisB[0] =  nodeB->getAbsDir().apply(boxB.axis[0]);
    556   rotAxisB[1] =  nodeB->getAbsDir().apply(boxB.axis[1]);
    557   rotAxisB[2] =  nodeB->getAbsDir().apply(boxB.axis[2]);
    558 
    559 
    560   t = nodeA->getAbsCoor() + nodeA->getAbsDir().apply(boxA.center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(boxB.center));
    561 
    562   //   printf("\n");
    563   //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[0].x, boxA->axis[0].y, boxA->axis[0].z, rotAxisA[0].x, rotAxisA[0].y, rotAxisA[0].z);
    564   //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[1].x, boxA->axis[1].y, boxA->axis[1].z, rotAxisA[1].x, rotAxisA[1].y, rotAxisA[1].z);
    565   //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[2].x, boxA->axis[2].y, boxA->axis[2].z, rotAxisA[2].x, rotAxisA[2].y, rotAxisA[2].z);
    566   //
    567   //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[0].x, boxB->axis[0].y, boxB->axis[0].z, rotAxisB[0].x, rotAxisB[0].y, rotAxisB[0].z);
    568   //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[1].x, boxB->axis[1].y, boxB->axis[1].z, rotAxisB[1].x, rotAxisB[1].y, rotAxisB[1].z);
    569   //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[2].x, boxB->axis[2].y, boxB->axis[2].z, rotAxisB[2].x, rotAxisB[2].y, rotAxisB[2].z);
    570 
     575  rotAxisA[0] =  nodeA->getAbsDir().apply(boxA->axis[0]);
     576  rotAxisA[1] =  nodeA->getAbsDir().apply(boxA->axis[1]);
     577  rotAxisA[2] =  nodeA->getAbsDir().apply(boxA->axis[2]);
     578
     579  rotAxisB[0] =  nodeB->getAbsDir().apply(boxB->axis[0]);
     580  rotAxisB[1] =  nodeB->getAbsDir().apply(boxB->axis[1]);
     581  rotAxisB[2] =  nodeB->getAbsDir().apply(boxB->axis[2]);
     582
     583  t = nodeA->getAbsCoor() + nodeA->getAbsDir().apply(boxA->center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(boxB->center));
    571584
    572585  /* All 3 axis of the object A */
     
    577590    l = rotAxisA[j];
    578591
    579     rA += fabs(boxA.halfLength[0] * rotAxisA[0].dot(l));
    580     rA += fabs(boxA.halfLength[1] * rotAxisA[1].dot(l));
    581     rA += fabs(boxA.halfLength[2] * rotAxisA[2].dot(l));
    582 
    583     rB += fabs(boxB.halfLength[0] * rotAxisB[0].dot(l));
    584     rB += fabs(boxB.halfLength[1] * rotAxisB[1].dot(l));
    585     rB += fabs(boxB.halfLength[2] * rotAxisB[2].dot(l));
     592    rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l));
     593    rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l));
     594    rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l));
     595
     596    rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l));
     597    rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l));
     598    rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l));
    586599
    587600    PRINTF(5)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
     
    601614    l = rotAxisB[j];
    602615
    603     rA += fabs(boxA.halfLength[0] * rotAxisA[0].dot(l));
    604     rA += fabs(boxA.halfLength[1] * rotAxisA[1].dot(l));
    605     rA += fabs(boxA.halfLength[2] * rotAxisA[2].dot(l));
    606 
    607     rB += fabs(boxB.halfLength[0] * rotAxisB[0].dot(l));
    608     rB += fabs(boxB.halfLength[1] * rotAxisB[1].dot(l));
    609     rB += fabs(boxB.halfLength[2] * rotAxisB[2].dot(l));
     616    rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l));
     617    rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l));
     618    rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l));
     619
     620    rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l));
     621    rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l));
     622    rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l));
    610623
    611624    PRINTF(5)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
     
    629642      l = rotAxisA[j].cross(rotAxisB[k]);
    630643
    631       rA += fabs(boxA.halfLength[0] * rotAxisA[0].dot(l));
    632       rA += fabs(boxA.halfLength[1] * rotAxisA[1].dot(l));
    633       rA += fabs(boxA.halfLength[2] * rotAxisA[2].dot(l));
    634 
    635       rB += fabs(boxB.halfLength[0] * rotAxisB[0].dot(l));
    636       rB += fabs(boxB.halfLength[1] * rotAxisB[1].dot(l));
    637       rB += fabs(boxB.halfLength[2] * rotAxisB[2].dot(l));
     644      rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l));
     645      rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l));
     646      rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l));
     647
     648      rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l));
     649      rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l));
     650      rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l));
    638651
    639652      PRINTF(5)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
     
    648661
    649662  /* FIXME: there is no collision mark set now */
    650      boxA.bCollided = true; /* use this ONLY(!!!!) for drawing operations */
    651      boxB.bCollided = true;
     663     boxA->bCollided = true; /* use this ONLY(!!!!) for drawing operations */
     664     boxB->bCollided = true;
    652665
    653666
     
    655668  return true;
    656669}
    657 
    658 
    659 
    660 
    661 
    662 
    663 
    664 
    665670
    666671
  • trunk/src/lib/collision_detection/obb_tree_node.h

    r7711 r7732  
    4848    void forkBox(OBB& box);
    4949
    50     bool overlapTest(OBB& boxA, OBB& boxB, WorldEntity* nodeA, WorldEntity* nodeB);
     50    void collideWithOBB(OBBTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB);
     51    bool overlapTest(OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB);
    5152
    5253
Note: See TracChangeset for help on using the changeset viewer.