readme
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#ifndef COLLISION_MESH_CLASS
|
||||
#define COLLISION_MESH_CLASS
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#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<Triangle>& meshTriangles);
|
||||
|
||||
// The 12 triangles of a unit cube, used for any body without its own mesh
|
||||
static const CollisionMesh& UnitBox();
|
||||
|
||||
const std::vector<Triangle>& 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<int>& 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<Triangle> triangles;
|
||||
std::vector<Node> nodes;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user