Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::Box< T > Class Template Reference

Math class that represents a three dimensional box. More...

Public Member Functions

 Box (T Width, T Height, T Depth)
 Constructs a Box object from its width, height and depth. More...
 
 Box (T X, T Y, T Z, T Width, T Height, T Depth)
 Constructs a Rect<T> object from its position, width, height and depth. More...
 
 Box (const T box[6])
 Constructs a Box object from an array of six elements. More...
 
 Box (const Rect< T > &rect)
 Constructs a Box object from a Rect. More...
 
 Box (const Vector3< T > &lengths)
 Constructs a Box object from a vector representing width, height and depth. More...
 
 Box (const Vector3< T > &vec1, const Vector3< T > &vec2)
 Constructs a Box object from two vectors representing point of the space (X, Y, Z) will be the components minimum of the two vectors and the (width, height, depth) will be the components maximum - minimum. More...
 
template<typename U >
 Box (const Box< U > &box)
 Constructs a Box object from another type of Box. More...
 
 Box (const Box &box)=default
 
bool Contains (T X, T Y, T Z) const
 Tests whether the box contains the provided point inclusive of the edge of the box. More...
 
bool Contains (const Box &box) const
 Tests whether the box contains the provided box inclusive of the edge of the box. More...
 
bool Contains (const Vector3< T > &point) const
 Tests whether the box contains the provided point inclusive of the edge of the box. More...
 
BoxExtendTo (T X, T Y, T Z)
 Extends the box to contain the point in the boundary. More...
 
BoxExtendTo (const Box &box)
 Extends the box to contain the box. More...
 
BoxExtendTo (const Vector3< T > &point)
 Extends the box to contain the point in the boundary. More...
 
Sphere< T > GetBoundingSphere () const
 Gets the bounding sphere for the box. More...
 
Vector3< T > GetCenter () const
 Gets a Vector3 for the center. More...
 
Vector3< T > GetCorner (BoxCorner corner) const
 Gets the Vector3 for the corner. More...
 
Vector3< T > GetLengths () const
 Gets a Vector3 for the lengths. More...
 
Vector3< T > GetMaximum () const
 Gets a Vector3 for the maximum point. More...
 
Vector3< T > GetMinimum () const
 Gets a Vector3 for the minimum point. More...
 
Vector3< T > GetNegativeVertex (const Vector3< T > &normal) const
 Computes the negative vertex of one direction. More...
 
Vector3< T > GetPosition () const
 Gets a Vector3 for the position. More...
 
Vector3< T > GetPositiveVertex (const Vector3< T > &normal) const
 Computes the positive vertex of one direction. More...
 
GetRadius () const
 Gets the radius of the box. More...
 
Sphere< T > GetSquaredBoundingSphere () const
 Gets the squared bounding sphere for the box. More...
 
GetSquaredRadius () const
 Gets the squared radius of the box. More...
 
bool Intersect (const Box &box, Box *intersection=nullptr) const
 Checks whether or not this box intersects another one. More...
 
bool IsValid () const
 Checks whether this box is valid. More...
 
BoxMakeZero ()
 Makes the box position (0, 0, 0) and lengths (0, 0, 0) More...
 
BoxSet (T Width, T Height, T Depth)
 Sets the components of the box with width, height and depth. More...
 
BoxSet (T X, T Y, T Z, T Width, T Height, T Depth)
 Constructs a Box object from its position and sizes. More...
 
BoxSet (const T box[6])
 Sets the components of the box from an array of six elements. More...
 
BoxSet (const Box &box)
 Sets the components of the box with components from another. More...
 
BoxSet (const Rect< T > &rect)
 Sets the components of the box with components from a Rect. More...
 
BoxSet (const Vector3< T > &lengths)
 Sets the components of the box from a vector representing width, height and depth. More...
 
BoxSet (const Vector3< T > &vec1, const Vector3< T > &vec2)
 Sets the components of the box from two vectors representing point of the space (X, Y, Z) will be the components minimum of the two vectors and the (width, height, depth) will be the components maximum - minimum. More...
 
template<typename U >
BoxSet (const Box< U > &box)
 
String ToString () const
 Gives a string representation. More...
 
BoxTransform (const Matrix4< T > &matrix, bool applyTranslation=true)
 Transforms the box according to the matrix. More...
 
BoxTranslate (const Vector3< T > &translation)
 Translates the box. More...
 
T & operator[] (std::size_t i)
 Returns the ith element of the box. More...
 
operator[] (std::size_t i) const
 Returns the ith element of the box. More...
 
Box operator* (T scalar) const
 Multiplies the lengths with the scalar. More...
 
Box operator* (const Vector3< T > &vec) const
 Multiplies the lengths with the vector. More...
 
Boxoperator= (const Box &other)=default
 
Boxoperator*= (T scalar)
 Multiplies the lengths of this box with the scalar. More...
 
Boxoperator*= (const Vector3< T > &vec)
 Multiplies the lengths of this box with the vector. More...
 
bool operator== (const Box &box) const
 Compares the box to other one. More...
 
bool operator!= (const Box &box) const
 Compares the box to other one. More...
 
template<typename U >
Box< T > & Set (const Box< U > &box)
 Sets the components of the box from another type of Box. More...
 

Static Public Member Functions

static Box Lerp (const Box &from, const Box &to, T interpolation)
 Interpolates the box to other one with a factor of interpolation. More...
 
static Box Zero ()
 Shorthand for the box (0, 0, 0, 0, 0, 0) More...
 

Public Attributes

x
 
y
 
z
 
width
 
height
 
depth
 

Detailed Description

template<typename T>
class Nz::Box< T >

Math class that represents a three dimensional box.

Constructor & Destructor Documentation

◆ Box() [1/7]

template<typename T>
Nz::Box< T >::Box ( Width,
Height,
Depth 
)

Constructs a Box object from its width, height and depth.

Parameters
WidthWidth of the box (following X)
HeightHeight of the box (following Y)
DepthDepth of the box (following Z)
Remarks
Position will be (0, 0, 0)

◆ Box() [2/7]

template<typename T>
Nz::Box< T >::Box ( X,
Y,
Z,
Width,
Height,
Depth 
)

Constructs a Rect<T> object from its position, width, height and depth.

Parameters
XX position
YY position
ZZ position
WidthWidth of the box (following X)
HeightHeight of the box (following Y)
DepthDepth of the box (following Z)

◆ Box() [3/7]

template<typename T>
Nz::Box< T >::Box ( const T  vec[6])

Constructs a Box object from an array of six elements.

Parameters
vec[6]vec[0] is X position, vec[1] is Y position, vec[2] is Z position, vec[3] is width, vec[4] is height and vec[5] is depth

◆ Box() [4/7]

template<typename T>
Nz::Box< T >::Box ( const Rect< T > &  rect)

Constructs a Box object from a Rect.

Parameters
rectRectangle which describes (X, Y) position and (width, height) lenghts
Remarks
Z position is 0 and depth is 1

◆ Box() [5/7]

template<typename T>
Nz::Box< T >::Box ( const Vector3< T > &  lengths)

Constructs a Box object from a vector representing width, height and depth.

Parameters
lengths(Width, Height, Depth) of the box
Remarks
Positions will be (0, 0, 0)

◆ Box() [6/7]

template<typename T>
Nz::Box< T >::Box ( const Vector3< T > &  vec1,
const Vector3< T > &  vec2 
)

Constructs a Box object from two vectors representing point of the space (X, Y, Z) will be the components minimum of the two vectors and the (width, height, depth) will be the components maximum - minimum.

Parameters
vec1First point
vec2Second point

◆ Box() [7/7]

template<typename T >
template<typename U >
Nz::Box< T >::Box ( const Box< U > &  box)
explicit

Constructs a Box object from another type of Box.

Parameters
boxBox of type U to convert to type T

Member Function Documentation

◆ Contains() [1/3]

template<typename T>
bool Nz::Box< T >::Contains ( X,
Y,
Z 
) const

Tests whether the box contains the provided point inclusive of the edge of the box.

Returns
true if inclusive
Parameters
XX position of the point
YY position of the point
ZZ position of the point
See also
Contains

◆ Contains() [2/3]

template<typename T>
bool Nz::Box< T >::Contains ( const Box< T > &  box) const

Tests whether the box contains the provided box inclusive of the edge of the box.

Returns
true if inclusive
Parameters
boxOther box to test
See also
Contains

◆ Contains() [3/3]

template<typename T>
bool Nz::Box< T >::Contains ( const Vector3< T > &  point) const

Tests whether the box contains the provided point inclusive of the edge of the box.

Returns
true if inclusive
Parameters
pointPosition of the point
See also
Contains

◆ ExtendTo() [1/3]

template<typename T>
Box< T > & Nz::Box< T >::ExtendTo ( X,
Y,
Z 
)

Extends the box to contain the point in the boundary.

Returns
A reference to this box extended
Parameters
XX position of the point
YY position of the point
ZZ position of the point
See also
ExtendTo

◆ ExtendTo() [2/3]

template<typename T>
Box< T > & Nz::Box< T >::ExtendTo ( const Box< T > &  box)

Extends the box to contain the box.

Returns
A reference to this box extended
Parameters
boxOther box to contain
See also
ExtendTo

◆ ExtendTo() [3/3]

template<typename T>
Box< T > & Nz::Box< T >::ExtendTo ( const Vector3< T > &  point)

Extends the box to contain the point in the boundary.

Returns
A reference to this box extended
Parameters
pointPosition of the point
See also
ExtendTo

◆ GetBoundingSphere()

template<typename T >
Sphere< T > Nz::Box< T >::GetBoundingSphere ( ) const

Gets the bounding sphere for the box.

Returns
A sphere containing the box
See also
GetSquaredBoundingSphere

◆ GetCenter()

template<typename T >
Vector3< T > Nz::Box< T >::GetCenter ( ) const

Gets a Vector3 for the center.

Returns
The position of the center of the box

◆ GetCorner()

template<typename T >
Vector3< T > Nz::Box< T >::GetCorner ( BoxCorner  corner) const

Gets the Vector3 for the corner.

Returns
The position of the corner of the box according to enum BoxCorner
Parameters
cornerEnumeration of type BoxCorner
Remarks
If enumeration is not defined in BoxCorner, a NazaraError is thrown and a Vector3 uninitialised is returned

◆ GetLengths()

template<typename T >
Vector3< T > Nz::Box< T >::GetLengths ( ) const

Gets a Vector3 for the lengths.

Returns
The lengths of the box (width, height, depth)

◆ GetMaximum()

template<typename T >
Vector3< T > Nz::Box< T >::GetMaximum ( ) const

Gets a Vector3 for the maximum point.

Returns
The BoxCorner_NearRightTop of the box
See also
GetCorner

◆ GetMinimum()

template<typename T >
Vector3< T > Nz::Box< T >::GetMinimum ( ) const

Gets a Vector3 for the minimum point.

Returns
The BoxCorner_FarLeftBottom of the box
See also
GetCorner, GetPosition

◆ GetNegativeVertex()

template<typename T>
Vector3< T > Nz::Box< T >::GetNegativeVertex ( const Vector3< T > &  normal) const

Computes the negative vertex of one direction.

Returns
The position of the vertex on the box in the opposite way of the normal while considering the center. It means that if the normal has one component negative, the component is set to width, height or depth corresponding to the sign
Parameters
normalVector indicating a direction
See also
GetPositiveVertex

◆ GetPosition()

template<typename T >
Vector3< T > Nz::Box< T >::GetPosition ( ) const

Gets a Vector3 for the position.

Returns
The BoxCorner_FarLeftBottom of the box
See also
GetCorner, GetMinimum

◆ GetPositiveVertex()

template<typename T>
Vector3< T > Nz::Box< T >::GetPositiveVertex ( const Vector3< T > &  normal) const

Computes the positive vertex of one direction.

Returns
The position of the vertex on the box in the same way of the normal while considering the center. It means that if the normal has one component positive, the component is set to width or height corresponding to the sign
Parameters
normalVector indicating a direction
See also
GetNegativeVertex

◆ GetRadius()

template<typename T >
T Nz::Box< T >::GetRadius ( ) const

