Table of Contents

Class DistanceLimit

Namespace
Jitter2.Dynamics.Constraints
Assembly
Jitter2.dll

Constrains the distance between a fixed point in the reference frame of one body and a fixed point in the reference frame of another body. A fixed limit removes one translational degree of freedom; a range limit acts when a boundary is reached. For a distance of zero, use the BallSocket constraint.

public class DistanceLimit : Constraint<DistanceLimit.DistanceLimitData>, IDebugDrawable
Inheritance
DistanceLimit
Implements
Inherited Members

Properties

Anchor1

Gets or sets the anchor point on the first rigid body in world space. The anchor point is fixed in the local reference frame of the first body.

[ReferenceFrame(ReferenceFrame.World)]
public JVector Anchor1 { get; set; }

Property Value

JVector

Anchor2

Gets or sets the anchor point on the second rigid body in world space. The anchor point is fixed in the local reference frame of the second body.

[ReferenceFrame(ReferenceFrame.World)]
public JVector Anchor2 { get; set; }

Property Value

JVector

Bias

Gets or sets the bias factor controlling how aggressively distance error is corrected.

public float Bias { get; set; }

Property Value

float

Default is 0.2. Higher values correct errors faster but may cause instability.

Distance

Gets the current distance between anchor points in world space.

public float Distance { get; }

Property Value

float

Impulse

Gets the accumulated solver impulse from the last solved substep.

public float Impulse { get; }

Property Value

float

Softness

Gets or sets the softness (compliance) of the constraint.

public float Softness { get; set; }

Property Value

float

Default is DefaultLinearSoftness. Higher values allow more distance error but improve stability.

TargetDistance

Gets or sets the target distance between anchor points.

public float TargetDistance { get; set; }

Property Value

float

Set during initialization from the initial anchor separation.

Methods

Create()

Sets the solver dispatch id used by this instance. Override this in derived classes to assign the correct registered solver pair. The id is later written into the unmanaged header when the constraint is enabled.

protected override void Create()

DebugDraw(IDebugDrawer)

Draws a debug visualization of this constraint.

public override void DebugDraw(IDebugDrawer drawer)

Parameters

drawer IDebugDrawer

The debug drawer to receive visualization primitives.

Exceptions

NotImplementedException

Thrown if the derived class does not override this method.

DebugDraw(IDebugDrawer, in DebugDrawSettings)

Draws this constraint using the supplied visualization settings. Custom constraints that only override DebugDraw(IDebugDrawer) use their default visualization.

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

Parameters

drawer IDebugDrawer
settings DebugDrawSettings

Initialize(JVector, JVector)

Initializes the constraint with a fixed distance between anchor points.

public void Initialize(JVector anchor1, JVector anchor2)

Parameters

anchor1 JVector

Anchor point on the first body in world space.

anchor2 JVector

Anchor point on the second body in world space.

Exceptions

ArgumentException

Thrown when anchor1 or anchor2 contains a non-finite value.

Initialize(JVector, JVector, LinearLimit)

Initializes the constraint with distance limits between anchor points.

public void Initialize(JVector anchor1, JVector anchor2, LinearLimit limit)

Parameters

anchor1 JVector

Anchor point on the first body in world space.

anchor2 JVector

Anchor point on the second body in world space.

limit LinearLimit

Allowed offsets from the initial distance between anchor points. For example, a limit of (-1, 1) allows the distance to change by at most one unit in either direction.

Remarks

Computes local anchor points and the initial distance from current poses. Equal or reversed limits fix the distance offset at their midpoint. Default values: Softness = DefaultLinearSoftness, Bias = DefaultLinearBias.

Exceptions

ArgumentException

Thrown when anchor1 or anchor2 contains a non-finite value, or when either value in limit is NaN.

IterateDistanceLimit(ref ConstraintData, in TimeStep)

public static void IterateDistanceLimit(ref ConstraintData constraint, in TimeStep timeStep)

Parameters

constraint ConstraintData
timeStep TimeStep

PrepareForIterationDistanceLimit(ref ConstraintData, in TimeStep)

public static void PrepareForIterationDistanceLimit(ref ConstraintData constraint, in TimeStep timeStep)

Parameters

constraint ConstraintData
timeStep TimeStep

ResetWarmStart()

Resets the cached warm-start state used by the solver for this constraint.

public override void ResetWarmStart()

Remarks

This clears only persistent solver impulses. Constraint configuration remains unchanged. Useful after restoring snapshots or other discontinuous state changes where preserving warm-starting is undesirable.