Unravel Engine C++ Reference
Loading...
Searching...
No Matches
math::bbox Class Reference

Storage for box vector values and wraps up common functionality. More...

#include <bbox.h>

Public Member Functions

 bbox ()
 Default Constructor.
 
 bbox (const vec3 &minimum, const vec3 &maximum)
 Constructor that sets values from vector values passed.
 
 bbox (float xMin, float yMin, float zMin, float xMax, float yMax, float zMax)
 Constructor that sets values from float values passed.
 
plane get_plane (volume_plane::e side) const
 Retrieves the plane for the specified side of the bounding box.
 
void get_plane_points (volume_plane::e side, vec3 points_out[]) const
 Retrieves the four points that form the boundary of the specified side of the bounding box.
 
bboxfrom_points (const char *point_buffer, unsigned int point_count, unsigned int point_stride, bool reset=true)
 Calculates the bounding box based on the points specified.
 
bboxfrom_sphere (const vec3 &center, float radius)
 Calculates the bounding box based on the sphere specified.
 
bool intersect (const bbox &bounds) const
 Tests to see if this AABB is intersected by another AABB.
 
bool intersect (const bbox &bounds, bool &contained) const
 Tests to see if this AABB is intersected by another AABB with full containment test.
 
bool intersect (const bbox &bounds, bbox &intersection) const
 Tests to see if this AABB is intersected by another AABB and returns the resulting intersection.
 
bool intersect (const bbox &bounds, const vec3 &tolerance) const
 Tests to see if this AABB is intersected by another AABB with a tolerance.
 
bool intersect (const vec3 &origin, const vec3 &velocity, float &t, bool restrict_range=true) const
 Tests to see if a ray intersects the AABB.
 
bool intersect (const vec3 &v0, const vec3 &v1, const vec3 &v2, const bbox &triangle_bounds) const
 Tests to see if a triangle intersects the AABB.
 
bool intersect (const vec3 &v0, const vec3 &v1, const vec3 &v2) const
 Tests to see if a triangle intersects the AABB.
 
bool contains_point (const vec3 &point) const
 Tests to see if a point falls within this bounding box or not.
 
bool contains_point (const vec3 &point, const vec3 &tolerance) const
 Tests to see if a point falls within this bounding box or not including a specific tolerance around the box.
 
bool contains_point (const vec3 &point, float tolerance) const
 Tests to see if a point falls within this bounding box or not including a specific tolerance around the box.
 
vec3 closest_point (const vec3 &source_point) const
 Computes the closest point on the surface of the AABB to the input point.
 
void validate ()
 Ensures that the values placed in the min/max values never make the bounding box itself inverted.
 
void reset ()
 Resets the bounding box values.
 
bboxmul (const transform &t)
 Transforms an axis aligned bounding box by the specified matrix.
 
bboxmul_no_scale (const transform &t)
 
bboxadd_point (const vec3 &point)
 Grows the bounding box based on the point passed.
 
vec3 get_dimensions () const
 Returns a vector containing the dimensions of the bounding box.
 
vec3 get_center () const
 Returns a vector containing the exact center point of the box.
 
vec3 get_extents () const
 Returns a vector containing the extents of the bounding box (the half-dimensions)
 
void inflate (float amount)
 Grows the bounding box by the specified number of world space units on all three axes.
 
void inflate (const vec3 &amount)
 Grows the bounding box by the specified numbers of world space units on each of the three axes independently.
 
bool is_populated () const
 Checks if the bounding box is populated.
 
bool is_degenerate () const
 Checks if the bounding box is degenerate (empty)
 
std::array< vec3, 8 > get_corners () const
 
bbox operator* (float scale) const
 Scales the bounding box values by the scalar passed.
 
bboxoperator+= (const vec3 &shift)
 Moves the bounding box by the vector passed.
 
bboxoperator-= (const vec3 &shift)
 Moves the bounding box by the vector passed.
 
bboxoperator*= (const transform &t)
 Transforms the bounding box by the matrix passed.
 
bboxoperator*= (float scale)
 Scales the bounding box values by the scalar passed.
 
bool operator== (const bbox &bounds) const
 Checks for equality between this bounding box and another.
 
