1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #pragma once
- #include <Mathematics/DCPQuery.h>
- #include <Mathematics/AlignedBox.h>
- namespace WwiseGTE
- {
- template <int N, typename Real>
- class DCPQuery<Real, Vector<N, Real>, AlignedBox<N, Real>>
- {
- public:
- struct Result
- {
- Real distance, sqrDistance;
- Vector<N, Real> boxClosest;
- };
- Result operator()(Vector<N, Real> const& point, AlignedBox<N, Real> const& box)
- {
-
-
- Vector<N, Real> boxCenter, boxExtent;
- box.GetCenteredForm(boxCenter, boxExtent);
- Vector<N, Real> closest = point - boxCenter;
- Result result;
- DoQuery(closest, boxExtent, result);
-
- result.boxClosest = boxCenter + closest;
- return result;
- }
- protected:
-
-
-
- void DoQuery(Vector<N, Real>& point, Vector<N, Real> const& boxExtent,
- Result& result)
- {
- result.sqrDistance = (Real)0;
- for (int i = 0; i < N; ++i)
- {
- if (point[i] < -boxExtent[i])
- {
- Real delta = point[i] + boxExtent[i];
- result.sqrDistance += delta * delta;
- point[i] = -boxExtent[i];
- }
- else if (point[i] > boxExtent[i])
- {
- Real delta = point[i] - boxExtent[i];
- result.sqrDistance += delta * delta;
- point[i] = boxExtent[i];
- }
- }
- result.distance = std::sqrt(result.sqrDistance);
- }
- };
-
- template <int N, typename Real>
- using DCPPointAlignedBox = DCPQuery<Real, Vector<N, Real>, AlignedBox<N, Real>>;
- template <typename Real>
- using DCPPoint2AlignedBox2 = DCPPointAlignedBox<2, Real>;
- template <typename Real>
- using DCPPoint3AlignedBox3 = DCPPointAlignedBox<3, Real>;
- }
|