Table of Contents

Class Shape

Namespace
Jitter2.Collision.Shapes
Assembly
Jitter2.dll

Defines collision geometry in local coordinates.

public abstract class Shape : IDynamicTreeProxy, IPartitionedSetIndex, IUpdatableBoundingBox, ISupportFeature, ISupportMappable, IRayCastable, IAngularSweepTestable, ISweepTestable, IDistanceTestable, IDebugDrawable
Inheritance
Shape
Implements
Derived
Inherited Members

Remarks

A shape has no position or orientation of its own. Shapes attached to a RigidBody use that body's transform.

Fields

ShapeId

A unique identifier for this shape.

public readonly ulong ShapeId

Field Value

ulong

Properties

Velocity

Gets the velocity of the entity, used for bounding box expansion.

[ReferenceFrame(ReferenceFrame.World)]
public abstract JVector Velocity { get; }

Property Value

JVector

WorldBoundingBox

The bounding box of the shape in world space. It is automatically updated when the position or orientation of the corresponding instance of RigidBody changes. It may include the body's predicted translation and rotation over the next step.

public JBoundingBox WorldBoundingBox { get; protected set; }

Property Value

JBoundingBox

Methods

DebugDraw(IDebugDrawer)

Draws the shape using the default visualization settings.

public void DebugDraw(IDebugDrawer drawer)

Parameters

drawer IDebugDrawer

DebugDraw(IDebugDrawer, in DebugDrawSettings)

Draws the shape as world-space triangles using the supplied settings.

public virtual void DebugDraw(IDebugDrawer drawer, in DebugDrawSettings settings)

Parameters

drawer IDebugDrawer
settings DebugDrawSettings

Remarks

Point clouds and custom shapes may use an approximate surface with gaps or overlapping faces. Higher detail settings increase the drawing cost and do not guarantee a more accurate surface.

DebugDrawLocal<TSink>(ref TSink, in DebugDrawSettings)

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

protected virtual 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.

Distance<T>(in T, in JQuaternion, in JVector, out JVector, out JVector, out JVector, out float)

Finds the closest points between this object and the query shape.

[ReferenceFrame(ReferenceFrame.World)]
public abstract bool Distance<T>(in T support, in JQuaternion orientation, in JVector position, out JVector pointA, out JVector pointB, out JVector normal, out float distance) where T : ISupportMappable

Parameters

support T

The query shape.

orientation JQuaternion

The query shape orientation in world space.

position JVector

The query shape position in world space.

pointA JVector

Closest point on the query shape in world space. Undefined when the shapes overlap.

pointB JVector

Closest point on this object in world space. Undefined when the shapes overlap.

normal JVector

Unit direction from the query shape toward this object, or Zero when the shapes overlap. Do not use this to test whether a result was found.

distance float

The separation distance between the shapes. Zero when overlapping.

Returns

bool

true if the shapes are separated; false if they overlap.

Type Parameters

T

The query support-map type.

GetCenter(out JVector)

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

[ReferenceFrame(ReferenceFrame.Local)]
public abstract void GetCenter(out JVector point)

Parameters

point JVector

An interior point in local space.

RayCast(in JVector, in JVector, out JVector, out float)

Performs a ray cast against this object.

[ReferenceFrame(ReferenceFrame.World)]
public abstract bool RayCast(in JVector origin, in JVector direction, out JVector normal, out float lambda)

Parameters

origin JVector

The starting point of the ray.

direction JVector

The direction of the ray. Does not need to be normalized.

normal JVector

The surface normal at the intersection point, or Zero if the ray origin is inside the object. Use the return value, not this parameter, to test whether a hit occurred.

lambda float

The ray parameter of the intersection: hitPoint = origin + lambda * direction. It is a distance only if direction is normalized. Zero when the ray origin is inside the object.

Returns

bool

true if the ray intersects with the object; otherwise, false. Also returns true when the ray origin is inside the object, with lambda set to zero and normal set to Zero.

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

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

[ReferenceFrame(ReferenceFrame.Local)]
public virtual 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.

[ReferenceFrame(ReferenceFrame.Local)]
public abstract 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.

Sweep<T>(in T, in JQuaternion, in JVector, in JVector, out JVector, out JVector, out JVector, out float)

Performs a sweep test against this object.

[ReferenceFrame(ReferenceFrame.World)]
public abstract bool Sweep<T>(in T support, in JQuaternion orientation, in JVector position, in JVector sweep, out JVector pointA, out JVector pointB, out JVector normal, out float lambda) where T : ISupportMappable

Parameters

support T

The query shape.

orientation JQuaternion

The query shape orientation in world space.

position JVector

The query shape position in world space.

sweep JVector

The query shape translation in world space.

pointA JVector

Collision point on the query shape in world space at the sweep origin. Undefined when the shapes already overlap.

pointB JVector

Collision point on this object in world space at the sweep origin. Undefined when the shapes already overlap.

normal JVector

Collision normal in world space, or Zero if the shapes already overlap. Use the return value to determine whether a hit occurred; do not rely on this being non-zero.

lambda float

The time of impact expressed in units of sweep. Zero if the shapes already overlap.

Returns

bool

true if the query shape hits or already overlaps this object; otherwise, false.

Type Parameters

T

The query support-map type.

Sweep<T>(in T, in JQuaternion, in JVector, in JVector, in JVector, float, float, out JVector, out JVector, out JVector, out float)

Finds the first impact within the specified time interval.

[ReferenceFrame(ReferenceFrame.World)]
public virtual bool Sweep<T>(in T support, in JQuaternion orientation, in JVector position, in JVector velocity, in JVector angularVelocity, float extent, float maximumTime, out JVector pointA, out JVector pointB, out JVector normal, out float lambda) where T : ISupportMappable

Parameters

support T

The query shape.

orientation JQuaternion

The query shape's initial world-space orientation.

position JVector

The query shape's initial world-space position and rotation origin.

velocity JVector

The query shape's linear velocity in world space.

angularVelocity JVector

The query shape's angular velocity in world space, in radians per second.

extent float

A radius enclosing the query shape about its rotation origin, including any local offset.

maximumTime float

The last time to search, in seconds.

pointA JVector

Contact point on the query shape at its initial pose.

pointB JVector

Contact point on this object in world space.

normal JVector

World-space normal from the query shape toward this object at impact; zero for initial overlap.

lambda float

Time of impact in seconds; zero for initial overlap.

Returns

bool

True if an impact is found; false if the shapes miss or the search fails.

Type Parameters

T

The query support-map type.

UpdateWorldBoundingBox(float)

Recomputes the world-space bounding box.

[ReferenceFrame(ReferenceFrame.World)]
public abstract void UpdateWorldBoundingBox(float dt = 0)

Parameters

dt float

The timestep for velocity-based expansion. Default is zero.