Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
ConvexHullBuilder Class Reference

A convex hull builder that tries to create hulls as accurately as possible. Used for offline processing. More...

#include <ConvexHullBuilder.h>

Inheritance diagram for ConvexHullBuilder:
NonCopyable

Classes

class  Edge
 Class that holds the information of an edge. More...
 
class  Face
 Class that holds the information of one face. More...
 

Public Types

enum class  EResult {
  Success , MaxVerticesReached , TooFewPoints , TooFewFaces ,
  Degenerate
}
 Result enum that indicates how the hull got created. More...
 
using ConflictList = Array< int >
 
using Positions = Array< Vec3 >
 
using Faces = Array< Face * >
 

Public Member Functions

 ConvexHullBuilder (const Positions &inPositions)
 Constructor. More...
 
 ~ConvexHullBuilder ()
 Destructor. More...
 
EResult Initialize (int inMaxVertices, float inTolerance, const char *&outError)
 
int GetNumVerticesUsed () const
 Returns the amount of vertices that are currently used by the hull. More...
 
bool ContainsFace (const Array< int > &inIndices) const
 Returns true if the hull contains a polygon with inIndices (counter clockwise indices in mPositions) More...
 
void GetCenterOfMassAndVolume (Vec3 &outCenterOfMass, float &outVolume) const
 Calculate the center of mass and the volume of the current convex hull. More...
 
void DetermineMaxError (Face *&outFaceWithMaxError, float &outMaxError, int &outMaxErrorPositionIdx, float &outCoplanarDistance) const
 
const FacesGetFaces () const
 Access to the created faces. Memory is owned by the convex hull builder. More...
 
- Public Member Functions inherited from NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
void operator= (const NonCopyable &)=delete
 

Detailed Description

A convex hull builder that tries to create hulls as accurately as possible. Used for offline processing.

Member Typedef Documentation

◆ ConflictList

◆ Faces

◆ Positions

Member Enumeration Documentation

◆ EResult

enum class ConvexHullBuilder::EResult
strong

Result enum that indicates how the hull got created.

Enumerator
Success 

Hull building finished successfully.

MaxVerticesReached 

Hull building finished successfully, but the desired accuracy was not reached because the max vertices limit was reached.

TooFewPoints 

Too few points to create a hull.

TooFewFaces 

Too few faces in the created hull (signifies precision errors during building)

Degenerate 

Degenerate hull detected.

Constructor & Destructor Documentation

◆ ConvexHullBuilder()

ConvexHullBuilder::ConvexHullBuilder ( const Positions inPositions)
explicit

Constructor.

◆ ~ConvexHullBuilder()

ConvexHullBuilder::~ConvexHullBuilder ( )
inline

Destructor.

Member Function Documentation

◆ ContainsFace()

bool ConvexHullBuilder::ContainsFace ( const Array< int > &  inIndices) const

Returns true if the hull contains a polygon with inIndices (counter clockwise indices in mPositions)

◆ DetermineMaxError()

void ConvexHullBuilder::DetermineMaxError ( Face *&  outFaceWithMaxError,
float &  outMaxError,
int &  outMaxErrorPositionIdx,
float &  outCoplanarDistance 
) const

Determines the point that is furthest outside of the hull and reports how far it is outside of the hull (which indicates a failure during hull building)

Parameters
outFaceWithMaxErrorThe face that caused the error
outMaxErrorThe maximum distance of a point to the hull
outMaxErrorPositionIdxThe index of the point that had this distance
outCoplanarDistancePoints that are less than this distance from the hull are considered on the hull. This should be used as a lowerbound for the allowed error.

◆ GetCenterOfMassAndVolume()

void ConvexHullBuilder::GetCenterOfMassAndVolume ( Vec3 outCenterOfMass,
float &  outVolume 
) const

Calculate the center of mass and the volume of the current convex hull.

◆ GetFaces()

const Faces & ConvexHullBuilder::GetFaces ( ) const
inline

Access to the created faces. Memory is owned by the convex hull builder.

◆ GetNumVerticesUsed()

int ConvexHullBuilder::GetNumVerticesUsed ( ) const

Returns the amount of vertices that are currently used by the hull.

◆ Initialize()

ConvexHullBuilder::EResult ConvexHullBuilder::Initialize ( int  inMaxVertices,
float  inTolerance,
const char *&  outError 
)

Takes all positions as provided by the constructor and use them to build a hull Any points that are closer to the hull than inTolerance will be discarded

Parameters
inMaxVerticesMax vertices to allow in the hull. Specify INT_MAX if there is no limit.
inToleranceMax distance that a point is allowed to be outside of the hull
outErrorError message when building fails
Returns
Status code that reports if the hull was created or not

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