// David Eberly, Geometric Tools, Redmond WA 98052 // Copyright (c) 1998-2020 // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt // https://www.geometrictools.com/License/Boost/LICENSE_1_0.txt // Version: 4.0.2019.08.13 #pragma once #include namespace WwiseGTE { template class ExtremalQuery3 { public: // Abstract base class. virtual ~ExtremalQuery3() = default; // Disallow copying and assignment. ExtremalQuery3(ExtremalQuery3 const&) = delete; ExtremalQuery3& operator=(ExtremalQuery3 const&) = delete; // Member access. inline Polyhedron3 const& GetPolytope() const { return mPolytope; } inline std::vector> const& GetFaceNormals() const { return mFaceNormals; } // Compute the extreme vertices in the specified direction and return // the indices of the vertices in the polyhedron vertex array. virtual void GetExtremeVertices(Vector3 const& direction, int& positiveDirection, int& negativeDirection) = 0; protected: // The caller must ensure that the input polyhedron is convex. ExtremalQuery3(Polyhedron3 const& polytope) : mPolytope(polytope) { // Create the face normals. auto vertexPool = mPolytope.GetVertices(); auto const& indices = mPolytope.GetIndices(); int const numTriangles = static_cast(indices.size()) / 3; mFaceNormals.resize(numTriangles); for (int t = 0; t < numTriangles; ++t) { Vector3 v0 = vertexPool[indices[3 * t + 0]]; Vector3 v1 = vertexPool[indices[3 * t + 1]]; Vector3 v2 = vertexPool[indices[3 * t + 2]]; Vector3 edge1 = v1 - v0; Vector3 edge2 = v2 - v0; mFaceNormals[t] = UnitCross(edge1, edge2); } } Polyhedron3 const& mPolytope; std::vector> mFaceNormals; }; }