12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #pragma once
- #include <Mathematics/DistPointTriangle.h>
- #include <Mathematics/Tetrahedron3.h>
- namespace WwiseGTE
- {
- template <typename Real>
- class DCPQuery<Real, Vector3<Real>, Tetrahedron3<Real>>
- {
- public:
- struct Result
- {
- Real distance, sqrDistance;
- Vector3<Real> tetrahedronClosestPoint;
- };
- Result operator()(Vector3<Real> const& point, Tetrahedron3<Real> const& tetrahedron)
- {
- Result result;
-
-
-
-
- Plane3<Real> planes[4];
- tetrahedron.GetPlanes(planes);
-
-
-
- result.sqrDistance = std::numeric_limits<Real>::max();
- result.tetrahedronClosestPoint = Vector3<Real>::Zero();
- for (int i = 0; i < 4; ++i)
- {
- if (Dot(planes[i].normal, point) >= planes[i].constant)
- {
- int indices[3] = { 0, 0, 0 };
- tetrahedron.GetFaceIndices(i, indices);
- Triangle3<Real> triangle(
- tetrahedron.v[indices[0]],
- tetrahedron.v[indices[1]],
- tetrahedron.v[indices[2]]);
- DCPQuery<Real, Vector3<Real>, Triangle3<Real>> query;
- auto ptResult = query(point, triangle);
- if (ptResult.sqrDistance < result.sqrDistance)
- {
- result.sqrDistance = ptResult.sqrDistance;
- result.tetrahedronClosestPoint = ptResult.closest;
- }
- }
- }
- if (result.sqrDistance == std::numeric_limits<Real>::max())
- {
-
-
- result.sqrDistance = (Real)0;
- result.tetrahedronClosestPoint = point;
- }
- result.distance = std::sqrt(result.sqrDistance);
- return result;
- }
- };
- }
|