Saga
Saga Game Engine
Loading...
Searching...
No Matches
Saga::BoundingBox Struct Reference

Represents a bounding box. More...

#include <boundingBox.h>

Public Member Functions

glm::vec3 centroid ()
 Compute the centroid of the BoundingBox.
 
glm::vec3 size ()
 Compute the size of the BoundingBox.
 
float surfaceArea ()
 Compute the surface area of the BoundinBox.
 
float volume ()
 Compute the volume of the BoundingBox.
 
bool inside (glm::vec3 point)
 Determins if a point is inside of the bounding box.
 
bool collidesWithRay (glm::vec4 point, glm::vec4 dir)
 Determine if the BoundingBox collide with a ray.
 
std::optional< float > findCollisionWithRay (glm::vec4 point, glm::vec4 dir)
 Find the point of collision between a ray and the BoundingBox.
 
bool intersectWith (const BoundingBox &other)
 Determines if a BoundingBox intersects with another.
 
float lowerBoundSquareDistanceTo (const glm::vec3 point)
 Compute the Lower-Bound squared distance from a point to the BoundingBox.
 
std::optional< float > findCollisionWithBox (glm::vec3 centroid, glm::vec3 dir, glm::vec3 size)
 Find the collision between a moving bounding box and this one.
 

Static Public Member Functions

static BoundingBox getExtremeBound ()
 Get a special invalid BoundingBox used as a starting point for mergeBox and confineBox. This bounding box has the lower left corner at infinitiy and upper right corner at negative infinity.
 
static BoundingBox mergeBox (const BoundingBox &a, const BoundingBox &b)
 Compute a BoundingBox that is the union of the two input boxes.
 
static BoundingBox confineBox (const BoundingBox &a, const BoundingBox &b)
 Confine a BoundingBox within the other, effectively computing their intersection.
 
static BoundingBox pointBox (const glm::vec3 &point)
 Create a bounding box containing only one point.
 

Public Attributes

glm::vec3 bounds [2]
 coordinates of the lower-left and upper-right corners of the bounding box, respectively.
 

Static Public Attributes

static float const oo = 1e9f
 infinity value. No bounding box's absolute value in any dimension can exceed this.
 

Detailed Description

Represents a bounding box.

Member Function Documentation

◆ centroid()

vec3 Saga::BoundingBox::centroid ( )

Compute the centroid of the BoundingBox.

Returns
glm::vec3 centroid of the BoundingBox.

◆ collidesWithRay()

bool Saga::BoundingBox::collidesWithRay ( glm::vec4  point,
glm::vec4  dir 
)

Determine if the BoundingBox collide with a ray.

Parameters
pointthe start of the ray.
dirthe direction of the ray.
Returns
true if the ray collides with the bounding box.
false otherwise.
Here is the call graph for this function:

◆ confineBox()

BoundingBox Saga::BoundingBox::confineBox ( const BoundingBox a,
const BoundingBox b 
)
static

Confine a BoundingBox within the other, effectively computing their intersection.

Parameters
athe first bounding box.
bthe second bounding box.
Returns
BoundingBox the intersection of the two.

◆ findCollisionWithBox()

std::optional< float > Saga::BoundingBox::findCollisionWithBox ( glm::vec3  centroid,
glm::vec3  dir,
glm::vec3  size 
)

Find the collision between a moving bounding box and this one.

Parameters
centroidcentroid of the box.
dirdirection the box is moving.
sizethe size of the box.
Returns
std::optional<float> t where centroid+dir*t is the first collision between the box and bounding box, if it exists. This value is in the range [0,1]. If the boxes start off intersecting, the value returned will be 0.
Here is the call graph for this function:

◆ findCollisionWithRay()

std::optional< float > Saga::BoundingBox::findCollisionWithRay ( glm::vec4  point,
glm::vec4  dir 
)

Find the point of collision between a ray and the BoundingBox.

Parameters
pointthe start of the ray.
dirthe direction of the ray.
Returns
std::optional<float> t where point + dir * t is the first collision between the ray and the bounding box. t is in the range [0,1]. If the ray starts inside of the BoundingBox, then return 0.
Here is the call graph for this function:

◆ getExtremeBound()

BoundingBox Saga::BoundingBox::getExtremeBound ( )
static

Get a special invalid BoundingBox used as a starting point for mergeBox and confineBox. This bounding box has the lower left corner at infinitiy and upper right corner at negative infinity.

◆ inside()

bool Saga::BoundingBox::inside ( glm::vec3  point)

Determins if a point is inside of the bounding box.

Returns
true if it is inside.
false otherwise.

◆ intersectWith()

bool Saga::BoundingBox::intersectWith ( const BoundingBox other)

Determines if a BoundingBox intersects with another.

Parameters
otherthe other bounding box.
Returns
true if the two intersects.
false otherwise.

◆ lowerBoundSquareDistanceTo()

float Saga::BoundingBox::lowerBoundSquareDistanceTo ( const glm::vec3  point)

Compute the Lower-Bound squared distance from a point to the BoundingBox.

Parameters
pointthe point to compute distance to.
Returns
a number that represents a lower-bound on the squared distance to the box.

◆ mergeBox()

BoundingBox Saga::BoundingBox::mergeBox ( const BoundingBox a,
const BoundingBox b 
)
static

Compute a BoundingBox that is the union of the two input boxes.

Parameters
athe first bounding box.
bthe second bounding box.
Returns
BoundingBox the union of the two.

◆ pointBox()

BoundingBox Saga::BoundingBox::pointBox ( const glm::vec3 &  point)
static

Create a bounding box containing only one point.

Parameters
pointthe point the bounding box contains.
Returns
BoundingBox a bounding box containing only that point.

◆ size()

vec3 Saga::BoundingBox::size ( )

Compute the size of the BoundingBox.

Returns
glm::vec3 size of the BoundingBox in each direction.

◆ surfaceArea()

float Saga::BoundingBox::surfaceArea ( )

Compute the surface area of the BoundinBox.

Returns
float the surface area. 0 if the BoundingBox is not valid, for instance if therte exists a dimension dim such that bounds[0][dim] > bounds[1][dim]
Here is the call graph for this function:

◆ volume()

float Saga::BoundingBox::volume ( )

Compute the volume of the BoundingBox.

Returns
float volume of the BoundingBox. If the BoundingBox is not valid, for instance if there exists a dimension dim such that bounds[0][dim] > bounds[1][dim] then this value is 0.
Here is the call graph for this function:

Member Data Documentation

◆ bounds

glm::vec3 Saga::BoundingBox::bounds[2]

coordinates of the lower-left and upper-right corners of the bounding box, respectively.

◆ oo

const float Saga::BoundingBox::oo = 1e9f
static

infinity value. No bounding box's absolute value in any dimension can exceed this.


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