Ocular Engine
Ocular::Math::BoundsAABB Class Reference

#include <BoundsAABB.hpp>

Inheritance diagram for Ocular::Math::BoundsAABB:
Ocular::Math::Bounds

Public Member Functions

 BoundsAABB (std::list< Point3f > const &points, Math::Matrix4x4 const &matrix=Math::Matrix4x4())
 
 BoundsAABB (std::vector< Graphics::Vertex > const &vertices, Math::Matrix4x4 const &matrix=Math::Matrix4x4())
 
 BoundsAABB (Vector3f const &center, Vector3f const &extents)
 
void construct (std::list< Point3f > const &points, Math::Matrix4x4 const &matrix=Math::Matrix4x4())
 
void construct (std::vector< Graphics::Vertex > const &vertices, Math::Matrix4x4 const &matrix=Math::Matrix4x4())
 
void setCenter (Vector3f const &center)
 
void setExtents (Vector3f const &extents)
 
Vector3f const & getCenter () const
 
Vector3f const & getExtents () const
 
Vector3f const & getMinPoint () const
 
Vector3f const & getMaxPoint () const
 
void expand (Vector3f const &modifier)
 
void expandToContain (Vector3f const &point)
 
void expandToContain (BoundsAABB const &bounds)
 
bool intersects (Ray const &ray) const
 
bool intersects (Ray const &ray, Point3f &point, float &distance) const
 
bool intersects (BoundsSphere const &bounds) const
 
bool intersects (BoundsAABB const &bounds) const
 
bool intersects (BoundsOBB const &bounds) const
 
bool intersects (Plane const &plane, IntersectionType *result=nullptr) const
 
bool contains (Vector3f const &point, IntersectionType *result=nullptr) const
 
bool contains (BoundsAABB const &bounds, IntersectionType *result=nullptr) const
 
- Public Member Functions inherited from Ocular::Math::Bounds
BoundsType getType () const
 
bool isVisible () const
 
void setVisible (bool visible)
 

Protected Member Functions

void calculateMinMaxPoints ()
 
- Protected Member Functions inherited from Ocular::Math::Bounds
 Bounds (BoundsType const type)
 

Additional Inherited Members

- Protected Attributes inherited from Ocular::Math::Bounds
bool m_Visible
 
BoundsType m_Type
 

Detailed Description

Implementation of an Axis Aligned Bounding Box.

As per it's name, an AABB is always aligned according to the world axis and thus can never rotate. Instead, when the object it contains is rotated, the AABB must be recalculated.

Intersection testing with AABBs is very fast, but can be fairly inaccurate, and thus they are typically used for first pass tests of culling and collision tests.

To perform an intersection test see the Ocular::Math::Intersects functions.

Constructor & Destructor Documentation

Ocular::Math::BoundsAABB::BoundsAABB ( std::list< Point3f > const &  points,
Math::Matrix4x4 const &  matrix = Math::Matrix4x4() 
)

Creates a new AABB from a list of spatial points.

Parameters
[in]points
Ocular::Math::BoundsAABB::BoundsAABB ( Vector3f const &  center,
Vector3f const &  extents 
)

Creates a new AABB with the specified parameters.

Parameters
[in]centerCenter position of the AABB
[in]extentsExtents along each axis from the center. So an extents of (5.0, 5.0, 5.0) would result in a 10x10x10 AABB.

Member Function Documentation

void Ocular::Math::BoundsAABB::construct ( std::list< Point3f > const &  points,
Math::Matrix4x4 const &  matrix = Math::Matrix4x4() 
)

Constructs the bounds from a collection of spatial points.

Parameters
[in]points
bool Ocular::Math::BoundsAABB::contains ( Vector3f const &  point,
IntersectionType *  result = nullptr 
) const

Calculates if the bounds contains the specified point.

To test for just intersection, see the series of Ocular::Math::Intersects functions.

Parameters
[in]point
[out]resultThe exact result of the containment test (intersection, outside, inside).
Returns
TRUE if point is inside or intersects.
bool Ocular::Math::BoundsAABB::contains ( BoundsAABB const &  bounds,
IntersectionType *  result = nullptr 
) const

Calculates if any portion of the specified bounds is contained within the AABB.

To test for just intersection, see the series of Ocular::Math::Intersects functions.