bool operator!= (const bbox &bounds) const
 Checks for inequality between this bounding box and another.
 

Static Public Member Functions

static bbox mul (const bbox &bounds, const transform &t)
 Static method to transform the specified bounding box by the provided matrix and return the new resulting box as a copy.
 
static bbox mul_no_scale (const bbox &bounds, const transform &t)
 

Public Attributes

vec3 min
 The minimum vector value of the bounding box.
 
vec3 max
 The maximum vector value of the bounding box.
 

Static Public Attributes

static bbox empty
 An empty bounding box.
 

Detailed Description

Storage for box vector values and wraps up common functionality.

Definition at line 20 of file bbox.h.

Constructor & Destructor Documentation

◆ bbox() [1/3]

math::bbox::bbox ( )

Default Constructor.

Definition at line 8 of file bbox.cpp.

◆ bbox() [2/3]

math::bbox::bbox ( const vec3 & minimum,
const vec3 & maximum )

Constructor that sets values from vector values passed.

Parameters
minimumMinimum vector value
maximumMaximum vector value

Definition at line 14 of file bbox.cpp.

◆ bbox() [3/3]

math::bbox::bbox ( float xMin,
float yMin,
float zMin,
float xMax,
float yMax,
float zMax )

Constructor that sets values from float values passed.

Parameters
xMinMinimum x-coordinate
yMinMinimum y-coordinate
zMinMinimum z-coordinate
xMaxMaximum x-coordinate
yMaxMaximum y-coordinate
zMaxMaximum z-coordinate

Definition at line 21 of file bbox.cpp.

Member Function Documentation

◆ add_point()

bbox & math::bbox::add_point ( const vec3 & point)

Grows the bounding box based on the point passed.

Parameters
pointThe point to add
Returns
Reference to the modified bounding box

Definition at line 924 of file bbox.cpp.

◆ closest_point()

vec3 math::bbox::closest_point ( const vec3 & source_point) const

Computes the closest point on the surface of the AABB to the input point.

Parameters
source_pointThe input point
Returns
The closest point on the AABB

Definition at line 826 of file bbox.cpp.

◆ contains_point() [1/3]

bool math::bbox::contains_point ( const vec3 & point) const

Tests to see if a point falls within this bounding box or not.

Parameters
pointThe point to test
Returns
True if the point is within the bounding box, false otherwise

Definition at line 792 of file bbox.cpp.

◆ contains_point() [2/3]

bool math::bbox::contains_point ( const vec3 & point,
const vec3 & tolerance ) const

Tests to see if a point falls within this bounding box or not including a specific tolerance around the box.

Parameters
pointThe point to test
toleranceThe tolerance value
Returns
True if the point is within the bounding box with tolerance, false otherwise

Definition at line 809 of file bbox.cpp.

◆ contains_point() [3/3]

bool math::bbox::contains_point ( const vec3 & point,
float tolerance ) const

Tests to see if a point falls within this bounding box or not including a specific tolerance around the box.

Parameters
pointThe point to test
toleranceThe tolerance value
Returns
True if the point is within the bounding box with tolerance, false otherwise

Definition at line 775 of file bbox.cpp.

◆ from_points()

bbox & math::bbox::from_points ( const char * point_buffer,
unsigned int point_count,
unsigned int point_stride,
bool reset = true )

Calculates the bounding box based on the points specified.

Parameters
point_bufferPointer to the buffer containing points
point_countNumber of points
point_strideStride between points
resetReset the bounding box before calculation
Returns
Reference to the modified bounding box

Definition at line 190 of file bbox.cpp.

◆ from_sphere()

bbox & math::bbox::from_sphere ( const vec3 & center,
float radius )

Calculates the bounding box based on the sphere specified.

Parameters
centerCenter of the sphere
radiusRadius of the sphere
Returns
Reference to the modified bounding box

Definition at line 213 of file bbox.cpp.

◆ get_center()

vec3 math::bbox::get_center ( ) const

Returns a vector containing the exact center point of the box.

Returns
The center point of the box

Definition at line 946 of file bbox.cpp.

◆ get_corners()

std::array< vec3, 8 > math::bbox::get_corners ( ) const

