AxisAlignedBoundingBox Class Reference


Detailed Description

Represents a bounding box whose axes are aligned with the coordinate system.

The box is usually referred by two corners, the start corner means the one whose coordinates are the smallest, while the end corner means the opposite.

Examples:

CurveBrush/CurveCreator.h, FixedFunctionMaterial/FixedFunctionMaterial.h, ImmediateModeRenderer/ImmediateModeRenderer.h, and ToonMaterial/ToonMaterial.h.

Definition at line 816 of file math.h.

#include <math.h>

List of all members.

Public Member Functions

  AxisAlignedBoundingBox (void)
  Creates an empty bounding box.
  AxisAlignedBoundingBox (const Vector &vStart, const Vector &vEnd)
  Creates an object by specifying two corners of the box.
  AxisAlignedBoundingBox (const Vector &vCenter, float fSize)
  Creates an object by specifying the center of it and the distance of the sides from the center.
  AxisAlignedBoundingBox (const AxisAlignedBoundingBox &cA)
  Creates an object by cloning another one.
AxisAlignedBoundingBox operator= (const AxisAlignedBoundingBox &cBB)
  Assigns the value of a box object to another one.
AxisAlignedBoundingBox operator+= (const AxisAlignedBoundingBox &cBB)
  Extends the box to contain another one.
bool  operator== (const AxisAlignedBoundingBox &cBB) const
  Returns true if two boxes are identical, false otherwise.
void  Reset (void)
  Makes the box empty.
void  Serialize (Stream &s)
  Writes/reads the object data to/from a stream.
bool  operator!= (const AxisAlignedBoundingBox &cBox) const
  returns true if the two boxes are different, false otherwise.
void  Extend (const Vector &)
  Extends the box to contain the passed point.
void  Extend (const AxisAlignedBoundingBox &bb)
  Extends the box to contain another one.
void  Transform (const class Matrix &mMatrix)
  Transforms the box with the passed-in matrix, and returns the smallest box which contains the result.
Vector  operator[] (int iCornerIndex) const
  Returns the corners of the box. Valid indexes are 0-7.
float  Size (void) const
  Returns the maximum edge length of the box.
float  XSize (void) const
  Returns the length of the box along the X axis.
float  YSize (void) const
  Returns the length of the box along the Y axis.
float  ZSize (void) const
  Returns the length of the box along the Y axis.
float  Volume (void) const
  Returns the volume of the box.
Vector  Center (void) const
  Returns the center of the box.
bool  IsPartOf (const AxisAlignedBoundingBox &cBB) const
  Returns true if the passed-in box contains this box.
bool  IsTouching (const AxisAlignedBoundingBox &cBB) const
  Returns true if the two boxes intersect at all.
bool  IsTouching (const Vector &vStart, const Vector &vEnd, float &fPlace) const
  Returns true if the box intersects any part of a specified line.
bool  IsContaining (const Vector &cV) const
  Returns true if the box contains the specified point.
bool  IsContaining (const AxisAlignedBoundingBox &b) const
  Returns true if the box contains the specified box.
bool  IsEmpty (void) const
  Returns true if the box is empy.
AxisAlignedBoundingBox  operator* (float fFactor)
  Multiplies the box coordinates with a scalar value.

Public Attributes

Vector  m_vStart
Vector  m_vEnd

Constructor & Destructor Documentation

AxisAlignedBoundingBox ( void  ) [inline]

Creates an empty bounding box.

Definition at line 820 of file math.h.

{ Reset(); };
AxisAlignedBoundingBox ( const Vector vStart,
const Vector vEnd 
) [inline]

Creates an object by specifying two corners of the box.

Definition at line 823 of file math.h.

                                                                       :
        m_vStart( vStart ),
        m_vEnd( vEnd ) {};
AxisAlignedBoundingBox ( const Vector vCenter,
float  fSize 
) [inline]

Creates an object by specifying the center of it and the distance of the sides from the center.

This will be a cube.

Definition at line 829 of file math.h.

    {
        Vector v( fSize, fSize, fSize );
        m_vStart = vCenter-v;
        m_vEnd   = vCenter+v;
    };

Creates an object by cloning another one.

Definition at line 837 of file math.h.

                                                               :
    m_vStart( cA.m_vStart ),
    m_vEnd( cA.m_vEnd ) {};

Member Function Documentation

AxisAlignedBoundingBox& operator= ( const AxisAlignedBoundingBox cBB ) [inline]

Assigns the value of a box object to another one.

Definition at line 842 of file math.h.

    {
        m_vStart = cBB.m_vStart;
        m_vEnd = cBB.m_vEnd;
        return *this;
    };
AxisAlignedBoundingBox& operator+= ( const AxisAlignedBoundingBox cBB ) [inline]

Extends the box to contain another one.

Definition at line 850 of file math.h.

    {
        for ( int i = 0; i < 8; i++ ) Extend( cBB[i] );
        return *this;
    };
bool operator== ( const AxisAlignedBoundingBox cBB ) const [inline]

Returns true if two boxes are identical, false otherwise.

Definition at line 857 of file math.h.

    {
        return m_vStart == cBB.m_vStart && m_vEnd == cBB.m_vEnd;
    };
void Reset ( void  ) [inline]

Makes the box empty.

Definition at line 863 of file math.h.

    {
        m_vStart.Set( 0, 0, 0 );
        m_vEnd.Set( -1, -1, -1 );
    };
