Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5868 in orxonox.OLD


Ignore:
Timestamp:
Dec 2, 2005, 11:59:30 AM (19 years ago)
Author:
patrick
Message:

collision_detection: box dimension calculation adjusted

File:
1 edited

Legend:

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

    r5867 r5868  
    354354 * @param length: the length of the indexes array
    355355 */
    356 void OBBTreeNode::calculateBoxAxis(OBB& box, const modelInfo& modInfo, const int* triangleIndexes, unsigned int length)
     356void OBBTreeNode::calculateBoxAxis(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length)
    357357{
    358358
     
    370370  float               maxLength[3];
    371371  float               minLength[3];
    372 
    373 
    374   /* get a bad bounding box */
     372  const sVec3D*       tmpVec;
     373
     374  /*
     375  this step is split up in two: first there will be made a bounding box which is
     376  very badly centered. In the secon step there will be calculated a new center
     377  and a better bounding box.
     378  */
     379
     380  /* get a bad bounding box axis */
    375381  halfLength[0] = -1.0f;
    376   for(int j = 0; j < length; ++j)
    377   {
    378     tmpLength = fabs(p0.distancePoint(vertices[j]));
    379     if( tmpLength > halfLength[0])
    380       halfLength[0] = tmpLength;
     382  for( int j = 0; j < length; ++j)
     383  {
     384    for( int i = 0; i < 3; ++i)
     385    {
     386      tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[j]].indexToVertices[i]]);
     387      tmpLength = fabs(p0.distancePoint(*tmpVec));
     388      if( tmpLength > halfLength[0])
     389        halfLength[0] = tmpLength;
     390    }
    381391  }
    382392
    383393  halfLength[1] = -1.0f;
    384   for(int j = 0; j < length; ++j)
    385   {
    386     tmpLength = fabs(p1.distancePoint(vertices[j]));
    387     if( tmpLength > halfLength[1])
    388       halfLength[1] = tmpLength;
     394  for( int j = 0; j < length; ++j)
     395  {
     396    for( int i = 0; i < 3; ++i)
     397    {
     398      tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[j]].indexToVertices[i]]);
     399      tmpLength = fabs(p0.distancePoint(*tmpVec));
     400      if( tmpLength > halfLength[1])
     401        halfLength[1] = tmpLength;
     402    }
    389403  }
    390404
    391405  halfLength[2] = -1.0f;
    392   for(int j = 0; j < length; ++j)
    393   {
    394     tmpLength = fabs(p2.distancePoint(vertices[j]));
    395     if( tmpLength > halfLength[2])
    396       halfLength[2] = tmpLength;
     406  for( int j = 0; j < length; ++j)
     407  {
     408    for( int i = 0; i < 3; ++i)
     409    {
     410      tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[j]].indexToVertices[i]]);
     411      tmpLength = fabs(p0.distancePoint(*tmpVec));
     412      if( tmpLength > halfLength[2])
     413        halfLength[2] = tmpLength;
     414    }
    397415  }
    398416
     
    400418
    401419  /* get the maximal dimensions of the body in all directions */
    402   maxLength[0] = p0.distancePoint(vertices[0]);
    403   minLength[0] = p0.distancePoint(vertices[0]);
    404   for(int j = 0; j < length; ++j)
    405   {
    406     tmpLength = p0.distancePoint(vertices[j]);
    407     if( tmpLength > maxLength[0])
    408       maxLength[0] = tmpLength;
    409     else if( tmpLength < minLength[0])
    410       minLength[0] = tmpLength;
    411   }
    412 
    413   maxLength[1] = p1.distancePoint(vertices[0]);
    414   minLength[1] = p1.distancePoint(vertices[0]);
    415   for(int j = 0; j < length; ++j)
    416   {
    417     tmpLength = p1.distancePoint(vertices[j]);
    418     if( tmpLength > maxLength[1])
    419       maxLength[1] = tmpLength;
    420     else if( tmpLength < minLength[1])
    421       minLength[1] = tmpLength;
    422   }
    423 
    424   maxLength[2] = p2.distancePoint(vertices[0]);
    425   minLength[2] = p2.distancePoint(vertices[0]);
    426   for(int j = 0; j < length; ++j)
    427   {
    428     tmpLength = p2.distancePoint(vertices[j]);
    429     if( tmpLength > maxLength[2])
    430       maxLength[2] = tmpLength;
    431     else if( tmpLength < minLength[2])
    432       minLength[2] = tmpLength;
     420  /* for the initialisation the value just has to be inside of the polygon soup -> first vertices (rand) */
     421  tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[0]].indexToVertices[0]]);
     422  maxLength[0] = p0.distancePoint(*tmpVec);
     423  minLength[0] = p0.distancePoint(*tmpVec);
     424  for( int j = 0; j < length; ++j)
     425  {
     426    for( int i = 0; i < 3; ++i)
     427    {
     428      tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[j]].indexToVertices[i]]);
     429      tmpLength = p0.distancePoint(*tmpVec);
     430      if( tmpLength > maxLength[0])
     431        maxLength[0] = tmpLength;
     432      else if( tmpLength < minLength[0])
     433        minLength[0] = tmpLength;
     434    }
     435  }
     436
     437  /* for the initialisation the value just has to be inside of the polygon soup -> first vertices (rand) */
     438  tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[0]].indexToVertices[0]]);
     439  maxLength[1] = p1.distancePoint(*tmpVec);
     440  minLength[1] = p1.distancePoint(*tmpVec);
     441  for( int j = 0; j < length; ++j)
     442  {
     443    for( int i = 0; i < 3; ++i)
     444    {
     445      tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[j]].indexToVertices[i]]);
     446      tmpLength = p0.distancePoint(*tmpVec);
     447      if( tmpLength > maxLength[1])
     448        maxLength[1] = tmpLength;
     449      else if( tmpLength < minLength[1])
     450        minLength[1] = tmpLength;
     451    }
     452  }
     453
     454  /* for the initialisation the value just has to be inside of the polygon soup -> first vertices (rand) */
     455  tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[0]].indexToVertices[0]]);
     456  maxLength[2] = p2.distancePoint(*tmpVec);
     457  minLength[2] = p2.distancePoint(*tmpVec);
     458  for( int j = 0; j < length; ++j)
     459  {
     460    for( int i = 0; i < 3; ++i)
     461    {
     462      tmpVec = (sVec3D*)(&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[j]].indexToVertices[i]]);
     463      tmpLength = p0.distancePoint(*tmpVec);
     464      if( tmpLength > maxLength[2])
     465        maxLength[2] = tmpLength;
     466      else if( tmpLength < minLength[2])
     467        minLength[2] = tmpLength;
     468    }
    433469  }
    434470
Note: See TracChangeset for help on using the changeset viewer.