Gets the radius of the box.

Returns
Value of the radius which is the biggest distance between a corner and the center

◆ GetSquaredBoundingSphere()

template<typename T >
Sphere< T > Nz::Box< T >::GetSquaredBoundingSphere ( ) const

Gets the squared bounding sphere for the box.

Returns
A sphere containing the box
See also
GetBoundingSphere

◆ GetSquaredRadius()

template<typename T >
T Nz::Box< T >::GetSquaredRadius ( ) const

Gets the squared radius of the box.

Returns
Value of the squared radius which is the squared of biggest distance between a corner and the center

◆ Intersect()

template<typename T >
bool Nz::Box< T >::Intersect ( const Box< T > &  box,
Box< T > *  intersection = nullptr 
) const

Checks whether or not this box intersects another one.

Returns
true if the box intersects
Parameters
boxBox to check
intersectionOptional argument for the box which represent the intersection

◆ IsValid()

template<typename T >
bool Nz::Box< T >::IsValid ( ) const

Checks whether this box is valid.

Returns
true if the box has a strictly positive width, height and depth

◆ Lerp()

template<typename T>
Box< T > Nz::Box< T >::Lerp ( const Box< T > &  from,
const Box< T > &  to,
interpolation 
)
static

Interpolates the box to other one with a factor of interpolation.

Returns
A new box which is the interpolation of two rectangles
Parameters
fromInitial box
toTarget box
interpolationFactor of interpolation
Remarks
interpolation is meant to be between 0 and 1, other values are potentially undefined behavior
With NAZARA_DEBUG, a NazaraError is thrown and Zero() is returned
See also
Lerp

◆ MakeZero()

template<typename T >
Box< T > & Nz::Box< T >::MakeZero ( )

Makes the box position (0, 0, 0) and lengths (0, 0, 0)

Returns
A reference to this box with position (0, 0, 0) and lengths (0, 0, 0)
See also
Zero

◆ operator!=()

template<typename T >
bool Nz::Box< T >::operator!= ( const Box< T > &  box) const

Compares the box to other one.

Returns
false if the boxes are the same
Parameters
boxOther box to compare with

◆ operator*() [1/2]

template<typename T>
Box< T > Nz::Box< T >::operator* ( scalar) const

Multiplies the lengths with the scalar.

Returns
A box where the position is the same and width, height and depth are the product of the old width, height and depth and the scalar
Parameters
scalarThe scalar to multiply width, height and depth with

◆ operator*() [2/2]

template<typename T>
Box< T > Nz::Box< T >::operator* ( const Vector3< T > &  vec) const

Multiplies the lengths with the vector.

Returns
A box where the position is the same and width, height and depth are the product of the old width, height and depth with the vec
Parameters
vecThe vector where component one multiply width, two height and three depth

◆ operator*=() [1/2]

template<typename T>
Box< T > & Nz::Box< T >::operator*= ( scalar)

Multiplies the lengths of this box with the scalar.

Returns
A reference to this box where lengths are the product of these lengths and the scalar
Parameters
scalarThe scalar to multiply width, height and depth with

◆ operator*=() [2/2]

template<typename T>
Box< T > & Nz::Box< T >::operator*= ( const Vector3< T > &  vec)

Multiplies the lengths of this box with the vector.

Returns
A reference to this box where width, height and depth are the product of the old width, height and depth with the vec
Parameters
vecThe vector where component one multiply width, two height and three depth

◆ operator==()

template<typename T >
bool Nz::Box< T >::operator== ( const Box< T > &  box) const

Compares the box to other one.

Returns
true if the boxes are the same
Parameters
boxOther box to compare with

◆ operator[]() [1/2]

template<typename T >
T & Nz::Box< T >::operator[] ( std::size_t  i)

Returns the ith element of the box.

Returns
A reference to the ith element of the box
Remarks
Access to index greater than 6 is undefined behavior
Produce a NazaraError if you try to access to index greater than 6 with NAZARA_MATH_SAFE defined
Exceptions
std::domain_errorif NAZARA_MATH_SAFE is defined and one of you try to acces to index greather than 6