Returns the 8 corners of the box in the following order: (xmin,ymin,zmin), (xmax,ymin,zmin), (xmin,ymax,zmin), (xmax,ymax,zmin), (xmin,ymin,zmax), (xmax,ymin,zmax), (xmin,ymax,zmax), (xmax,ymax,zmax)

Definition at line 976 of file bbox.cpp.

◆ get_dimensions()

vec3 math::bbox::get_dimensions ( ) const

Returns a vector containing the dimensions of the bounding box.

Returns
The dimensions of the bounding box

Definition at line 941 of file bbox.cpp.

◆ get_extents()

vec3 math::bbox::get_extents ( ) const

Returns a vector containing the extents of the bounding box (the half-dimensions)

Returns
The extents of the bounding box

Definition at line 951 of file bbox.cpp.

◆ get_plane()

plane math::bbox::get_plane ( volume_plane::e side) const

Retrieves the plane for the specified side of the bounding box.

Parameters
sideThe side of the bounding box
Returns
The plane for the specified side

Definition at line 59 of file bbox.cpp.

◆ get_plane_points()

void math::bbox::get_plane_points ( volume_plane::e side,
vec3 points_out[] ) const

Retrieves the four points that form the boundary of the specified side of the bounding box.

Parameters
sideThe side of the bounding box
points_outArray to store the four points

Definition at line 97 of file bbox.cpp.

◆ inflate() [1/2]

void math::bbox::inflate ( const vec3 & amount)

Grows the bounding box by the specified numbers of world space units on each of the three axes independently.

Parameters
amountThe amount to grow the bounding box on each axis

Definition at line 966 of file bbox.cpp.

◆ inflate() [2/2]

void math::bbox::inflate ( float amount)

Grows the bounding box by the specified number of world space units on all three axes.

Parameters
amountThe amount to grow the bounding box

Definition at line 956 of file bbox.cpp.

◆ intersect() [1/7]

bool math::bbox::intersect ( const bbox & bounds) const

Tests to see if this AABB is intersected by another AABB.

Parameters
boundsThe other bounding box
Returns
True if intersected, false otherwise

Definition at line 244 of file bbox.cpp.

◆ intersect() [2/7]

bool math::bbox::intersect ( const bbox & bounds,
bbox & intersection ) const

Tests to see if this AABB is intersected by another AABB and returns the resulting intersection.

Parameters
boundsThe other bounding box
intersectionThe resulting intersection bounding box
Returns
True if intersected, false otherwise

Definition at line 292 of file bbox.cpp.

◆ intersect() [3/7]

bool math::bbox::intersect ( const bbox & bounds,
bool & contained ) const

Tests to see if this AABB is intersected by another AABB with full containment test.

Parameters
boundsThe other bounding box
containedOutput parameter to indicate if fully contained
Returns
True if intersected, false otherwise

Definition at line 250 of file bbox.cpp.

◆ intersect() [4/7]

bool math::bbox::intersect ( const bbox & bounds,
const vec3 & tolerance ) const

Tests to see if this AABB is intersected by another AABB with a tolerance.

Parameters
boundsThe other bounding box
toleranceThe tolerance vector
Returns
True if intersected, false otherwise

Definition at line 312 of file bbox.cpp.

◆ intersect() [5/7]

bool math::bbox::intersect ( const vec3 & origin,
const vec3 & velocity,
float & t,
bool restrict_range = true ) const

Tests to see if a ray intersects the AABB.

Parameters
originThe origin of the ray
velocityThe direction and magnitude of the ray
tOutput parameter for the intersection time
restrict_rangeRestrict the range of t to [0, 1]
Returns
True if intersected, false otherwise

Definition at line 322 of file bbox.cpp.

◆ intersect() [6/7]

bool math::bbox::intersect ( const vec3 & v0,
const vec3 & v1,
const vec3 & v2 ) const

Tests to see if a triangle intersects the AABB.

Parameters
v0First vertex of the triangle
v1Second vertex of the triangle
v2Third vertex of the triangle
Returns
True if intersected, false otherwise

Definition at line 633 of file bbox.cpp.

◆ intersect() [7/7]

bool math::bbox::intersect ( const vec3 & v0,
const vec3 & v1,
const vec3 & v2,
const bbox & triangle_bounds ) const