Parameters
[in]bounds
[out]resultThe exact result of the containment test (intersection, outside, inside).
Returns
TRUE if bounds is inside or intersects.
void Ocular::Math::BoundsAABB::expand ( Vector3f const &  modifier)

Linearly modifies the extents according to the specified values.

If positie modifiers are given, then the box will expand outward. If negative modifiers are given, then the box will shrink inward.

The extents can not be negative and thus will be clamped to 0.0 if necessary.

Parameters
[in]modifier
void Ocular::Math::BoundsAABB::expandToContain ( Vector3f const &  point)

Expands the bounding box so that it contains the specified point. If the box already contains the point, then no action will be taken.

Parameters
[in]point
void Ocular::Math::BoundsAABB::expandToContain ( BoundsAABB const &  bounds)

Expands the bounding box so that it contains the specified bounds. If the box already fully contains the bounds, then no action will be taken.

Parameters
[in]point
Vector3f const & Ocular::Math::BoundsAABB::getCenter ( ) const
Returns
The center point of the bounding box.
Vector3f const & Ocular::Math::BoundsAABB::getExtents ( ) const
Returns
The extents (side half-lenths) of the bounding box.
Vector3f const & Ocular::Math::BoundsAABB::getMaxPoint ( ) const
Returns
The largest point furthest from the center that is contained within the box.
Vector3f const & Ocular::Math::BoundsAABB::getMinPoint ( ) const
Returns
The smallest point furthest from the center that is contained within the box.
bool Ocular::Math::BoundsAABB::intersects ( Ray const &  ray) const

Performs an intersection test on a ray and AABB.

Parameters
[in]ray
Returns
TRUE if the ray and AABB intersect.
bool Ocular::Math::BoundsAABB::intersects ( Ray const &  ray,
Point3f point,
float &  distance 
) const

Performs an intersection test on a ray and AABB.

This version of the method also returns the point at which the two intersect. If speed is of the uptmost concern and/or the exact point of intersection is not required, then the other version may be used instead.

Parameters
[in]ray
[out]pointThe point that the ray and AABB intersect, if they intersect.
[out]distanceThe distance from the ray origin to the point of intersection
Returns
TRUE if the ray and AABB intersect.
bool Ocular::Math::BoundsAABB::intersects ( BoundsSphere const &  bounds) const

Performs an intersection test on a bounding sphere and AABB.

Parameters
[in]bounds
Returns
TRUE if the bounding sphere and AABB intersect.
bool Ocular::Math::BoundsAABB::intersects ( BoundsAABB const &  bounds) const

Performs an intersection test on two AABBs.

Parameters
[in]bounds
Returns
TRUE if the two AABBs intersect.
bool Ocular::Math::BoundsAABB::intersects ( BoundsOBB const &  bounds) const

Performs an intersection test on a AABB and OBB.

Parameters
[in]bounds
Returns
TRUE if the bounding sphere and OBB intersect.
bool Ocular::Math::BoundsAABB::intersects ( Plane const &  plane,
IntersectionType *  result = nullptr 
) const

Performs an intersection test on a plane and AABB.

If the result is Inside, then the AABB is located entirely within the plane's positive half space.
If the result is Outside, then the AABB is located entirely outside the plane's positive half space.

The positive half space of the plane is the direction that the plane is facing, as described by it's normal.

As an example, say we have the plane defined as:

 Point: (0.0, 0.0, 0.0)
Normal: (0.0, 1.0, 0.0)

The plane is 'facing up' along the world origin.

If the intersection test returns Outside, then the AABB is entirely in the +y world space.
If the intersection test returns Inside, then the AABB is entirely in the -y world space.

Parameters
[in]plane
[out]resultDetailed intersection result.
Returns
TRUE if the plane and AABB intersects, otherwise FALSE.
void Ocular::Math::BoundsAABB::setCenter ( Vector3f const &  center)

Sets the center point of the bounding box.

The minimum and maximum points will be automatically updated to take into account the new center.

Parameters
[in]center
void Ocular::Math::BoundsAABB::setExtents ( Vector3f const &  extents)

Sets the positive half-lengths of the bounding box sides.

The minimum and maximum points will be automatically updated to take into account the new extents.

Parameters
[in]extents

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