Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool IntersectRayWithOBB(const Vector& vecRayStart, const Vector& vecRayDelta,
- matrix3x4_t& matOBBToWorld, const Vector vecOBBMins, const Vector vecOBBMaxs)
- {
- Vector vecBoxExtents = (vecOBBMins + vecOBBMaxs) * 0.5;
- Vector vecBoxCenter;
- // transform to world space
- Math::TransformVector(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
- Vector extent, uextent;
- Vector segmentCenter = vecRayStart + vecRayDelta - vecBoxCenter;
- extent.Init();
- // 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;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement