Table of Contents

Class ConvexHullShape

Namespace
Jitter2.Collision.Shapes
Assembly
Jitter2.dll

Represents a convex hull shape defined by a set of triangles.

public class ConvexHullShape : RigidBodyShape, IDynamicTreeProxy, IPartitionedSetIndex, IUpdatableBoundingBox, ISupportFeature, ISupportMappable, IRayCastable, IAngularSweepTestable, 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

triangles IEnumerable<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 triangles is empty, or when the convex hull consists of more than MaxValue vertices.

InvalidOperationException

Thrown when triangles does 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

triangles ReadOnlySpan<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 triangles is empty, or when the convex hull consists of more than MaxValue vertices.

InvalidOperationException

Thrown when triangles does not define a non-degenerate volume.

Properties

Shift

Gets or sets the offset added to the hull vertices in local coordinates.

public JVector Shift { get; set; }

Property Value

JVector

Methods

CalculateBoundingBox(in JQuaternion, in JVector, out JBoundingBox)

public override void CalculateBoundingBox(in JQuaternion orientation, in JVector position, out JBoundingBox box)

Parameters

orientation JQuaternion
position JVector
box JBoundingBox

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 shape's mass, center of mass, and inertia at unit density. The default implementation approximates the surface; overrides can provide exact mass properties.

public override void CalculateMassInertia(out JSymmetricMatrix inertia, out JVector com, out float mass)

Parameters

inertia JSymmetricMatrix
com JVector
mass float

Remarks

The inertia tensor is computed relative to the coordinate system origin (0,0,0), not the center of mass.

Clone()

Creates a copy that shares the original hull geometry.

public ConvexHullShape Clone()

Returns

ConvexHullShape

DebugDrawLocal<TSink>(ref TSink, in DebugDrawSettings)

Draws the shape's surface as triangles in local coordinates.

protected override void DebugDrawLocal<TSink>(ref TSink triangleSink, in DebugDrawSettings settings) where TSink : ISink<JTriangle>

Parameters

triangleSink TSink

The destination for generated triangles.

settings DebugDrawSettings

The visualization settings.

Type Parameters

TSink

Remarks

Override to provide custom debug geometry; otherwise, the surface is approximated. Use outward-facing triangles for closed surfaces. Body and shape transforms are applied automatically.

GetCenter(out JVector)

Returns a point inside the shape. It does not need to be the center of mass.

public override void GetCenter(out JVector point)

Parameters

point JVector

An interior point in local space.

SupportFeature(in JVector, float, Span<JVector>)

Writes the outermost feature of the shape in the given direction.

public override int SupportFeature(in JVector direction, float tolerance, Span<JVector> vertices)

Parameters

direction JVector

The direction in local space. Does not need to be normalized.

tolerance float

The sine of the angle within which directions share the feature.

vertices Span<JVector>

Receives the vertices in local space: one for a point, two for a segment, three or more for a convex polygon in winding order. At least MaxVertices entries long.

Returns

int

The number of vertices written, at least one.

Remarks

The default samples the support mapping with SupportFeatureSampler. Shapes that know their features analytically should override it.

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

direction JVector

The search direction in local space. Does not need to be normalized.

result JVector

The 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.