GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::physics::ConvexPolytopeShape< N > Class Template Reference

Convex polytope shape. More...

#include <GREM/physics/Shape.hpp>

Public Types

using Vertex = typename ConvexPolytope<N, float>::Vertex
 Vertex type of the convex polytope shape.
using Face = typename ConvexPolytope<N, float>::Face
 Face type of the convex polytope shape.
using Edge = typename ConvexPolytope<N, float>::Edge
 Edge type of the convex polytope shape.

Public Member Functions

GREM_ALWAYS_INLINE ConvexPolytopeShape (SharedPointer< ConvexPolytope< N, float > > polytope) noexcept
 Construct a convex polytope shape from an existing convex polytope.
 ConvexPolytopeShape (Span< const Vertex > vertices, ConvexPolytopeVertexIndex maxVertexCount=Limits< ConvexPolytopeVertexIndex >::MAX)
 Construct a convex polytope shape from a set of vertices.
GREM_ALWAYS_INLINE const SharedPointer< ConvexPolytope< N, float > > & getConvexPolytope () const noexcept
 Get the underlying convex polytope of the shape.
Volume calculateVolume () const
 Calculate an estimate of the volume of the shape.
PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia (Mass mass) const
 Calculate an estimate of the local moment of inertia of the shape given a certain mass.
GREM_ALWAYS_INLINE Optional< Box< N > > getBoundingBox (const Transformation< N > &transformation) const
 Get the axis-aligned bounding box of the shape given its position and orientation in the world.
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius (const Basis< N > &basis) const
 Get the radius of the bounding sphere of the shape.
Optional< Area > getReferenceArea (const Basis< N > &basis, Direction< N > direction) const
 Get an estimate of the reference area of the shape for a certain direction, typically calculated as the area of the largest cross section orthogonal to the given direction.
