Sphere-to-OBB
Checking if a Sphere and an Oriented Bounding Box (OBB) intersect is very similar to checking if a Sphere and an AABB intersect. First, we find the closest point on the OBB to the Sphere. Next, we must find the distance between the center of the Sphere and the closest point. Finally, we compare the distance against the radius of the sphere. If the distance is less than the radius, we have an intersection:
Getting ready
We are going to implement a function to test if a Sphere and an OBB are intersecting. We will also create a #define
macro to test the opposite. This new macro just switches the function name and argument order.
How to do it…
Follow the given steps to implement sphere to OBB intersection testing:
Declare
SphereOBB
inGeometry3D.h
:bool SphereOBB(const Sphere& sphere, const OBB& obb);
Declare
OBBSphere
inGeometry3D.h
:#define OBBSphere(obb, sphere) \ SphereOBB(sphere, obb)
Implement
SphereOBB
inGeometry3D.h
:bool SphereOBB(const Sphere& sphere, const OBB&...