//SDK RIP fixed to work with d3dvector and removed useless stuff
bool IntersectRayWithOBB(const D3DXVECTOR3 &vecRayStart, const D3DXVECTOR3 &vecRayDelta,
const matrix3x4_t &matOBBToWorld, const D3DXVECTOR3 &vecOBBMins, const D3DXVECTOR3 &vecOBBMaxs)
{
// OPTIMIZE: Store this in the box instead of computing it here
// compute center in local space
D3DXVECTOR3 vecBoxExtents = (vecOBBMins + vecOBBMaxs) * 0.5;
D3DXVECTOR3 vecBoxCenter;
// transform to world space
VectorTransform(vecBoxExtents, matOBBToWorld, vecBoxCenter);
// calc extents from local center
vecBoxExtents = vecOBBMaxs - vecBoxExtents;
// OPTIMIZE: This is optimized for world space. If the transform is fast enough, it may make more
// sense to just xform and call UTIL_ClipToBox() instead. MEASURE THIS.
// save the extents of the ray along
D3DXVECTOR3 extent, uextent;
D3DXVECTOR3 segmentCenter = vecRayStart + vecRayDelta - vecBoxCenter;
extent.x = extent.y = extent.z = 0.0f;
// check box axes for separation
for (int j = 0; j < 3; j++)
{
extent[j] = vecRayDelta.x * matOBBToWorld[0][j] + vecRayDelta.y * matOBBToWorld[1][j] + vecRayDelta.z * matOBBToWorld[2][j];
uextent[j] = fabsf(extent[j]);
float coord = segmentCenter.x * matOBBToWorld[0][j] + segmentCenter.y * matOBBToWorld[1][j] + segmentCenter.z * matOBBToWorld[2][j];
coord = fabsf(coord);
if (coord >(vecBoxExtents[j] + uextent[j]))
return false;
}
// now check cross axes for separation
float tmp, cextent;
D3DXVECTOR3 cross;
D3DXVec3Cross(&cross, &vecRayDelta, &segmentCenter);// = vecRayDelta.Cross(segmentCenter);
cextent = cross.x * matOBBToWorld[0][0] + cross.y * matOBBToWorld[1][0] + cross.z * matOBBToWorld[2][0];
cextent = fabsf(cextent);
tmp = vecBoxExtents[1] * uextent[2] + vecBoxExtents[2] * uextent[1];
if (cextent > tmp)
return false;
cextent = cross.x * matOBBToWorld[0][1] + cross.y * matOBBToWorld[1][1] + cross.z * matOBBToWorld[2][1];
cextent = fabsf(cextent);
tmp = vecBoxExtents[0] * uextent[2] + vecBoxExtents[2] * uextent[0];
if (cextent > tmp)
return false;
cextent = cross.x * matOBBToWorld[0][2] + cross.y * matOBBToWorld[1][2] + cross.z * matOBBToWorld[2][2];
cextent = fabsf(cextent);
tmp = vecBoxExtents[0] * uextent[1] + vecBoxExtents[1] * uextent[0];
if (cextent > tmp)
return false;
return true;
}