void Serialize ( Stream s )

Writes/reads the object data to/from a stream.

bool operator!= ( const AxisAlignedBoundingBox cBox ) const [inline]

returns true if the two boxes are different, false otherwise.

Definition at line 874 of file math.h.

        { return !(operator ==(cBox)); };
void Extend ( const Vector )

Extends the box to contain the passed point.

void Extend ( const AxisAlignedBoundingBox bb ) [inline]

Extends the box to contain another one.

Definition at line 882 of file math.h.

    {
        if ( !bb.IsEmpty() ) {
            Extend( bb.m_vStart );
            Extend( bb.m_vEnd );
        };
    };
void Transform ( const class Matrix mMatrix )

Transforms the box with the passed-in matrix, and returns the smallest box which contains the result.

This is usually larger than the original box, because the transformation might rotate the box out of axis alignment.

Vector operator[] ( int  iCornerIndex ) const

Returns the corners of the box. Valid indexes are 0-7.

float Size ( void  ) const [inline]

Returns the maximum edge length of the box.

Definition at line 901 of file math.h.

{ return Max( Max( XSize(), YSize() ), ZSize() ); };
float XSize ( void  ) const [inline]

Returns the length of the box along the X axis.

Definition at line 904 of file math.h.

{ return m_vEnd.m_fX-m_vStart.m_fX; };
float YSize ( void  ) const [inline]

Returns the length of the box along the Y axis.

Definition at line 907 of file math.h.

{ return m_vEnd.m_fY-m_vStart.m_fY; };
float ZSize ( void  ) const [inline]

Returns the length of the box along the Y axis.

Definition at line 910 of file math.h.

{ return m_vEnd.m_fZ-m_vStart.m_fZ; };
float Volume ( void  ) const [inline]

Returns the volume of the box.

Definition at line 913 of file math.h.

{ return XSize()*YSize()*ZSize(); };
Vector Center ( void  ) const [inline]

Returns the center of the box.

Definition at line 916 of file math.h.

{ return (m_vStart+m_vEnd)*0.5f; };
bool IsPartOf ( const AxisAlignedBoundingBox cBB ) const [inline]

Returns true if the passed-in box contains this box.

Definition at line 919 of file math.h.

    {
        return (
            m_vStart.m_fX >= cBB.m_vStart.m_fX && m_vEnd.m_fX <= cBB.m_vEnd.m_fX &&
            m_vStart.m_fY >= cBB.m_vStart.m_fY && m_vEnd.m_fY <= cBB.m_vEnd.m_fY &&
            m_vStart.m_fZ >= cBB.m_vStart.m_fZ && m_vEnd.m_fZ <= cBB.m_vEnd.m_fZ );
    };
bool IsTouching ( const AxisAlignedBoundingBox cBB ) const [inline]

Returns true if the two boxes intersect at all.

Definition at line 928 of file math.h.

    {
        return (
            m_vStart.m_fX < cBB.m_vEnd.m_fX && m_vEnd.m_fX > cBB.m_vStart.m_fX &&
            m_vStart.m_fY < cBB.m_vEnd.m_fY && m_vEnd.m_fY > cBB.m_vStart.m_fY &&
            m_vStart.m_fZ < cBB.m_vEnd.m_fZ && m_vEnd.m_fZ > cBB.m_vStart.m_fZ );
    };
bool IsTouching ( const Vector vStart,
const Vector vEnd,
float &  fPlace 
) const

Returns true if the box intersects any part of a specified line.

If there is an intersection, then a point guaranteed to be inside the box is returned in the third argument (fPlace). That argument represents a location along the line from vStart to vEnd. (Location = vStart + fPlace*vEnd)

Parameters:
[in] vStart A point (represented as a Vector) defining the start of the line
[in] vEnd A point (represented as a Vector) defining the end of the line
[out] fPlace A number between 0.0 and 1.0, defining a position along the line that is guaranteed to be inside the box (if true was returned).
bool IsContaining ( const Vector cV ) const [inline]

Returns true if the box contains the specified point.

Definition at line 951 of file math.h.

    {
        return (
            m_vStart.m_fX <= cV.m_fX && m_vEnd.m_fX >= cV.m_fX &&
            m_vStart.m_fY <= cV.m_fY && m_vEnd.m_fY >= cV.m_fY &&
            m_vStart.m_fZ <= cV.m_fZ && m_vEnd.m_fZ >= cV.m_fZ );
    };
bool IsContaining ( const AxisAlignedBoundingBox b ) const [inline]

Returns true if the box contains the specified box.

Definition at line 961 of file math.h.

        { return IsContaining( b.m_vStart ) && IsContaining( b.m_vEnd ); };
bool IsEmpty ( void  ) const [inline]

Returns true if the box is empy.

Note that when the start and end corners are equal then the box is not treated as empty.

Definition at line 967 of file math.h.

{ return m_vStart.x > m_vEnd.x; };
AxisAlignedBoundingBox operator* ( float  fFactor ) [inline]

Multiplies the box coordinates with a scalar value.

Definition at line 970 of file math.h.

    {
        return AxisAlignedBoundingBox( m_vStart*fFactor, m_vEnd*fFactor );
    };

Member Data Documentation

Definition at line 976 of file math.h.


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

AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox
AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox AxisAlignedBoundingBox