SaturnRingLibrary 0.9.1
SGL wrapper
 
Loading...
Searching...
No Matches
SRL::Math::Types::AABB Class Reference

Detailed Description

Axis-Aligned Bounding Box (AABB) representation for efficient collision detection.

An AABB is a rectangular cuboid whose faces are aligned with the coordinate axes. It is defined by a center point and half-extents (size) along each axis.

Key features of this implementation:

  • Memory-efficient representation using only a center point and half-extents
  • Constant-time intersection tests with other AABBs, rays, and points
  • Optimized for performance-critical collision detection pipelines
  • Supports both construction from min/max points and from center/size
  • Provides methods for volume and surface area calculations

AABBs are primarily used for:

  • Broad-phase collision detection in physics simulations
  • Spatial partitioning structures (octrees, BVH trees)
  • View frustum culling in rendering pipelines
  • Ray-casting acceleration

This implementation inherits from the Shape base class, allowing it to be used polymorphically with other geometric primitives in the library.

Note
While AABBs are very efficient for collision detection, they can become inefficient for rotated objects. Consider using oriented bounding boxes (OBBs) for objects that undergo significant rotation.

#include <aabb.hpp>

Inheritance diagram for SRL::Math::Types::AABB:
SRL::Math::Types::Shape

Public Member Functions

constexpr AABB ()
 Creates AABB at origin with zero size.
 
constexpr AABB (const Vector3D &center, const Fxp &size)
 Creates AABB from center and size.
 
constexpr AABB (const Vector3D &center, const Vector3D &halfSize)
 Creates AABB from center and half-extents.
 
bool Contains (const Vector3D &point) const override
 Check if a point is inside the AABB.
 
bool ContainsAABB (const AABB &other) const
 Check if another AABB is inside this AABB.
 
bool ContainsPoint (const Vector3D &point) const
 Check if a point is inside the AABB.
 
constexpr AABB Expand (const Fxp &margin) const
 Expand the AABB by a margin.
 
constexpr Vector3D GetClosestPoint (const Vector3D &point) const
 Gets closest point on AABB to target point.
 
constexpr Vector3D GetMax () const
 Gets maximum corner point.
 
constexpr Vector3D GetMin () const
 Gets minimum corner point.
 
Vector3D GetPosition () const
 Get the position of the AABB.
 
constexpr Vector3D GetSize () const
 Gets box half-size.
 
constexpr Fxp GetSurfaceArea () const
 Calculate the surface area of the AABB.
 
std::array< Vector3D, 8 > GetVertices () const
 Get all 8 vertices of the AABB.
 
constexpr Fxp GetVolume () const
 Calculate the volume of the AABB.
 
AABB Intersection (const AABB &other) const
 Calculate the intersection of two AABBs.
 
bool Intersects (const Plane &plane) const override
 Check if the AABB intersects with a plane.
 
bool IntersectsAABB (const AABB &other) const
 Check if this AABB intersects with another AABB.
 
AABB Merge (const AABB &other) const
 Merge this AABB with another AABB to create a new AABB that encompasses both.
 
constexpr AABB Scale (const Fxp &scale) const
 Scale the AABB by a factor.
 
constexpr void SetPosition (const Vector3D &pos)
 Sets shape center position.
 

Static Public Member Functions

static constexpr AABB FromMinMax (const Vector3D &minPoint, const Vector3D &maxPoint)
 Creates AABB from min/max points.
 

Protected Attributes

Vector3D position