Raven Engine v0.1
A modern 3D Game Engine
Loading...
Searching...
No Matches
Crux::AABB Struct Reference

Axis-aligned bounding box defined by a min and max corner in 3D space. More...

#include <BoundingVolumes.h>

Public Member Functions

constexpr vec3 Center () const
 Returns the center point of the box.
constexpr vec3 HalfExtents () const
 Returns the half-extents of the box (half the size along each axis).
constexpr vec3 Size () const
 Returns the full size of the box along each axis.
constexpr bool IsValid () const
 Checks whether this AABB is valid (not inside-out).
constexpr void Expand (const vec3 &point)
 Expands the box to include the given point.
constexpr void Expand (const AABB &other)
 Expands the box to fully contain another AABB.
constexpr void Expand (f32 amount)
 Uniformly expands the box outward by a fixed amount on all sides.
AABB Transformed (const mat4 &m) const
 Returns a new AABB enclosing this box after an affine transform is applied.
constexpr bool Intersects (const AABB &other) const
 Tests whether this box overlaps another AABB.
constexpr bool Contains (const vec3 &point) const
 Tests whether a point lies inside or on the surface of this box.
constexpr bool Contains (const AABB &other) const
 Tests whether another AABB is fully contained within this box.
constexpr vec3 ClosestPoint (const vec3 &point) const
 Returns the closest point on or inside this box to a given point.

Static Public Member Functions

static constexpr AABB Empty ()
 Returns an empty (inside-out) AABB.
static constexpr AABB FromCenterExtents (const vec3 &center, const vec3 &halfExtents)
 Constructs an AABB from a center point and half-extents.
static AABB FromMinMax (const vec3 &min, const vec3 &max)
 Constructs an AABB from explicit min and max corners.
static constexpr AABB Merge (const AABB &a, const AABB &b)
 Returns the smallest AABB containing both inputs.

Public Attributes

vec3 Min {0x1.fffffep+127, 0x1.fffffep+127, 0x1.fffffep+127}
vec3 Max {-0x1.fffffep+127, -0x1.fffffep+127, -0x1.fffffep+127}

Detailed Description

Axis-aligned bounding box defined by a min and max corner in 3D space.

Initialized to an "inside-out" state so that the first Expand() call produces a valid box regardless of point order.

Member Function Documentation

◆ Center()

vec3 Crux::AABB::Center ( ) const
inlineconstexpr

Returns the center point of the box.

Returns
The midpoint between Min and Max.

◆ ClosestPoint()

vec3 Crux::AABB::ClosestPoint ( const vec3 & point) const
inlineconstexpr

Returns the closest point on or inside this box to a given point.

Parameters
pointThe query point.
Returns
The nearest point within [Min, Max] to point.

◆ Contains() [1/2]

bool Crux::AABB::Contains ( const AABB & other) const
inlineconstexpr

Tests whether another AABB is fully contained within this box.

Parameters
otherThe AABB to test.
Returns
True if both corners of other lie within this box.

◆ Contains() [2/2]

bool Crux::AABB::Contains ( const vec3 & point) const
inlineconstexpr

Tests whether a point lies inside or on the surface of this box.

Parameters
pointThe point to test.
Returns
True if the point is within [Min, Max] on all axes.

◆ Empty()

constexpr AABB Crux::AABB::Empty ( )
inlinestaticconstexpr

Returns an empty (inside-out) AABB.

Returns
An AABB with Min set to +FLT_MAX and Max set to -FLT_MAX.

◆ Expand() [1/3]

void Crux::AABB::Expand ( const AABB & other)
inlineconstexpr

Expands the box to fully contain another AABB.

Parameters
otherThe AABB to include.

◆ Expand() [2/3]

void Crux::AABB::Expand ( const vec3 & point)
inlineconstexpr

Expands the box to include the given point.

Parameters
pointThe point to include.

◆ Expand() [3/3]

void Crux::AABB::Expand ( f32 amount)
inlineconstexpr

Uniformly expands the box outward by a fixed amount on all sides.

Parameters
amountThe distance to expand each side outward.

◆ FromCenterExtents()

constexpr AABB Crux::AABB::FromCenterExtents ( const vec3 & center,
const vec3 & halfExtents )
inlinestaticconstexpr

Constructs an AABB from a center point and half-extents.

Parameters
centerThe center point of the box.
halfExtentsHalf the size of the box along each axis.
Returns
An AABB with Min = center - halfExtents and Max = center + halfExtents.

◆ FromMinMax()

AABB Crux::AABB::FromMinMax ( const vec3 & min,
const vec3 & max )
inlinestatic

Constructs an AABB from explicit min and max corners.

Parameters
minThe minimum corner of the box.
maxThe maximum corner of the box.
Returns
An AABB spanning [min, max].

◆ HalfExtents()

vec3 Crux::AABB::HalfExtents ( ) const
inlineconstexpr

Returns the half-extents of the box (half the size along each axis).

Returns
Half the size of the box along each axis.

◆ Intersects()

bool Crux::AABB::Intersects ( const AABB & other) const
inlineconstexpr

Tests whether this box overlaps another AABB.

Touching counts as intersection.

Parameters
otherThe AABB to test against.
Returns
True if the two boxes overlap on all three axes.

◆ IsValid()

bool Crux::AABB::IsValid ( ) const
inlineconstexpr

Checks whether this AABB is valid (not inside-out).

Returns
True if Min <= Max on all axes.

◆ Merge()

constexpr AABB Crux::AABB::Merge ( const AABB & a,
const AABB & b )
inlinestaticconstexpr

Returns the smallest AABB containing both inputs.

Parameters
aThe first AABB.
bThe second AABB.
Returns
The union of a and b.

◆ Size()

vec3 Crux::AABB::Size ( ) const
inlineconstexpr

Returns the full size of the box along each axis.

Returns
Max - Min per component.

◆ Transformed()

AABB Crux::AABB::Transformed ( const mat4 & m) const
inline

Returns a new AABB enclosing this box after an affine transform is applied.

Uses the Arvo method: transforms the center and reprojects the half-extents through the absolute values of the rotation/scale portion of the matrix. Correct for any affine transform (rotation, scale, shear, translation).

Parameters
mRow-major affine transform matrix.
Returns
A new AABB enclosing the transformed box.

Member Data Documentation

◆ Max

vec3 Crux::AABB::Max {-0x1.fffffep+127, -0x1.fffffep+127, -0x1.fffffep+127}

◆ Min

vec3 Crux::AABB::Min {0x1.fffffep+127, 0x1.fffffep+127, 0x1.fffffep+127}

The documentation for this struct was generated from the following file: