Added AABB struct

This commit is contained in:
MihailRis 2023-11-29 13:18:47 +03:00
parent b6a139528d
commit 7add5e6dcb

31
src/maths/aabb.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef MATHS_AABB_H_
#define MATHS_AABB_H_
#include <glm/glm.hpp>
// 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_