◆ operator[]() [2/2]

template<typename T >
T Nz::Box< T >::operator[] ( std::size_t  i) const

Returns the ith element of the box.

Returns
A value to the ith element of the box
Remarks
Access to index greater than 6 is undefined behavior
Produce a NazaraError if you try to access to index greater than 6 with NAZARA_MATH_SAFE defined
Exceptions
std::domain_errorif NAZARA_MATH_SAFE is defined and one of you try to acces to index greather than 6

◆ Set() [1/8]

template<typename T>
Box< T > & Nz::Box< T >::Set ( Width,
Height,
Depth 
)

Sets the components of the box with width, height and depth.

Returns
A reference to this box
Parameters
WidthWidth of the box (following X)
HeightHeight of the box (following Y)
DepthDepth of the box (following Z)
Remarks
Position will be (0, 0, 0)

◆ Set() [2/8]

template<typename T>
Box< T > & Nz::Box< T >::Set ( X,
Y,
Z,
Width,
Height,
Depth 
)

Constructs a Box object from its position and sizes.

Parameters
XX component of position
YY component of position
ZZ component of position
WidthWidth of the box (following X)
HeightHeight of the box (following Y)
DepthDepth of the box (following Z)

◆ Set() [3/8]

template<typename T>
Box< T > & Nz::Box< T >::Set ( const T  box[6])

Sets the components of the box from an array of six elements.

Returns
A reference to this box
Parameters
box[6]box[0] is X position, box[1] is Y position, box[2] is Z position, box[3] is width, box[4] is height and box[5] is depth

◆ Set() [4/8]

template<typename T>
Box< T > & Nz::Box< T >::Set ( const Box< T > &  box)

Sets the components of the box with components from another.

Returns
A reference to this box
Parameters
boxThe other box

◆ Set() [5/8]

template<typename T>
Box< T > & Nz::Box< T >::Set ( const Rect< T > &  rect)

Sets the components of the box with components from a Rect.

Returns
A reference to this box
Parameters
rectRectangle which describes (X, Y) position and (width, height) lenghts
Remarks
Z position is 0 and depth is 1

◆ Set() [6/8]

template<typename T>
Box< T > & Nz::Box< T >::Set ( const Vector3< T > &  lengths)

Sets the components of the box from a vector representing width, height and depth.

Returns
A reference to this box
Parameters
lengths(Width, Height, depth) of the box
Remarks
Position will be (0, 0, 0)

◆ Set() [7/8]

template<typename T>
Box< T > & Nz::Box< T >::Set ( const Vector3< T > &  vec1,
const Vector3< T > &  vec2 
)

Sets the components of the box from two vectors representing point of the space (X, Y, Z) will be the components minimum of the two vectors and the (width, height, depth) will be the components maximum - minimum.

Returns
A reference to this box
Parameters
vec1First point
vec2Second point

◆ Set() [8/8]

template<typename T>
template<typename U >
Box<T>& Nz::Box< T >::Set ( const Box< U > &  box)

Sets the components of the box from another type of Box.

Returns
A reference to this box
Parameters
boxBox of type U to convert its components

◆ ToString()

template<typename T >
String Nz::Box< T >::ToString ( ) const

Gives a string representation.

Returns
A string representation of the object: "Box(x, y, z, width, height, depth)"

◆ Transform()

template<typename T>
Box< T > & Nz::Box< T >::Transform ( const Matrix4< T > &  matrix,
bool  applyTranslation = true 
)

Transforms the box according to the matrix.

Returns
A reference to this box transformed
Parameters
matrixMatrix4 representing the transformation
applyTranslationShould transform the position or the direction

◆ Translate()

template<typename T>
Box< T > & Nz::Box< T >::Translate ( const Vector3< T > &  translation)

Translates the box.

Returns
A reference to this box translated
Parameters
translationVector3 which is the translation for the position

◆ Zero()

template<typename T >
Box< T > Nz::Box< T >::Zero ( )
static

Shorthand for the box (0, 0, 0, 0, 0, 0)

Returns
A box with position (0, 0, 0) and lengths (0, 0, 0)
See also
MakeZero

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