#ifndef COLLISION_MESH_CLASS #define COLLISION_MESH_CLASS #include #include #include "Structures.h" // Triangle soup for triangle by triangle collision, wrapped in a BVH. // Triangles live in the body's unit space, so t.GetMatrix() takes them to world space // the same way it does for a Mesh. Winding must be counter clockwise seen from outside. class CollisionMesh { public: CollisionMesh(const std::vector& meshTriangles); // The 12 triangles of a unit cube, used for any body without its own mesh static const CollisionMesh& UnitBox(); const std::vector& GetTriangles() const { return triangles; } // Appends the index of every triangle whose BVH leaf could touch tri (same space as the mesh) void Query(const Triangle& tri, std::vector& hits) const; private: struct Node { glm::vec3 boundsMin; glm::vec3 boundsMax; int left = -1; // -1 = leaf int right = -1; int start = 0; int count = 0; }; int Build(int start, int count); std::vector triangles; std::vector nodes; }; #endif