diff --git a/src/maths/aabb.h b/src/maths/aabb.h new file mode 100644 index 00000000..097e772f --- /dev/null +++ b/src/maths/aabb.h @@ -0,0 +1,31 @@ +#ifndef MATHS_AABB_H_ +#define MATHS_AABB_H_ + +#include + +// Axis Aligned Bounding Box +struct AABB { + glm::vec3 a; + glm::vec3 b; + + inline glm::vec3 min() const { + return glm::min(a, b); + } + + inline glm::vec3 size() const { + return glm::vec3( + fabs(b.x - a.x), + fabs(b.y - a.y), + fabs(b.z - a.z) + ); + } + + inline bool inside(const glm::vec3 pos) const { + const glm::vec3 p = min(); + const glm::vec3 s = size(); + return !(pos.x < p.x || pos.y < p.y || + pos.x >= p.x+s.x || pos.y >= p.y+s.y); + } +}; + +#endif // MATHS_AABB_H_ \ No newline at end of file