BoundingSphere

Functions

CID

GetClassID

void *

As

const void *

As

class T_As

As

class T_As

As

BoundingSphere

BoundingSphere

BoundingSphere

BoundingSphere

~BoundingSphere

void

SetCenter

void

SetRadius

RED_RC

Set

RED_RC

Set

RED_RC

Set

RED_RC

Set

RED_RC

Add

RED_RC

Add

RED_RC

Add

RED_RC

Set

RED_RC

Add

const Vector3 &

GetCenter

double

GetRadius

double

GetRadius2

RED_RC

SetAABB

RED_RC

SetAABB

RED_RC

SetAABB

void

GetAABB

bool

IsAABB

Detailed Description

class BoundingSphere : public RED::Object

Standard bounding element of all RED shapes.

@related Shape Attributes in a Scene Graph, class RED::IShape

Shape geometry in space is limited using a bounding sphere, that is a sphere spatially enclosing all shape geometry, or that can be manually defined for any culling purpose. A parent/children hierarchy is kept with the bounding spheres of a DAG. This does not necessarily imply that a parent bounding sphere will contain the spheres of all it’s children, but it implies that a parent bounding sphere will contain it’s children true geometry at least.

A bounding sphere is defined in the space of the shape it’s linked with.

The class can also contain an Axis Aligned Bounding Box information (AABB). This AABB is only informative and it’s not used in any engine calculation. A valid bounding sphere can be automatically setup when filling an AABB information. Unless specified otherwise, any method manipulating the bounding sphere parameters in the class has no effect on the AABB that remain unchanged.

Public Functions

virtual void *As(const RED::CID &iCID)

Converts the object to an instance of the given type.

Parameters

iCID – Requested class.

Returns

An object pointer of the given class on success, NULL otherwise.

virtual const void *As(const RED::CID &iCID) const

Converts the object to an instance of the given type.

Parameters

iCID – Requested class.

Returns

An object pointer of the given class on success, NULL otherwise.

template<class T_As>
inline T_As *As()
template<class T_As>
inline const T_As *As() const
BoundingSphere()

BoundingSphere construction method.

Construct a bounding sphere with a RED_TOL2 radius, located at the shape space origin. No AABB.

BoundingSphere(const RED::Vector3 &iCenter, double iRadius)

BoundingSphere construction method provided a center and a radius.

Coordinates are local to the shape that’ll use this sphere. No AABB.

Parameters
  • iCenterRED::Vector3 center coordinates.

  • iRadius – Radius of the sphere.

BoundingSphere(const RED::Vector<RED::Vector3> &iVertexArray)

BoundingSphere construction method from a list of vertices.

Constructs a bounding sphere that encloses all given vertices. No AABB.

Parameters

iVertexArray – List of vertices to enclose.

BoundingSphere(float *iVertexArray, int iSize)

BoundingSphere construction method from a list of vertices.

Constructs a bounding sphere enclosing the provided vertex array. No AABB.

Parameters
  • iVertexArray – List of vertices (XYZ XYZ XYZ in memory).

  • iSize – Size of iVertexArray in floats (= 3*nb_vertices).

virtual ~BoundingSphere()

BoundingSphere destruction method.

inline void SetCenter(const RED::Vector3 &iCenter)

Sets the center of the bounding sphere.

Parameters

iCenter – New bounding sphere center.

inline void SetRadius(double iRadius)

Sets the radius of the bounding sphere.

Parameters

iRadius – New radius of the bounding sphere.

RED_RC Set(const RED::Vector3 &iCenter, double iRadius)

Sets the bounding sphere according to provided center and radius.

Parameters
  • iCenter – Center coordinates of the sphere.

  • iRadius – Radius to assign to the sphere.

Returns

RED_OK when the assignment succeeded,

RED_BAD_PARAM if the method received an invalid parameter.

RED_RC Set(const RED::Vector<RED::Vector3> &iVertexArray)

Defines a bounding sphere that encloses a list of vertices.

Computes a bounding sphere as small as possible that encloses the given vertex array.

Parameters

iVertexArray – List of vertices to enclose.

Returns

RED_OK when the computation succeeded,

RED_BAD_PARAM if the method received invalid parameters.

RED_RC Set(float *iVertexArray, int iSize)

Defines a bounding sphere that encloses a list of vertices.

Same as RED::BoundingSphere::Set, using 3 floats per vertex.

Parameters
  • iVertexArray – List of vertices (XYZ XYZ XYZ in memory).

  • iSize – Size of iVertexArray in floats (= 3*nb_vertices).

Returns

RED_OK when the computation succeeded,

RED_BAD_PARAM if the method received invalid parameters.

RED_RC Set(const void *iVertexArray, int iVertexSize, RED::MESH_FORMAT iFormat, int iNbVertices)

Defines a bounding sphere that encloses a list of vertices.

This method behaves similarly to all other RED::BoundingSphere::Set methods except that it’s using a more generic format. The iVertexArray parameter can be retrieved from a RED::IMeshShape::GetVertexArray for instance (as well as from a RED::ILineShape or RED::IPointShape

). The method uses the same size and format parameters as the GetVertexArray call does. In addition, the number of vertices has to be supplied.

Note that .w coordinates are ignored for the calculation of 3d

