Class ConvexHullShape
Represents a convex hull shape defined by a set of triangles.
public class ConvexHullShape : RigidBodyShape, IDynamicTreeProxy, IPartitionedSetIndex, IUpdatableBoundingBox, ISupportMappable, IRayCastable, ISweepTestable, IDistanceTestable, IDebugDrawable, ICloneableShape<ConvexHullShape>
- Inheritance
-
ConvexHullShape
- Implements
- Inherited Members
Constructors
ConvexHullShape(IEnumerable<JTriangle>)
Initializes a new instance of the ConvexHullShape class, creating a convex hull.
public ConvexHullShape(IEnumerable<JTriangle> triangles)
Parameters
trianglesIEnumerable<JTriangle>Triangles describing the convex hull surface. Their vertices must lie on the surface of the convex hull to avoid incorrect results or indefinite hangs in the collision algorithm.
Exceptions
- ArgumentException
Thrown when
trianglesis empty, or when the convex hull consists of more than MaxValue vertices.- InvalidOperationException
Thrown when
trianglesdoes not define a non-degenerate volume.
ConvexHullShape(ReadOnlySpan<JTriangle>)
Initializes a new instance of the ConvexHullShape class, creating a convex hull.
public ConvexHullShape(ReadOnlySpan<JTriangle> triangles)
Parameters
trianglesReadOnlySpan<JTriangle>Triangles describing the convex hull surface. Their vertices must lie on the surface of the convex hull to avoid incorrect results or indefinite hangs in the collision algorithm.
Exceptions
- ArgumentException
Thrown when
trianglesis empty, or when the convex hull consists of more than MaxValue vertices.- InvalidOperationException
Thrown when
trianglesdoes not define a non-degenerate volume.
Properties
Shift
Gets or sets the shift applied to the convex hull vertices.
public JVector Shift { get; set; }
Property Value
Methods
CalculateBoundingBox(in JQuaternion, in JVector, out JBoundingBox)
public override void CalculateBoundingBox(in JQuaternion orientation, in JVector position, out JBoundingBox box)
Parameters
orientationJQuaternionpositionJVectorboxJBoundingBox
CalculateMassInertia()
Recalculates the mass, center of mass, and inertia tensor from the convex hull triangles.
public void CalculateMassInertia()
Exceptions
- InvalidOperationException
Thrown when the convex hull does not define a non-degenerate volume.
CalculateMassInertia(out JSymmetricMatrix, out JVector, out float)
Calculates the mass and inertia of the shape. Can be overridden by child classes to improve performance or accuracy. The default implementation relies on an approximation of the shape constructed using the support map function.
public override void CalculateMassInertia(out JSymmetricMatrix inertia, out JVector com, out float mass)
Parameters
inertiaJSymmetricMatrixcomJVectormassfloat
Remarks
The inertia tensor is computed relative to the coordinate system origin (0,0,0), not the center of mass.
Clone()
Creates a clone of the convex hull shape. Note that the underlying data structure is shared among instances.
public ConvexHullShape Clone()
Returns
- ConvexHullShape
A new instance of the ConvexHullShape class that shares the same underlying data structure as the original instance.
DebugDrawLocal<TSink>(ref TSink, in DebugDrawSettings)
Appends debug triangles in the coordinate system used by SupportMap(in JVector, out JVector).
protected override void DebugDrawLocal<TSink>(ref TSink triangleSink, in DebugDrawSettings settings) where TSink : ISink<JTriangle>
Parameters
triangleSinkTSinkThe destination for generated triangles.
settingsDebugDrawSettingsThe visualization settings.
Type Parameters
TSink
Remarks
Override this method to supply custom surface geometry. Rigid-body and affine transforms are applied by the caller. Use outward-facing triangles for closed surfaces. Without an override, the shape is drawn as an approximate surface.
GetCenter(out JVector)
Computes a representative point within the convex hull, used as an initial search point in GJK-based algorithms.
public override void GetCenter(out JVector point)
Parameters
pointJVectorA point inside the convex hull.
SupportMap(in JVector, out JVector)
Computes the point on the shape that is furthest in the specified direction.
public override void SupportMap(in JVector direction, out JVector result)
Parameters
directionJVectorThe search direction in local space. Does not need to be normalized.
resultJVectorThe point on the shape's surface furthest along
direction.
UpdateShape()
Updates the shape's cached mass, inertia, and bounding box.
public void UpdateShape()
Exceptions
- InvalidOperationException
Thrown when the convex hull does not define a non-degenerate volume.