RaycastResult< N > castLocalRay (Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
 Find the closest intersection of this shape with a given ray in local space.
bool containsLocalPoint (Length< N > localPoint) const
 Check if a local point relative to the origin of the shape is contained within the shape.
Length< N > getLocalSupportPointOffset (Direction< N > localDirection) const
 Get the local offset from the origin of the shape to the farthest point on the shape in a certain local direction.
ConvexPolytopeVertexIndex getLocalSupportPointVertexIndex (Direction< N > localDirection, ConvexPolytopeVertexIndex searchStartVertexIndex) const
 Get the vertex index of the farthest point on the shape in a certain local direction.
GREM_ALWAYS_INLINE ConvexPolytopeVertexIndex getVertexCount () const
 Get the total number of vertices in the convex polytope defined by this shape.
GREM_ALWAYS_INLINE ConvexPolytopeFaceIndex getFaceCount () const
 Get the total number of faces on the convex polytope defined by this shape.
GREM_ALWAYS_INLINE ConvexPolytopeEdgeIndex getEdgeCount () const
 Get the total number of edges, including twin edges, on the convex polyhedron defined by this 3-dimensional shape.
Length< N > getLocalVertexOffset (ConvexPolytopeVertexIndex vertexIndex) const
 Get the local offset of a specific vertex in the convex polytope defined by this shape.
Length< N > getLocalFaceOffset (ConvexPolytopeFaceIndex faceIndex) const
 Get the local offset of a specific face on the convex polytope defined by this shape.
Direction< N > getLocalFaceNormal (ConvexPolytopeFaceIndex faceIndex) const
 Get the local normal of a specific face on the convex polytope defined by this shape.
ConvexPolytopeFaceIndex getFaceIndexWithMostFittingLocalNormal (Direction< N > localDirection, ConvexPolytopeFaceIndex searchStartFaceIndex) const
 Get the index of the face on the convex polytope defined by this shape whose local normal is the most parallel with a given local direction.
ConvexPolytopeVertexIndex getFirstVertexIndexOfEdge (ConvexPolytopeEdgeIndex edgeIndex) const
 Get the vertex index of the first point of a specific edge on the convex polyhedron defined by this 3-dimensional shape.
ConvexPolytopeFaceIndex getFaceIndexOfEdge (ConvexPolytopeEdgeIndex edgeIndex) const
 Get the index of the face that a specific edge is part of on the convex polyhedron defined by this 3-dimensional shape.
ConvexPolytopeEdgeIndex getNextEdgeIndex (ConvexPolytopeEdgeIndex edgeIndex) const
 Get the index of the next edge after another edge on the same face on the convex polyhedron defined by this 3-dimensional shape, which will eventually loop back around to the given edge again.
ConvexPolytopeEdgeIndex getFirstEdgeIndexOfFace (ConvexPolytopeFaceIndex faceIndex) const
 Get the index of the first edge that a specific face is made up of on the convex polyhedron defined by this 3-dimensional shape.
ConvexPolytopeEdgeIndex getSomeEdgeIndexOfVertex (ConvexPolytopeVertexIndex vertexIndex) const
 Get the index of some edge that has a specific vertex as its origin on the convex polyhedron defined by this 3-dimensional shape.

Detailed Description

template<size_t N>
class grem::physics::ConvexPolytopeShape< N >

Convex polytope shape.

Template Parameters
Nnumber of dimensions of the world space (must be 2 or 3).

Member Typedef Documentation

◆ Vertex

template<size_t N>
using grem::physics::ConvexPolytopeShape< N >::Vertex = typename ConvexPolytope<N, float>::Vertex

Vertex type of the convex polytope shape.

◆ Face

template<size_t N>
using grem::physics::ConvexPolytopeShape< N >::Face = typename ConvexPolytope<N, float>::Face

Face type of the convex polytope shape.

◆ Edge

template<size_t N>
using grem::physics::ConvexPolytopeShape< N >::Edge = typename ConvexPolytope<N, float>::Edge

Edge type of the convex polytope shape.

Constructor & Destructor Documentation

◆ ConvexPolytopeShape() [1/2]

template<size_t N>
GREM_ALWAYS_INLINE grem::physics::ConvexPolytopeShape< N >::ConvexPolytopeShape ( SharedPointer< ConvexPolytope< N, float > > polytope)
inlineexplicitnoexcept

Construct a convex polytope shape from an existing convex polytope.

Parameters
polytopeshared pointer to the polytope. Must not be nullptr.

◆ ConvexPolytopeShape() [2/2]

template<size_t N>
grem::physics::ConvexPolytopeShape< N >::ConvexPolytopeShape ( Span< const Vertex > vertices,
ConvexPolytopeVertexIndex maxVertexCount = Limits< ConvexPolytopeVertexIndex >::MAX )
explicit

Construct a convex polytope shape from a set of vertices.

Parameters
verticesread-only view over a set of vertices to construct the convex hull from.
maxVertexCountmaximum number of vertices to build the convex hull out of.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

Member Function Documentation

◆ getConvexPolytope()

template<size_t N>
GREM_ALWAYS_INLINE const SharedPointer< ConvexPolytope< N, float > > & grem::physics::ConvexPolytopeShape< N >::getConvexPolytope ( ) const
inlinenodiscardnoexcept

Get the underlying convex polytope of the shape.

Returns
a read-only reference to the underlying convex polytope.

◆ calculateVolume()

template<size_t N>
Volume grem::physics::ConvexPolytopeShape< N >::calculateVolume ( ) const
nodiscard

Calculate an estimate of the volume of the shape.

Returns
the estimated volume of the shape.

◆ calculatePrincipalMomentsOfInertia()

template<size_t N>
PrincipalMomentsOfInertia< N > grem::physics::ConvexPolytopeShape< N >::calculatePrincipalMomentsOfInertia ( Mass mass) const
nodiscard

Calculate an estimate of the local moment of inertia of the shape given a certain mass.

Parameters
massassumed mass of the shape.
Returns
the estimated moment of inertia in shape-local space.

◆ getBoundingBox()

template<size_t N>
GREM_ALWAYS_INLINE Optional< Box< N > > grem::physics::ConvexPolytopeShape< N >::getBoundingBox ( const Transformation< N > & transformation) const
inlinenodiscard

Get the axis-aligned bounding box of the shape given its position and orientation in the world.

Parameters
transformationtransformation of the shape in world space.
Returns
an axis-aligned bounding box in world space that would contain the entire shape if the shape was at the given position and orientation in the world, or an empty optional if the shape extends infinitely and cannot be fit inside a finite box.

◆ getBoundingRadius()

template<size_t N>
GREM_ALWAYS_INLINE Optional< Distance > grem::physics::ConvexPolytopeShape< N >::getBoundingRadius ( const Basis< N > & basis) const
inlinenodiscard

Get the radius of the bounding sphere of the shape.

Parameters
basistransformation basis of the shape in world space.
Returns
the maximum distance from the origin of any point on the shape, or an empty optional if the shape extends infinitely and cannot be fit inside a finite sphere.

◆ getReferenceArea()

template<size_t N>
Optional< Area > grem::physics::ConvexPolytopeShape< N >::getReferenceArea ( const Basis< N > & basis,
Direction< N > direction ) const
nodiscard

Get an estimate of the reference area of the shape for a certain direction, typically calculated as the area of the largest cross section orthogonal to the given direction.

Parameters
basistransformation basis of the shape in world space.
directiondirection to get the reference area for.
Returns
the reference area, or an empty optional if an area cannot be determined, e.g. because the shape is infinite.

◆ castLocalRay()

template<size_t N>
RaycastResult< N > grem::physics::ConvexPolytopeShape< N >::castLocalRay ( Length< N > localRayOrigin,
Direction< N > localRayDirection,
Distance maxLocalRayDistance ) const
nodiscard

Find the closest intersection of this shape with a given ray in local space.

Parameters
localRayOriginoffset of the ray origin in shape-local space.
localRayDirectionunit direction vector of the ray in shape-local space. Must be a unit vector.
maxLocalRayDistancemaximum hit distance of the ray in shape-local space. Must be non-negative.
Returns
the result of the raycast.

◆ containsLocalPoint()

template<size_t N>
bool grem::physics::ConvexPolytopeShape< N >::containsLocalPoint ( Length< N > localPoint) const
nodiscard

Check if a local point relative to the origin of the shape is contained within the shape.

Parameters
localPointpoint in shape-local space to check.
Returns
true if the shape contains the given point, false otherwise.
Exceptions
BadVariantAccessif the underlying shape type is not convex.

◆ getLocalSupportPointOffset()

template<size_t N>
Length< N > grem::physics::ConvexPolytopeShape< N >::getLocalSupportPointOffset ( Direction< N > localDirection) const
nodiscard

Get the local offset from the origin of the shape to the farthest point on the shape in a certain local direction.

Parameters
localDirectionunit vector in shape-local space of the direction to evaluate. Must be a unit vector.
Returns
a relative vector from the origin of the shape to the farthest point on the shape in the given direction, in shape-local space.
Exceptions
BadVariantAccessif the underlying shape type is not convex.

◆ getLocalSupportPointVertexIndex()

template<size_t N>
ConvexPolytopeVertexIndex grem::physics::ConvexPolytopeShape< N >::getLocalSupportPointVertexIndex ( Direction< N > localDirection,
ConvexPolytopeVertexIndex searchStartVertexIndex ) const
nodiscard

Get the vertex index of the farthest point on the shape in a certain local direction.

Parameters
localDirectionunit vector in shape-local space of the direction to evaluate. Must be a unit vector.
searchStartVertexIndexinitial vertex index to start the search from. Must either be 0, or less than getVertexCount().
Returns
the vertex index of the farthest point on the shape in the given direction.
Exceptions
BadVariantAccessif the underlying shape type is not a convex polytope.

◆ getVertexCount()

template<size_t N>
GREM_ALWAYS_INLINE ConvexPolytopeVertexIndex grem::physics::ConvexPolytopeShape< N >::getVertexCount ( ) const
inlinenodiscard

Get the total number of vertices in the convex polytope defined by this shape.

Returns
the number of vertices in the shape.
Exceptions
BadVariantAccessif the underlying shape type is not a convex polytope.

◆ getFaceCount()

template<size_t N>
GREM_ALWAYS_INLINE ConvexPolytopeFaceIndex grem::physics::ConvexPolytopeShape< N >::getFaceCount ( ) const
inlinenodiscard

Get the total number of faces on the convex polytope defined by this shape.

Returns
the number of faces on the shape.
Exceptions
BadVariantAccessif the underlying shape type is not a convex polytope.

◆ getEdgeCount()

template<size_t N>
GREM_ALWAYS_INLINE ConvexPolytopeEdgeIndex grem::physics::ConvexPolytopeShape< N >::getEdgeCount ( ) const
inlinenodiscard

Get the total number of edges, including twin edges, on the convex polyhedron defined by this 3-dimensional shape.

Returns
the number of edges, including twin edges, on the shape.
Exceptions
BadVariantAccessif the underlying shape type is not a convex polytope.

◆ getLocalVertexOffset()

template<size_t N>
Length< N > grem::physics::ConvexPolytopeShape< N >::getLocalVertexOffset ( ConvexPolytopeVertexIndex vertexIndex) const
nodiscard

Get the local offset of a specific vertex in the convex polytope defined by this shape.

Parameters
vertexIndexindex of the vertex to get the offset of.
Returns
the offset of the given vertex from the center of the shape, in shape-local space.
Exceptions
BadVariantAccessif the underlying shape type is not a convex polytope.

◆ getLocalFaceOffset()

template<size_t N>
Length< N > grem::physics::ConvexPolytopeShape< N >::getLocalFaceOffset ( ConvexPolytopeFaceIndex faceIndex) const
nodiscard

Get the local offset of a specific face on the convex polytope defined by this shape.

Parameters
faceIndexindex of the face to get the offset of.
Returns
an arbitrary point the given face, in shape-local space.
Exceptions
BadVariantAccessif the underlying shape type is not a convex polytope.

◆ getLocalFaceNormal()

template<size_t N>
Direction< N > grem::physics::ConvexPolytopeShape< N >::getLocalFaceNormal ( ConvexPolytopeFaceIndex faceIndex) const
nodiscard

Get the local normal of a specific face on the convex polytope defined by this shape.

Parameters
faceIndexindex of the face to get the normal of.
Returns
a unit direction vector perpendicular to the given face, in shape-local space, pointing outwards from the center of the shape.
Exceptions
BadVariantAccessif the underlying shape type is not a convex polytope.

◆ getFaceIndexWithMostFittingLocalNormal()

template<size_t N>
ConvexPolytopeFaceIndex grem::physics::ConvexPolytopeShape< N >::getFaceIndexWithMostFittingLocalNormal ( Direction< N > localDirection,
ConvexPolytopeFaceIndex searchStartFaceIndex ) const
nodiscard

Get the index of the face on the convex polytope defined by this shape whose local normal is the most parallel with a given local direction.

Parameters
localDirectionunit direction vector to search in, in object space. Must be a unit vector.
searchStartFaceIndexinitial face index to start the search from. Must either be 0, or less than getFaceCount().
Returns
the index of the face whose normal is pointing the most towards the given direction.
Exceptions
BadVariantAccessif the underlying shape type is not a convex polytope.

◆ getFirstVertexIndexOfEdge()

template<size_t N>
ConvexPolytopeVertexIndex grem::physics::ConvexPolytopeShape< N >::getFirstVertexIndexOfEdge ( ConvexPolytopeEdgeIndex edgeIndex) const
nodiscard

Get the vertex index of the first point of a specific edge on the convex polyhedron defined by this 3-dimensional shape.

Parameters
edgeIndexindex of the edge whose vertex index to get.
Returns
the vertex index of the first point of the given edge.
Exceptions
BadVariantAccessif the underlying shape type is not a convex polytope.

◆ getFaceIndexOfEdge()

template<size_t N>
ConvexPolytopeFaceIndex grem::physics::ConvexPolytopeShape< N >::getFaceIndexOfEdge ( ConvexPolytopeEdgeIndex edgeIndex) const
nodiscard

Get the index of the face that a specific edge is part of on the convex polyhedron defined by this 3-dimensional shape.

Parameters
edgeIndexindex of the edge to get the face index of.
Returns
the index of the face that the given edge belongs to.
Exceptions
BadVariantAccessif the underlying shape type is not a convex polytope.

◆ getNextEdgeIndex()

template<size_t N>
ConvexPolytopeEdgeIndex grem::physics::ConvexPolytopeShape< N >::getNextEdgeIndex ( ConvexPolytopeEdgeIndex edgeIndex) const
nodiscard

Get the index of the next edge after another edge on the same face on the convex polyhedron defined by this 3-dimensional shape, which will eventually loop back around to the given edge again.

The winding order is counter-clockwise when viewed from outside of the shape.

Parameters
edgeIndexindex of the edge to get the next edge index of.
Returns
the index of the next edge on the same face.
Exceptions
BadVariantAccessif the underlying shape type is not a convex polytope.

◆ getFirstEdgeIndexOfFace()

template<size_t N>
ConvexPolytopeEdgeIndex grem::physics::ConvexPolytopeShape< N >::getFirstEdgeIndexOfFace ( ConvexPolytopeFaceIndex faceIndex) const
nodiscard

Get the index of the first edge that a specific face is made up of on the convex polyhedron defined by this 3-dimensional shape.

Parameters
faceIndexindex of the face to get the first edge index of.
Returns
the index of the first edge that belongs to the given face.
Exceptions
BadVariantAccessif the underlying shape type is not a convex polytope.

◆ getSomeEdgeIndexOfVertex()

template<size_t N>
ConvexPolytopeEdgeIndex grem::physics::ConvexPolytopeShape< N >::getSomeEdgeIndexOfVertex ( ConvexPolytopeVertexIndex vertexIndex) const
nodiscard

Get the index of some edge that has a specific vertex as its origin on the convex polyhedron defined by this 3-dimensional shape.

Parameters
vertexIndexindex of the vertex to get the edge index of.
Returns
some edge index that has the given vertex as its origin.
Exceptions
BadVariantAccessif the underlying shape type is not a convex polytope.

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