Like many OBB-to-any checks, this test can be greatly simplified by just rotating the sphere into the OBB's coordinate system, effectively making it a AABB to sphere test:
/// <summary>Test whether an oriented box and a sphere intersect each other</summary>
/// <param name="boxTransform">Orientation and position of the box</param>
/// <param name="boxExtents">Extents of the box to be tested</param>
/// <param name="sphereCenter">Center of the sphere relative to the box' center</param>
/// <param name="sphereRadius">Radius of the sphere</param>
/// <returns>True if the sphere overlaps with the oriented box</returns>
public static bool CheckContact(
Matrix boxTransform, Vector3 boxExtents,
Vector3 sphereCenter, float sphereRadius
) {
// Translate the sphere into box coordinates
Vector3 local = new Vector3(
Vector3.Dot(sphereCenter, boxTransform.Right),
Vector3.Dot(sphereCenter, boxTransform.Up),
Vector3.Dot(sphereCenter, boxTransform.Forward)
);
// Now it's a simple aabb check
return AabbSphereCollider.CheckContact(
-boxExtents, boxExtents, sphereCenter, sphereRadius
);
}
/// <param name="boxTransform">Orientation and position of the box</param>
/// <param name="boxExtents">Extents of the box to be tested</param>
/// <param name="sphereCenter">Center of the sphere relative to the box' center</param>
/// <param name="sphereRadius">Radius of the sphere</param>
/// <returns>True if the sphere overlaps with the oriented box</returns>
public static bool CheckContact(
Matrix boxTransform, Vector3 boxExtents,
Vector3 sphereCenter, float sphereRadius
) {
// Translate the sphere into box coordinates
Vector3 local = new Vector3(
Vector3.Dot(sphereCenter, boxTransform.Right),
Vector3.Dot(sphereCenter, boxTransform.Up),
Vector3.Dot(sphereCenter, boxTransform.Forward)
);
// Now it's a simple aabb check
return AabbSphereCollider.CheckContact(
-boxExtents, boxExtents, sphereCenter, sphereRadius
);
}
The AabbSphereCollider class used to perform the final collision test can be found in the article Static Intersection Test Between AABB and Sphere.