ExtremalQuery3.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // David Eberly, Geometric Tools, Redmond WA 98052
  2. // Copyright (c) 1998-2020
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // https://www.boost.org/LICENSE_1_0.txt
  5. // https://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
  6. // Version: 4.0.2019.08.13
  7. #pragma once
  8. #include <Mathematics/Polyhedron3.h>
  9. namespace WwiseGTE
  10. {
  11. template <typename Real>
  12. class ExtremalQuery3
  13. {
  14. public:
  15. // Abstract base class.
  16. virtual ~ExtremalQuery3() = default;
  17. // Disallow copying and assignment.
  18. ExtremalQuery3(ExtremalQuery3 const&) = delete;
  19. ExtremalQuery3& operator=(ExtremalQuery3 const&) = delete;
  20. // Member access.
  21. inline Polyhedron3<Real> const& GetPolytope() const
  22. {
  23. return mPolytope;
  24. }
  25. inline std::vector<Vector3<Real>> const& GetFaceNormals() const
  26. {
  27. return mFaceNormals;
  28. }
  29. // Compute the extreme vertices in the specified direction and return
  30. // the indices of the vertices in the polyhedron vertex array.
  31. virtual void GetExtremeVertices(Vector3<Real> const& direction,
  32. int& positiveDirection, int& negativeDirection) = 0;
  33. protected:
  34. // The caller must ensure that the input polyhedron is convex.
  35. ExtremalQuery3(Polyhedron3<Real> const& polytope)
  36. :
  37. mPolytope(polytope)
  38. {
  39. // Create the face normals.
  40. auto vertexPool = mPolytope.GetVertices();
  41. auto const& indices = mPolytope.GetIndices();
  42. int const numTriangles = static_cast<int>(indices.size()) / 3;
  43. mFaceNormals.resize(numTriangles);
  44. for (int t = 0; t < numTriangles; ++t)
  45. {
  46. Vector3<Real> v0 = vertexPool[indices[3 * t + 0]];
  47. Vector3<Real> v1 = vertexPool[indices[3 * t + 1]];
  48. Vector3<Real> v2 = vertexPool[indices[3 * t + 2]];
  49. Vector3<Real> edge1 = v1 - v0;
  50. Vector3<Real> edge2 = v2 - v0;
  51. mFaceNormals[t] = UnitCross(edge1, edge2);
  52. }
  53. }
  54. Polyhedron3<Real> const& mPolytope;
  55. std::vector<Vector3<Real>> mFaceNormals;
  56. };
  57. }