Nebula
Loading...
Searching...
No Matches
Math::bbox Class Reference

#include <bbox.h>

Detailed Description

Nebula's bounding box class.

Public Types

enum  {
  ClipLeft = N_BIT(0) , ClipRight = N_BIT(1) , ClipBottom = N_BIT(2) , ClipTop = N_BIT(3) ,
  ClipNear = N_BIT(4) , ClipFar = N_BIT(5)
}
 clip codes More...
 

Public Member Functions

 bbox ()
 constructor 1
 
 bbox (const point &center, const vector &extents)
 constructor 3
 
 bbox (const mat4 &m)
 construct bounding box from mat4
 
point center () const
 get center of box
 
vector extents () const
 get extents of box
 
vec3 size () const
 get size of box
 
scalar diagonal_size () const
 get diagonal size of box
 
void set (const mat4 &m)
 set from mat4
 
void set (const point &center, const vector &extents)
 set from center point and extents
 
void begin_extend ()
 begin extending the box
 
void extend (const vec3 &p)
 extend the box
 
void extend (const bbox &box)
 extend the box
 
void end_extend ()
 this resets the bounding box size to zero if no extend() method was called after begin_extend()
 
void transform (const mat4 &m)
 transform bounding box
 
void affine_transform (const mat4 &m)
 affine transform bounding box, does not allow for projections
 
bool intersects (const bbox &box) const
 check for intersection with axis aligned bounding box
 
bool intersects (const line &ray, float &t) const
 check for intersection with ray. parameter t will be filled with the "time" of intersection along line.m.
 
bool contains (const bbox &box) const
 check if this box completely contains the parameter box
 
bool contains (const vec3 &p) const
 return true if this box contains the position
 
ClipStatus::Type clipstatus (const bbox &other) const
 check for intersection with other bounding box
 
ClipStatus::Type clipstatus (const mat4 &viewProjection, const bool isOrtho=false) const
 check for intersection with projection volume
 
ClipStatus::Type clipstatus (const vec4 *x_columns, const vec4 *y_columns, const vec4 *z_columns, const vec4 *w_columns, const bool isOrtho=false) const
 check for intersection with pre-calculated columns
 
mat4 to_mat4 () const
 create a matrix which transforms a unit cube to this bounding box
 
point corner_point (int index) const
 return one of the 8 corner points
 
void get_clipplanes (const mat4 &viewProjection, Util::Array< vec4 > &outPlanes) const
 return side planes in clip space
 
template<typename T >
as () const
 convert to any type
 
float area () const
 calculate half-area of the surface of the box. If you need the full area, just multiply by 2.
 

Public Attributes

point pmin
 
point pmax
 

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

clip codes

Enumerator
ClipLeft 
ClipRight 
ClipBottom 
ClipTop 
ClipNear 
ClipFar 

Constructor & Destructor Documentation

◆ bbox() [1/3]

Math::bbox::bbox ( )
inline

constructor 1

◆ bbox() [2/3]

Math::bbox::bbox ( const point & center,
const vector & extents )
inline

constructor 3

◆ bbox() [3/3]

Math::bbox::bbox ( const mat4 & m)
inline

construct bounding box from mat4

Member Function Documentation

◆ affine_transform()

void Math::bbox::affine_transform ( const mat4 & m)
inline

affine transform bounding box, does not allow for projections

◆ area()

float Math::bbox::area ( ) const
inline

calculate half-area of the surface of the box. If you need the full area, just multiply by 2.

◆ as()

template<typename T >
T Math::bbox::as ( ) const

convert to any type

◆ begin_extend()

void Math::bbox::begin_extend ( )
inline

begin extending the box

◆ center()

point Math::bbox::center ( ) const
inline

get center of box

◆ clipstatus() [1/3]

ClipStatus::Type Math::bbox::clipstatus ( const bbox & other) const

check for intersection with other bounding box

Return box/box clip status.

◆ clipstatus() [2/3]

__forceinline ClipStatus::Type Math::bbox::clipstatus ( const mat4 & viewProjection,
const bool isOrtho = false ) const

check for intersection with projection volume

◆ clipstatus() [3/3]

__forceinline ClipStatus::Type Math::bbox::clipstatus ( const vec4 * x_columns,
const vec4 * y_columns,
const vec4 * z_columns,
const vec4 * w_columns,
const bool isOrtho = false ) const

check for intersection with pre-calculated columns

◆ contains() [1/2]

bool Math::bbox::contains ( const bbox & box) const
inline

check if this box completely contains the parameter box

Check if the parameter bounding box is completely contained in this bounding box.

◆ contains() [2/2]

bool Math::bbox::contains ( const vec3 & p) const
inline

return true if this box contains the position

Check if position is inside bounding box.

◆ corner_point()

point Math::bbox::corner_point ( int index) const

return one of the 8 corner points

Returns one of the 8 corners of the bounding box.

◆ diagonal_size()

scalar Math::bbox::diagonal_size ( ) const
inline

get diagonal size of box

◆ end_extend()

void Math::bbox::end_extend ( )
inline

this resets the bounding box size to zero if no extend() method was called after begin_extend()

This just checks whether the extend() method has actually been called after begin_extend() and just sets vmin and vmax to the null vector if it hasn't.

◆ extend() [1/2]

void Math::bbox::extend ( const bbox & box)
inline

extend the box

◆ extend() [2/2]

void Math::bbox::extend ( const vec3 & p)
inline

extend the box

◆ extents()

vector Math::bbox::extents ( ) const
inline

get extents of box

◆ get_clipplanes()

void Math::bbox::get_clipplanes ( const mat4 & viewProjection,
Util::Array< vec4 > & outPlanes ) const

return side planes in clip space

Get the bounding box's side planes in clip space.

◆ intersects() [1/2]

bool Math::bbox::intersects ( const bbox & box) const
inline

check for intersection with axis aligned bounding box

Check for intersection of 2 axis aligned bounding boxes.

The bounding boxes must live in the same coordinate space.

◆ intersects() [2/2]

bool Math::bbox::intersects ( const line & ray,
float & t ) const
inline

check for intersection with ray. parameter t will be filled with the "time" of intersection along line.m.

Ray/AABB Slab test from Real-Time Collision Detection by Christer Ericsson Assumes ray is normalized.

◆ set() [1/2]

void Math::bbox::set ( const mat4 & m)
inline

set from mat4

Construct a bounding box around a 4x4 matrix.

The translational part defines the center point, and the x,y,z vectors of the matrix define the extents.

◆ set() [2/2]

void Math::bbox::set ( const point & center,
const vector & extents )
inline

set from center point and extents

◆ size()

vec3 Math::bbox::size ( ) const
inline

get size of box

◆ to_mat4()

mat4 Math::bbox::to_mat4 ( ) const
inline

create a matrix which transforms a unit cube to this bounding box

Create a transform matrix which would transform a unit cube to this bounding box.

◆ transform()

void Math::bbox::transform ( const mat4 & m)
inline

transform bounding box

Transforms this axis aligned bounding by the 4x4 matrix.

This bounding box must be axis aligned with the matrix, the resulting bounding will be axis aligned in the matrix' "destination" space.

E.g. if you have a bounding box in model space 'modelBox', and a 'modelView' matrix, the operation

modelBox.transform(modelView)

would transform the bounding box into view space.

Member Data Documentation

◆ pmax

point Math::bbox::pmax

◆ pmin

point Math::bbox::pmin

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