HPC_Voxel_Engine 0.2.0
High-Performance C++ Voxel Engine
Loading...
Searching...
No Matches
AABB.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <cassert>
5#include "../core/MathUtils.h"
6
12class AABB {
13public:
16
21 AABB(const Core::Vec3& ObjMinPt, const Core::Vec3& ObjMaxPt)
22 : m_objMinPt(ObjMinPt), m_objMaxPt(ObjMaxPt) {
23 // Strict Validation: Stop execution if data is invalid.
24 // If these trigger, you likely have a negative size in your RigidBody.
25 assert(m_objMinPt.x <= m_objMaxPt.x && "AABB Error: Min.X > Max.X");
26 assert(m_objMinPt.y <= m_objMaxPt.y && "AABB Error: Min.Y > Max.Y");
27 assert(m_objMinPt.z <= m_objMaxPt.z && "AABB Error: Min.Z > Max.Z");
28 }
29
34 bool CheckCollision(const AABB& Other) const {
35 // Exit early if there is a gap on any axis
36 if (m_objMaxPt.x < Other.m_objMinPt.x || m_objMinPt.x > Other.m_objMaxPt.x)
37 return false;
38 if (m_objMaxPt.y < Other.m_objMinPt.y || m_objMinPt.y > Other.m_objMaxPt.y)
39 return false;
40 if (m_objMaxPt.z < Other.m_objMinPt.z || m_objMinPt.z > Other.m_objMaxPt.z)
41 return false;
42
43 return true;
44 }
45
46 Core::Vec3 GetCenter() const { return (m_objMinPt + m_objMaxPt) * 0.5f; }
47 Core::Vec3 GetHalfExtents() const { return (m_objMaxPt - m_objMinPt) * 0.5f; }
48
49 void Translate(const Core::Vec3& offset) {
50 m_objMinPt += offset;
51 m_objMaxPt += offset;
52 }
53};
Axis-Aligned Bounding Box for collision detection. Defined by a Minimum and Maximum point in 3D space...
Definition AABB.h:12
Core::Vec3 m_objMinPt
Definition AABB.h:14
AABB(const Core::Vec3 &ObjMinPt, const Core::Vec3 &ObjMaxPt)
Constructs an AABB from two points.
Definition AABB.h:21
void Translate(const Core::Vec3 &offset)
Definition AABB.h:49
Core::Vec3 GetHalfExtents() const
Definition AABB.h:47
Core::Vec3 GetCenter() const
Definition AABB.h:46
Core::Vec3 m_objMaxPt
Definition AABB.h:15
bool CheckCollision(const AABB &Other) const
Checks intersection with another AABB.
Definition AABB.h:34
A 3-component vector structure (x, y, z) with standard math operations.
Definition MathUtils.h:11
float x
Definition MathUtils.h:12
float z
Definition MathUtils.h:12
float y
Definition MathUtils.h:12