Advertisement
Guest User

kdop bbox test

a guest
Dec 15th, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. template < std::size_t uMax >
  2. class capped_kdop
  3. ...
  4.  
  5. bool isBBoxIn(const bounding_box3d& bbox, const matrix& world) const
  6.     {
  7.        
  8.         float3 c    = bbox.getCenter();
  9.         float sizex = bbox.maxEdge.x - bbox.minEdge.x;
  10.         float sizey = bbox.maxEdge.y - bbox.minEdge.y;
  11.         float sizez = bbox.maxEdge.z - bbox.minEdge.z;
  12.  
  13.         float3 corners[8] =
  14.         {
  15.             float3((c.x - sizex * 0.5f), (c.y - sizey * 0.5f), (c.z - sizez * 0.5f)),
  16.             float3((c.x + sizex * 0.5f), (c.y - sizey * 0.5f), (c.z - sizez * 0.5f)),
  17.             float3((c.x - sizex * 0.5f), (c.y + sizey * 0.5f), (c.z - sizez * 0.5f)),
  18.             float3((c.x + sizex * 0.5f), (c.y + sizey * 0.5f), (c.z - sizez * 0.5f)),
  19.             float3((c.x - sizex * 0.5f), (c.y - sizey * 0.5f), (c.z + sizez * 0.5f)),
  20.             float3((c.x + sizex * 0.5f), (c.y - sizey * 0.5f), (c.z + sizez * 0.5f)),
  21.             float3((c.x - sizex * 0.5f), (c.y + sizey * 0.5f), (c.z + sizez * 0.5f)),
  22.             float3((c.x + sizex * 0.5f), (c.y + sizey * 0.5f), (c.z + sizez * 0.5f))
  23.         };
  24.  
  25.         for(unsigned int i = 0; i < 8; ++i)
  26.         {
  27.             world.transformVector(corners[i]);
  28.         }
  29.  
  30.         for(unsigned short i = 0; i < total; ++i)
  31.         {
  32.             if(planes[i].getRelationWith(corners[0]) > 0.0f)
  33.             {
  34.                 continue;
  35.             }
  36.  
  37.             if(planes[i].getRelationWith(corners[1]) > 0.0f)
  38.             {
  39.                 continue;
  40.             }
  41.  
  42.             if(planes[i].getRelationWith(corners[2]) > 0.0f)
  43.             {
  44.                 continue;
  45.             }
  46.  
  47.             if(planes[i].getRelationWith(corners[3]) > 0.0f)
  48.             {
  49.                 continue;
  50.             }
  51.  
  52.             if(planes[i].getRelationWith(corners[4]) > 0.0f)
  53.             {
  54.                 continue;
  55.             }
  56.  
  57.             if(planes[i].getRelationWith(corners[5]) > 0.0f)
  58.             {
  59.                 continue;
  60.             }
  61.  
  62.             if(planes[i].getRelationWith(corners[6]) > 0.0f)
  63.             {
  64.                 continue;
  65.             }
  66.  
  67.             if(planes[i].getRelationWith(corners[7]) > 0.0f)
  68.             {
  69.                 continue;
  70.             }
  71.             return false;
  72.         }
  73.         return true;
  74.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement