18 #include "GeometryUtil.h"
22 class TriangleTreeCell {
24 TriangleTreeCell(std::vector<Triangle>& allTriangles) : _allTriangles(allTriangles) {}
25 TriangleTreeCell(std::vector<Triangle>& allTriangles,
const AABox& bounds,
int depth);
27 void insert(
size_t triangleIndex);
28 void reset(
const AABox& bounds,
int depth = 0);
31 bool findRayIntersection(
const glm::vec3& origin,
const glm::vec3& direction,
const glm::vec3& invDirection,
32 float& distance, BoxFace& face, Triangle& triangle,
bool precision,
int& trianglesTouched,
33 bool allowBackface =
false);
34 bool findParabolaIntersection(
const glm::vec3& origin,
const glm::vec3& velocity,
const glm::vec3& acceleration,
35 float& parabolicDistance, BoxFace& face, Triangle& triangle,
bool precision,
int& trianglesTouched,
36 bool allowBackface =
false);
38 const AABox& getBounds()
const {
return _bounds; }
44 bool findRayIntersectionInternal(
const glm::vec3& origin,
const glm::vec3& direction,
45 float& distance, BoxFace& face, Triangle& triangle,
bool precision,
int& trianglesTouched,
46 bool allowBackface =
false);
47 bool findParabolaIntersectionInternal(
const glm::vec3& origin,
const glm::vec3& velocity,
const glm::vec3& acceleration,
48 float& parabolicDistance, BoxFace& face, Triangle& triangle,
bool precision,
int& trianglesTouched,
49 bool allowBackface =
false);
51 std::pair<AABox, AABox> getTriangleTreeCellChildBounds();
53 std::vector<Triangle>& _allTriangles;
54 std::pair<std::shared_ptr<TriangleTreeCell>, std::shared_ptr<TriangleTreeCell>> _children;
56 int _population { 0 };
58 std::vector<size_t> _triangleIndices;
60 friend class TriangleSet;
63 using SortedTriangleCell = std::pair<float, std::shared_ptr<TriangleTreeCell>>;
66 TriangleSet() : _triangleTree(_triangles) {}
70 void insert(
const Triangle& t);
72 bool findRayIntersection(
const glm::vec3& origin,
const glm::vec3& direction,
const glm::vec3& invDirection,
73 float& distance, BoxFace& face, Triangle& triangle,
bool precision,
bool allowBackface =
false);
74 bool findParabolaIntersection(
const glm::vec3& origin,
const glm::vec3& velocity,
const glm::vec3& acceleration,
75 float& parabolicDistance, BoxFace& face, Triangle& triangle,
bool precision,
bool allowBackface =
false);
79 void reserve(
size_t size) { _triangles.reserve(size); }
80 size_t size()
const {
return _triangles.size(); }
86 bool convexHullContains(
const glm::vec3& point)
const;
87 const AABox& getBounds()
const {
return _bounds; }
90 bool _isBalanced {
false };
91 std::vector<Triangle> _triangles;
92 TriangleTreeCell _triangleTree;