Parameters
  • iVertexArray – The array of vertices.

  • iVertexSize – The number of coordinates for each vertex (1 = x; 2 = xy; 3 = xyz; 4 = xyzw).

  • iFormat – The vertex array format.

  • iNbVertices – The number of vertices to consider.

Returns

RED_OK if the method has succeeded,

RED_BAD_PARAM if the method has received invalid parameters.

RED_RC Add(const RED::Vector<RED::Vector3> &iVertexArray)

Adds new vertex geometry to an already defined bounding sphere.

This method merges the currently defined object bounding sphere with the provided vertices. The result of this call may extends the size of the current bounding sphere.

Note

Repeated usage of this method causes erosion, and accumulation of inaccuracies.

Parameters

iVertexArray – Added vertices.

Returns

RED_OK when the computation succeeded,

RED_BAD_PARAM if the method received invalid parameters.

RED_RC Add(float *iVertexArray, int iSize)

Adds new vertex geometry to an already defined bounding sphere.

Same as RED::BoundingSphere::Add, using 3 floats per vertex.

Parameters
  • iVertexArray – List of vertices (XYZ XYZ XYZ in memory).

  • iSize – Size of iVertexArray in floats (= 3*nb_vertices).

RED_RC Add(const void *iVertexArray, int iVertexSize, RED::MESH_FORMAT iFormat, int iNbVertices)

Adds new vertex geometry to an already defined bounding sphere.

Same as RED::BoundingSphere::Add, using all possible vertex formats and sizes.

Parameters
  • iVertexArray – The array of vertices.

  • iVertexSize – The number of coordinates for each vertex (1 = x; 2 = xy; 3 = xyz; 4 = xyzw).

  • iFormat – The vertex array format.

  • iNbVertices – The number of vertices to consider.

Returns

RED_OK if the method has succeeded,

RED_BAD_PARAM if the method has received invalid parameters.

RED_RC Set(const RED::Vector<RED::BoundingSphere*> &iSphereList)

Encloses a list of bounding spheres.

This method sets the sphere parameters so that they define a sphere enclosing the provided list of spheres.

Parameters

iSphereList – List of spheres to merge with.

Returns

RED_OK when the computation succeeded,

RED_BAD_PARAM if the method received invalid parameters.

RED_RC Add(const RED::Vector<RED::BoundingSphere*> &iSphereList)

Adds new spheres to the already defined bounding sphere.

This method merges the currently defined object bounding sphere with the provided spheres. The result of this call may extends the size of the current bounding sphere.

Note

Repeated usage of this method causes erosion, and accumulation of inaccuracies.

Parameters

iSphereList – List of spheres to merge with.

Returns

RED_OK when the computation succeeded,

RED_BAD_PARAM if the method received invalid parameters.

inline const RED::Vector3 &GetCenter() const

Gets the center of the bounding sphere.

Returns

the bounding sphere center.

inline double GetRadius() const

Gets the radius of the bounding sphere.

Returns

The bounding sphere radius.

inline double GetRadius2() const

Gets the square radius of the bounding sphere.

Returns

The square value of the sphere’s radius.

RED_RC SetAABB(const double iAABB[6], bool iOverrideSphere = false)

Add an AABB information to the class.

The specified AABB is informative only and does not modify the behavior of the engine. If iOverrideSphere is true, the bounding sphere is redefined from the box, which can lead to erosion.

Parameters
  • iAABB – The Axis Aligned Bounding Box parameters in that order [ xmin, xmax, ymin, ymax, zmin, zmax ]. It’s valid to set a zero AABB to reset it.

  • iOverrideSphere – If true, the sphere is overriden by a sphere calculated from the specified box.

Returns

RED_OK if the operation has succeeded,

RED_BAD_PARAM if iAABB is invalid ( xmax < xmin or ymax < ymin or zmax < zmin ).

RED_RC SetAABB(const RED::Vector<RED::Vector3> &iVertex, bool iOverrideSphere = false)

Add an AABB information to the class.

The specified AABB is informative only and does not modify the behavior of the engine. If iOverrideSphere is true, the bounding sphere is redefined from the box, which can lead to erosion.

Parameters
  • iVertex – The vertex array to enclose. If empty, the AABB is reset to zero.

  • iOverrideSphere – If true, the sphere is overriden by a sphere calculated from the specified box.

Returns

RED_OK if the operation has succeeded, RED_FAIL otherwise.

RED_RC SetAABB(const float *iVertex, int iVerticesCount, bool iOverrideSphere = false)

Add an AABB information to the class.

The specified AABB is informative only and does not modify the behavior of the engine. If iOverrideSphere is true, the bounding sphere is redefined from the box, which can lead to erosion.

Parameters
  • iVertex – The vertex array to enclose (XYZ, float).

  • iVerticesCount – The number of vertices.

  • iOverrideSphere – If true, the sphere is overriden by a sphere calculated from the specified box.

Returns

RED_OK if the operation has succeeded, RED_FAIL otherwise.

inline void GetAABB(double oAABB[6]) const

Access the AABB information stored in the class.

Parameters

oAABB – Returned AABB information [ xmin, xmax, ymin, ymax, zmin, zmax ].

inline bool IsAABB() const
Returns

true if a valid AABB has been set.

Public Static Functions

static inline RED::CID GetClassID()