1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #pragma once
- #include <Mathematics/AlignedBox.h>
- #include <Mathematics/Vector4.h>
- #include <cstdint>
- #include <vector>
- namespace WwiseGTE
- {
- template <typename Real>
- class ConvexPolyhedron3
- {
- public:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ConvexPolyhedron3() = default;
- ConvexPolyhedron3(std::vector<Vector3<Real>>&& inVertices, std::vector<int>&& inIndices,
- bool wantPlanes, bool wantAlignedBox)
- {
- if (inVertices.size() >= 4 && inIndices.size() >= 12)
- {
- vertices = std::move(inVertices);
- indices = std::move(inIndices);
- if (wantPlanes)
- {
- GeneratePlanes();
- }
- if (wantAlignedBox)
- {
- GenerateAlignedBox();
- }
- }
- }
-
-
- void GeneratePlanes()
- {
- if (vertices.size() > 0 && indices.size() > 0)
- {
- uint32_t const numTriangles = static_cast<uint32_t>(indices.size()) / 3;
- planes.resize(numTriangles);
- for (uint32_t t = 0, i = 0; t < numTriangles; ++t)
- {
- Vector3<Real> V0 = vertices[indices[i++]];
- Vector3<Real> V1 = vertices[indices[i++]];
- Vector3<Real> V2 = vertices[indices[i++]];
- Vector3<Real> E1 = V1 - V0;
- Vector3<Real> E2 = V2 - V0;
- Vector3<Real> N = Cross(E1, E2);
- planes[t] = HLift(N, -Dot(N, V0));
- }
- }
- }
- void GenerateAlignedBox()
- {
- if (vertices.size() > 0 && indices.size() > 0)
- {
- ComputeExtremes(static_cast<int>(vertices.size()), vertices.data(),
- alignedBox.min, alignedBox.max);
- }
- }
- std::vector<Vector3<Real>> vertices;
- std::vector<int> indices;
- std::vector<Vector4<Real>> planes;
- AlignedBox3<Real> alignedBox;
- };
- }
|