Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 22, 2005, 7:01:42 PM (18 years ago)
Author:
patrick
Message:

collision_bibischen: more interface changes, more covariance building

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/collision_detection/src/lib/collision_detection/obb_tree_node.cc

    r5712 r5713  
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION
    1717
    1818#include "obb_tree_node.h"
     
    4242 *  standard constructor
    4343 */
    44 OBBTreeNode::OBBTreeNode (const OBBTree* tree)
     44OBBTreeNode::OBBTreeNode (const OBBTree& tree, unsigned int depth)
    4545  : BVTreeNode()
    4646{
    4747  this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode");
    48   this->obbTree = tree;
     48
     49  this->obbTree = &tree;
     50  this->depth = depth;
     51
    4952  this->nodeLeft = NULL;
    5053  this->nodeRight = NULL;
    5154  this->bvElement = NULL;
     55
    5256  this->tmpVert1 = NULL;
    5357  this->tmpVert2 = NULL;
     
    7579    OBBTreeNode_sphereObj = gluNewQuadric();
    7680}
    77 
    7881
    7982/**
     
    117120
    118121  PRINTF(3)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length);
     122  printf("OBBTreeNode::spawnBVTree()\n");
    119123  this->depth = depth;
    120124
     
    132136  if( likely( this->depth > 0))
    133137  {
    134     this->forkBox(*this->bvElement);
     138    //this->forkBox(*this->bvElement);
    135139
    136140
     
    170174void OBBTreeNode::spawnBVTree(const int depth, const sVec3D *verticesList, unsigned int length)
    171175{
    172 //   PRINT(3)("\n");
     176//   PRINTF(3)("\n");
    173177//   PRINTF(3)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length);
    174178//   this->depth = depth;
     
    239243  for( int i = 0; i < length ; ++i)
    240244  {
    241     sVec3D* a = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[i].indexToVertices[0]]);
    242     p = *a;
    243     p.debug();
    244     //q = modelInf.pVertices[modelInf.pTriangles[i][1]];     //verticesList[i + 1];
    245     //r = modelInf.pVertices[modelInf.pTriangles[i][2]];     //verticesList[i + 2];
    246 
     245    tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[0]]);
     246    p = *tmpVec;
     247    tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[1]]);
     248    q = *tmpVec;
     249    tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[2]]);
     250    r = *tmpVec;
     251
     252    /* finding the facelet surface via cross-product */
    247253    t1 = p - q; t2 = p - r;
    248 
    249     /* finding the facelet surface via cross-product */
    250254    facelet[i] = 0.5f * fabs( t1.cross(t2).len() );
    251255    /* update the entire convex hull surface */
     
    270274      for( int i = 0; i + 3 < length; i+=3)
    271275      {
    272         p = verticesList[i];
    273         q = verticesList[i + 1];
    274         r = verticesList[i + 2];
     276        tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[0]]);
     277        p = *tmpVec;
     278        tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[1]]);
     279        q = *tmpVec;
     280        tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[2]]);
     281        r = *tmpVec;
     282
    275283
    276284        covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j] * p[k] +
     
    286294    PRINTF(3)(" Vertex[%i]: %f, %f, %f\n", i, box.vertices[i][0], box.vertices[i][1], box.vertices[i][2]);
    287295  PRINTF(3)("\nOBB Covariance Matrix:\n");
    288   for(int j = 0; j < 3; ++j) { PRINT(3)(" |"); for(int k = 0; k < 3; ++k) { PRINT(3)(" \b%f ", covariance[j][k]); } PRINT(3)(" |\n"); }
     296  for(int j = 0; j < 3; ++j) { PRINTF(3)(" |"); for(int k = 0; k < 3; ++k) { PRINTF(3)(" \b%f ", covariance[j][k]); } PRINTF(3)(" |\n"); }
    289297  PRINTF(3)("OBB Center: %f, %f, %f\n", center.x, center.y, center.z);
    290298
     
    357365void OBBTreeNode::calculateBoxAxis(OBB& box, const modelInfo& modInfo, const int* triangleIndexes, unsigned int length)
    358366{
    359   this->calculateBoxAxis(box, (const sVec3D*)modInfo.pVertices, modInfo.numVertices);
     367  //this->calculateBoxAxis(box, (const sVec3D*)modInfo.pVertices, modInfo.numVertices);
    360368}
    361369
     
    597605  PRINTF(3)("collideWith\n");
    598606  /* if the obb overlap, make subtests: check which node is realy overlaping  */
    599   PRINT(3)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex());
     607  PRINTF(3)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex());
    600608  if( unlikely(treeNode == NULL)) return;
    601609
     
    607615    if( likely( this->nodeLeft != NULL))
    608616    {
    609       PRINT(3)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode->getIndex());
     617      PRINTF(3)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode->getIndex());
    610618      if( this->overlapTest(this->nodeLeft->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))
    611619      {
     
    617625    if( likely( this->nodeRight != NULL))
    618626    {
    619       PRINT(3)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode->getIndex());
     627      PRINTF(3)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode->getIndex());
    620628      if(this->overlapTest(this->nodeRight->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))
    621629      {
     
    691699    if( (rA + rB) < fabs(t.dot(l)))
    692700    {
    693       PRINT(3)("no Collision\n");
     701      PRINTF(3)("no Collision\n");
    694702      return false;
    695703    }
     
    715723    if( (rA + rB) < fabs(t.dot(l)))
    716724    {
    717       PRINT(3)("no Collision\n");
     725      PRINTF(3)("no Collision\n");
    718726      return false;
    719727    }
     
    743751      if( (rA + rB) < fabs(t.dot(l)))
    744752      {
    745         PRINT(3)("keine Kollision\n");
     753        PRINTF(3)("keine Kollision\n");
    746754        return false;
    747755      }
     
    752760  boxA->bCollided = true; /* use this ONLY(!!!!) for drawing operations */
    753761  boxB->bCollided = true;
    754   PRINT(3)("Kollision!\n");
     762  PRINTF(3)("Kollision!\n");
    755763  return true;
    756764}
Note: See TracChangeset for help on using the changeset viewer.