Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. bool IntersectRayWithOBB(const Vector& vecRayStart, const Vector& vecRayDelta,
  2.     matrix3x4_t& matOBBToWorld, const Vector vecOBBMins, const Vector vecOBBMaxs)
  3. {
  4.     Vector vecBoxExtents = (vecOBBMins + vecOBBMaxs) * 0.5;
  5.     Vector vecBoxCenter;
  6.  
  7.     // transform to world space
  8.     Math::TransformVector(vecBoxExtents, matOBBToWorld, vecBoxCenter);
  9.  
  10.     // calc extents from local center
  11.     vecBoxExtents = vecOBBMaxs - vecBoxExtents;
  12.  
  13.     // OPTIMIZE: This is optimized for world space.  If the transform is fast enough, it may make more
  14.     // sense to just xform and call UTIL_ClipToBox() instead.  MEASURE THIS.
  15.  
  16.     // save the extents of the ray along
  17.     Vector extent, uextent;
  18.     Vector segmentCenter = vecRayStart + vecRayDelta - vecBoxCenter;
  19.  
  20.     extent.Init();
  21.  
  22.     // check box axes for separation
  23.     for (int j = 0; j < 3; j++)
  24.     {
  25.         extent[j] = vecRayDelta.x * matOBBToWorld[0][j] + vecRayDelta.y * matOBBToWorld[1][j] + vecRayDelta.z * matOBBToWorld[2][j];
  26.         uextent[j] = fabsf(extent[j]);
  27.         float coord = segmentCenter.x * matOBBToWorld[0][j] + segmentCenter.y * matOBBToWorld[1][j] + segmentCenter.z * matOBBToWorld[2][j];
  28.         coord = fabsf(coord);
  29.  
  30.         if (coord >(vecBoxExtents[j] + uextent[j]))
  31.             return false;
  32.     }
  33.  
  34.     return true;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement