-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAABB.cpp
32 lines (26 loc) · 1.09 KB
/
AABB.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <glm/glm.hpp>
#include "Util.hpp"
#include "AABB.hpp"
AABB::AABB(const v3& center, const float& halfDimension) :
center(center),
halfDimension(halfDimension)
{
}
AABB::AABB(const AABB& o) : center(o.center), halfDimension(o.halfDimension) {
}
bool AABB::containsPoint(const v3& point) const {
return (point.x <= center.x+halfDimension &&
point.x >= center.x-halfDimension &&
point.y <= center.y+halfDimension &&
point.y >= center.y-halfDimension &&
point.z <= center.z+halfDimension &&
point.z >= center.z-halfDimension);
}
bool AABB::intersectsAABB(const AABB& other) const {
return (other.center.x-other.halfDimension <= center.x+halfDimension &&
other.center.x+other.halfDimension >= center.x-halfDimension &&
other.center.y-other.halfDimension <= center.y+halfDimension &&
other.center.y+other.halfDimension >= center.y-halfDimension &&
other.center.z-other.halfDimension <= center.z+halfDimension &&
other.center.z+other.halfDimension >= center.z-halfDimension);
}