Tests to see if a triangle intersects the AABB.

Parameters
v0First vertex of the triangle
v1Second vertex of the triangle
v2Third vertex of the triangle
triangle_boundsBounding box of the triangle
Returns
True if intersected, false otherwise

Definition at line 496 of file bbox.cpp.

◆ is_degenerate()

bool math::bbox::is_degenerate ( ) const

Checks if the bounding box is degenerate (empty)

Returns
True if degenerate, false otherwise

Definition at line 52 of file bbox.cpp.

◆ is_populated()

bool math::bbox::is_populated ( ) const

Checks if the bounding box is populated.

Returns
True if populated, false otherwise

Definition at line 36 of file bbox.cpp.

◆ mul() [1/2]

bbox math::bbox::mul ( const bbox & bounds,
const transform & t )
static

Static method to transform the specified bounding box by the provided matrix and return the new resulting box as a copy.

Parameters
boundsThe bounding box to transform
tThe transformation matrix
Returns
The transformed bounding box

Definition at line 884 of file bbox.cpp.

◆ mul() [2/2]

bbox & math::bbox::mul ( const transform & t)

Transforms an axis aligned bounding box by the specified matrix.

Parameters
tThe transformation matrix
Returns
Reference to the transformed bounding box

Definition at line 876 of file bbox.cpp.

◆ mul_no_scale() [1/2]

bbox math::bbox::mul_no_scale ( const bbox & bounds,
const transform & t )
static

Definition at line 908 of file bbox.cpp.

◆ mul_no_scale() [2/2]

bbox & math::bbox::mul_no_scale ( const transform & t)

Definition at line 900 of file bbox.cpp.

◆ operator!=()

bool math::bbox::operator!= ( const bbox & bounds) const

Checks for inequality between this bounding box and another.

Parameters
boundsThe other bounding box
Returns
True if not equal, false otherwise

Definition at line 1027 of file bbox.cpp.

◆ operator*()

bbox math::bbox::operator* ( float scale) const

Scales the bounding box values by the scalar passed.

Parameters
scaleThe scale factor
Returns
The scaled bounding box

Definition at line 1004 of file bbox.cpp.

◆ operator*=() [1/2]

bbox & math::bbox::operator*= ( const transform & t)

Transforms the bounding box by the matrix passed.

Parameters
tThe transformation matrix
Returns
Reference to the modified bounding box

Definition at line 1016 of file bbox.cpp.

◆ operator*=() [2/2]

bbox & math::bbox::operator*= ( float scale)

Scales the bounding box values by the scalar passed.

Parameters
scaleThe scale factor
Returns
Reference to the modified bounding box

Definition at line 1009 of file bbox.cpp.

◆ operator+=()

bbox & math::bbox::operator+= ( const vec3 & shift)

Moves the bounding box by the vector passed.

Parameters
shiftThe vector to move by
Returns
Reference to the modified bounding box

Definition at line 990 of file bbox.cpp.

◆ operator-=()

bbox & math::bbox::operator-= ( const vec3 & shift)

Moves the bounding box by the vector passed.

Parameters
shiftThe vector to move by
Returns
Reference to the modified bounding box

Definition at line 997 of file bbox.cpp.

◆ operator==()

bool math::bbox::operator== ( const bbox & bounds) const

Checks for equality between this bounding box and another.

Parameters
boundsThe other bounding box
Returns
True if equal, false otherwise

Definition at line 1022 of file bbox.cpp.

◆ reset()

void math::bbox::reset ( )

Resets the bounding box values.

Definition at line 28 of file bbox.cpp.

◆ validate()

void math::bbox::validate ( )

Ensures that the values placed in the min/max values never make the bounding box itself inverted.

Definition at line 221 of file bbox.cpp.

Member Data Documentation

◆ empty

bbox math::bbox::empty
static

An empty bounding box.

Definition at line 316 of file bbox.h.

◆ max

vec3 math::bbox::max

The maximum vector value of the bounding box.

Definition at line 311 of file bbox.h.

◆ min

vec3 math::bbox::min

The minimum vector value of the bounding box.

Definition at line 306 of file bbox.h.


The documentation for this class was generated from the following files: