Add AABB::encapsulate(const Vector3& v)
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled

Add AABB::Create(const AABB& modelSpaceExtents, const Matrix4& modelMatrix)
This commit is contained in:
2026-05-17 12:50:26 -07:00
parent cc7dffbb9a
commit 17b4ec2cde
2 changed files with 20 additions and 0 deletions

View File

@@ -53,6 +53,7 @@ public:
void init(); void init();
static AABB Create(const Vector3& minPoint, const Vector3& maxPoint); static AABB Create(const Vector3& minPoint, const Vector3& maxPoint);
static AABB Create(const Vector3& corner1, const Vector3& corner2, const Matrix4& modelMatrix); static AABB Create(const Vector3& corner1, const Vector3& corner2, const Matrix4& modelMatrix);
static AABB Create(const AABB& modelSpaceExtents, const Matrix4& modelMatrix);
static AABB Create(); static AABB Create();
void scale(const Vector3& s); void scale(const Vector3& s);
@@ -69,6 +70,7 @@ public:
bool intersectsRay(const Vector3& v1, const Vector3& dir) const; bool intersectsRay(const Vector3& v1, const Vector3& dir) const;
bool intersectsSphere(const Vector3& center, float radius) const; bool intersectsSphere(const Vector3& center, float radius) const;
void encapsulate(const AABB& b); void encapsulate(const AABB& b);
void encapsulate(const Vector3& v);
bool operator ==(const AABB& b) const; bool operator ==(const AABB& b) const;
bool operator !=(const AABB& b) const; bool operator !=(const AABB& b) const;

View File

@@ -91,6 +91,13 @@ AABB AABB::Create(const Vector3& corner1, const Vector3& corner2, const Matrix4&
return r; return r;
} }
AABB AABB::Create(const AABB& modelSpaceExtents, const Matrix4& modelMatrix)
{
AABB r;
r.init(modelSpaceExtents.min, modelSpaceExtents.max, modelMatrix);
return r;
}
bool AABB::operator ==(const AABB& b) const bool AABB::operator ==(const AABB& b) const
{ {
return min == b.min && max == b.max; return min == b.min && max == b.max;
@@ -366,6 +373,17 @@ void AABB::encapsulate(const AABB& b)
if (b.max.z > max.z) max.z = b.max.z; if (b.max.z > max.z) max.z = b.max.z;
} }
void AABB::encapsulate(const Vector3& v)
{
if (v.x < min.x) min.x = v.x;
if (v.y < min.y) min.y = v.y;
if (v.z < min.z) min.z = v.z;
if (v.x > max.x) max.x = v.x;
if (v.y > max.y) max.y = v.y;
if (v.z > max.z) max.z = v.z;
}
Vector3 AABB::nearestPoint(const Vector3& v) const Vector3 AABB::nearestPoint(const Vector3& v) const
{ {
return Vector3::Create(KRCLAMP(v.x, min.x, max.x), KRCLAMP(v.y, min.y, max.y), KRCLAMP(v.z, min.z, max.z)); return Vector3::Create(KRCLAMP(v.x, min.x, max.x), KRCLAMP(v.y, min.y, max.y), KRCLAMP(v.z, min.z, max.z));