ExtremalQuery3PRJ.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/ExtremalQuery3.h>
  9. namespace WwiseGTE
  10. {
  11. template <typename Real>
  12. class ExtremalQuery3PRJ : public ExtremalQuery3<Real>
  13. {
  14. public:
  15. // Construction.
  16. ExtremalQuery3PRJ(Polyhedron3<Real> const& polytope)
  17. :
  18. ExtremalQuery3<Real>(polytope)
  19. {
  20. mCentroid = this->mPolytope.ComputeVertexAverage();
  21. }
  22. // Disallow copying and assignment.
  23. ExtremalQuery3PRJ(ExtremalQuery3PRJ const&) = delete;
  24. ExtremalQuery3PRJ& operator=(ExtremalQuery3PRJ const&) = delete;
  25. // Compute the extreme vertices in the specified direction and return
  26. // the indices of the vertices in the polyhedron vertex array.
  27. virtual void GetExtremeVertices(Vector3<Real> const& direction,
  28. int& positiveDirection, int& negativeDirection) override
  29. {
  30. Real minValue = std::numeric_limits<Real>::max(), maxValue = -minValue;
  31. negativeDirection = -1;
  32. positiveDirection = -1;
  33. auto vertexPool = this->mPolytope.GetVertexPool();
  34. for (auto i : this->mPolytope.GetUniqueIndices())
  35. {
  36. Vector3<Real> diff = vertexPool.get()->at(i) - mCentroid;
  37. Real dot = Dot(direction, diff);
  38. if (dot < minValue)
  39. {
  40. negativeDirection = i;
  41. minValue = dot;
  42. }
  43. if (dot > maxValue)
  44. {
  45. positiveDirection = i;
  46. maxValue = dot;
  47. }
  48. }
  49. }
  50. private:
  51. Vector3<Real> mCentroid;
  52. };
  53. }