CoriEngine
Loading...
Searching...
No Matches
AABB.hpp
Go to the documentation of this file.
1#pragma once
2
3namespace Cori {
7 namespace Utility {
11 struct AABB {
12 glm::vec2 m_Min;
13 glm::vec2 m_Max;
14 };
15
22 [[nodiscard]] inline AABB CalculateAABB(const glm::mat3& transform, const glm::vec2 halfSize) {
23 const glm::vec2 corners[4]{
24 {transform * glm::vec3{-halfSize.x, -halfSize.y, 1.0f}},
25 {transform * glm::vec3{halfSize.x, -halfSize.y, 1.0f}},
26 {transform * glm::vec3{halfSize.x, halfSize.y, 1.0f}},
27 {transform * glm::vec3{-halfSize.x, halfSize.y, 1.0f}},
28 };
29 AABB bounds { corners[0], corners[0] };
30
31 for (int32_t i = 1; i < 4; ++i) {
32 bounds.m_Min.x = std::min(bounds.m_Min.x, corners[i].x);
33 bounds.m_Min.y = std::min(bounds.m_Min.y, corners[i].y);
34 bounds.m_Max.x = std::max(bounds.m_Max.x, corners[i].x);
35 bounds.m_Max.y = std::max(bounds.m_Max.y, corners[i].y);
36 }
37
38 return bounds;
39 }
40
47 [[nodiscard]] inline bool AABBOverlapCheck(const AABB& a, const AABB& b) {
48 return (a.m_Min.x <= b.m_Max.x && a.m_Max.x >= b.m_Min.x) &&
49 (a.m_Min.y <= b.m_Max.y && a.m_Max.y >= b.m_Min.y);
50 }
51 }
52}
A namespace for utilities of different kinds.
Definition AABB.hpp:7
bool AABBOverlapCheck(const AABB &a, const AABB &b)
Checks if 2 AABBs overlap.
Definition AABB.hpp:47
AABB CalculateAABB(const glm::mat3 &transform, const glm::vec2 halfSize)
Calculates the AABB for the quad taking into account rotation and scale.
Definition AABB.hpp:22
Global engine namespace.
Axis-Aligned bounding box.
Definition AABB.hpp:11
glm::vec2 m_Max
Definition AABB.hpp:13
glm::vec2 m_Min
Definition AABB.hpp:12