1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #pragma once
- #include <Mathematics/FIQuery.h>
- #include <Mathematics/TIQuery.h>
- #include <Mathematics/DistPoint3Plane3.h>
- #include <Mathematics/Hypersphere.h>
- #include <Mathematics/Circle3.h>
- namespace WwiseGTE
- {
- template <typename Real>
- class TIQuery<Real, Plane3<Real>, Sphere3<Real>>
- {
- public:
- struct Result
- {
- bool intersect;
- };
- Result operator()(Plane3<Real> const& plane, Sphere3<Real> const& sphere)
- {
- Result result;
- DCPQuery<Real, Vector3<Real>, Plane3<Real>> ppQuery;
- auto ppResult = ppQuery(sphere.center, plane);
- result.intersect = (ppResult.distance <= sphere.radius);
- return result;
- }
- };
- template <typename Real>
- class FIQuery<Real, Plane3<Real>, Sphere3<Real>>
- {
- public:
- struct Result
- {
- bool intersect;
-
-
-
- bool isCircle;
- Circle3<Real> circle;
- Vector3<Real> point;
- };
- Result operator()(Plane3<Real> const& plane, Sphere3<Real> const& sphere)
- {
- Result result;
- DCPQuery<Real, Vector3<Real>, Plane3<Real>> 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;
-
- Real sum = sphere.radius + ppResult.distance;
- Real dif = sphere.radius - 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;
- }
- }
- };
- }
|