3DRadSpace 0.1.0Alpha
3DRadSpace is a free, simple to use, rapid application development game engine.
Loading...
Searching...
No Matches
Engine3DRadSpace.Math.BoundingBox Struct Reference

Represents a axis aligned bounding box in 3D space defined by position and scale. More...

#include <BoundingBox.hpp>

Collaboration diagram for Engine3DRadSpace.Math.BoundingBox:

Public Member Functions

 BoundingBox (Vector3 p, Vector3 s)
 BoundingBox ()=default
 Creates a null bounding box.
 BoundingBox (const Vector3 &pos, const Vector3 &scale)
 Creates a bounding box from position and scale.
 BoundingBox (const BoundingSphere &sphere)
 Create a bounding box that contains the given bounding sphere.
 BoundingBox (const BoundingBox &box1, const BoundingBox &box2)
 Creates a bounding box that contains both given bounding boxes.
 BoundingBox (const BoundingBox &box, const BoundingSphere &sphere)
 Creates a bounding box that contains the given bounding box and bounding sphere.
 BoundingBox (const BoundingSphere &sph1, const BoundingSphere &sph2)
 Creates a bounding box that contains both given bounding spheres.
Vector3 Min () const noexcept
 Minimal point.
Vector3 Center () const noexcept
 Returns the center of the bounding box.
Vector3 Max () const noexcept
 Returns the maximal point.
bool Intersects (const BoundingBox &box) const noexcept
 Does this intersect with the given bounding box?
bool Intersects (const BoundingSphere &sphere) const noexcept
 Does this intersect with the given bounding sphere?
bool Intersects (const BoundingPlane &plane) const noexcept
 Does this intersect with the given bounding plane?
bool Intersects (const Ray &ray) const noexcept
 Does this intersect with the given ray?
bool Contains (const Vector3 &p) const noexcept
 Is p inside this bounding box?
Vector3 operator[] (int i) const
 Returns a corner of this BoundingBox.
BoundingBox Transform (const Matrix4x4 &m) const noexcept
 Returns the smallest axis-aligned BoundingBox that contains this BoundingBox after being transformed by m.

Public Attributes

Vector3 Position
 Minimal point of the bounding box.
Vector3 Scale
 Abs(Max-Min). All components need to be positive.

Detailed Description

Represents a axis aligned bounding box in 3D space defined by position and scale.

This bounding box has the boundaries specified as (Position, Position + Scale). The scale should be positive in all coordinates.

Constructor & Destructor Documentation

◆ BoundingBox() [1/7]

Engine3DRadSpace.Math.BoundingBox.BoundingBox ( Vector3 p,
Vector3 s )
inline

◆ BoundingBox() [2/7]

Creates a null bounding box.

◆ BoundingBox() [3/7]

BoundingBox::BoundingBox ( const Vector3 & pos,
const Vector3 & scale )

Creates a bounding box from position and scale.

Parameters
posPosition.
scaleScale. Every coordinate should be positive.

◆ BoundingBox() [4/7]

BoundingBox::BoundingBox ( const BoundingSphere & sphere)
explicit

Create a bounding box that contains the given bounding sphere.

Parameters
sphereBounding sphere

◆ BoundingBox() [5/7]

BoundingBox::BoundingBox ( const BoundingBox & box1,
const BoundingBox & box2 )

Creates a bounding box that contains both given bounding boxes.

Parameters
box1First
box2Second

◆ BoundingBox() [6/7]

BoundingBox::BoundingBox ( const BoundingBox & box,
const BoundingSphere & sphere )

Creates a bounding box that contains the given bounding box and bounding sphere.

Parameters
boxBox.
sphereSphere.

◆ BoundingBox() [7/7]

BoundingBox::BoundingBox ( const BoundingSphere & sph1,
const BoundingSphere & sph2 )

Creates a bounding box that contains both given bounding spheres.

Parameters
sph1Sphere.
sph2Sphere.

Member Function Documentation

◆ Center()

Vector3 BoundingBox::Center ( ) const
noexcept

Returns the center of the bounding box.

Returns
Position + (Scale / 2).

◆ Contains()

bool BoundingBox::Contains ( const Vector3 & p) const
noexcept

Is p inside this bounding box?

Parameters
pPoint p
Returns
True if p is inside this BoundingBox. false otherwise.

◆ Intersects() [1/4]

bool BoundingBox::Intersects ( const BoundingBox & box) const
noexcept

Does this intersect with the given bounding box?

Parameters
boxThe bounding box to test for intersection
Returns
True if this bounding box intersects with the given bounding box, false otherwise.

◆ Intersects() [2/4]

bool BoundingBox::Intersects ( const BoundingPlane & plane) const
noexcept

Does this intersect with the given bounding plane?

Parameters
planeThe bounding plane to test for intersection
Returns
True if this bounding box intersects with the given bounding plane, false otherwise.

◆ Intersects() [3/4]

bool BoundingBox::Intersects ( const BoundingSphere & sphere) const
noexcept

Does this intersect with the given bounding sphere?

Parameters
sphereThe bounding sphere to test for intersection
Returns
True if this bounding box intersects with the given bounding sphere, false otherwise.

◆ Intersects() [4/4]

bool BoundingBox::Intersects ( const Ray & ray) const
noexcept

Does this intersect with the given ray?

Parameters
rayThe ray to test for intersection
Returns
True if this bounding box intersects with the given ray, false otherwise.

◆ Max()

Vector3 BoundingBox::Max ( ) const
noexcept

Returns the maximal point.

Returns
Position + Scale.

◆ Min()

Vector3 BoundingBox::Min ( ) const
noexcept

Minimal point.

Returns
Returns Position

◆ operator[]()

Vector3 BoundingBox::operator[] ( int i) const

Returns a corner of this BoundingBox.

Parameters
iRanged from 0 to 7.
Returns
A corner of this BoundingBox.

0: Min 1: (Max.X, Min.Y, Min.Z) 2: (Min.X, Max.Y, Min.Z) 3: (Min.X, Min.Y, Max.Z) 4: (Max.X, Max.Y, Min.Z) 5: (Max.X, Min.Y, Max.Z) 6: (Min.X, Max.Y, Max.Z) 7: Max

◆ Transform()

BoundingBox BoundingBox::Transform ( const Matrix4x4 & m) const
noexcept

Returns the smallest axis-aligned BoundingBox that contains this BoundingBox after being transformed by m.

Parameters
mTransformation matrix (translation, rotation and/or scale).
Returns
A new, axis-aligned BoundingBox that fully contains the transformed box.

Unlike transforming Position and Scale directly, this correctly accounts for rotation by re-deriving the axis-aligned extents from the transformed center/half-extents, guaranteeing the result always contains every corner of the original box.

Member Data Documentation

◆ Position

Vector3 Engine3DRadSpace.Math.BoundingBox.Position

Minimal point of the bounding box.

◆ Scale

Vector3 Engine3DRadSpace.Math.BoundingBox.Scale

Abs(Max-Min). All components need to be positive.


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