// David Eberly, Geometric Tools, Redmond WA 98052 // Copyright (c) 1998-2020 // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt // https://www.geometrictools.com/License/Boost/LICENSE_1_0.txt // Version: 4.0.2019.08.13 #pragma once #include #include #include #include #include namespace WwiseGTE { template class TIQuery, Sphere3> { public: struct Result { bool intersect; }; Result operator()(Plane3 const& plane, Sphere3 const& sphere) { Result result; DCPQuery, Plane3> ppQuery; auto ppResult = ppQuery(sphere.center, plane); result.intersect = (ppResult.distance <= sphere.radius); return result; } }; template class FIQuery, Sphere3> { public: struct Result { bool intersect; // If 'intersect' is true, the intersection is either a point or a // circle. When 'isCircle' is true, 'circle' is valid. When // 'isCircle' is false, 'point' is valid. bool isCircle; Circle3 circle; Vector3 point; }; Result operator()(Plane3 const& plane, Sphere3 const& sphere) { Result result; DCPQuery, Plane3> ppQuery; auto ppResult = ppQuery(sphere.center, plane); if (ppResult.distance < sphere.radius) { result.intersect = true; result.isCircle = true; result.circle.center = sphere.center - ppResult.signedDistance * plane.normal; result.circle.normal = plane.normal; // The sum and diff are both positive numbers. Real sum = sphere.radius + ppResult.distance; Real dif = sphere.radius - ppResult.distance; // arg = sqr(sphere.radius) - sqr(ppResult.distance) Real arg = sum * dif; result.circle.radius = std::sqrt(arg); return result; } else if (ppResult.distance == sphere.radius) { result.intersect = true; result.isCircle = false; result.point = sphere.center - ppResult.signedDistance * plane.normal; return result; } else { result.intersect = false; return result; } } }; }