Class TwistServo
- Namespace
- Jitter2.Dynamics.Constraints
- Assembly
- Jitter2.dll
Drives relative twist toward a target angle using limited torque. Controls one angular degree of freedom; translation and swing remain free.
public class TwistServo : Constraint<TwistServo.TwistServoData>, IDebugDrawable
- Inheritance
-
TwistServo
- Implements
- Inherited Members
Remarks
Uses signed joint angles in [-pi, pi], without tracking revolutions. Combine with mechanical limits that keep motion inside this angular interval.
Properties
Angle
Gets the current relative twist angle in [-pi, pi]. Revolutions are not tracked.
public JAngle Angle { get; }
Property Value
Bias
Gets or sets how aggressively the servo corrects its position error.
public float Bias { get; set; }
Property Value
- float
Default is DefaultAngularBias.
Impulse
Gets the signed angular impulse in the last solved substep.
public float Impulse { get; }
Property Value
MaximumTorque
Gets or sets the maximum total torque the servo can apply.
public float MaximumTorque { get; set; }
Property Value
- float
Default is zero. Positive infinity allows unlimited torque.
Softness
Gets or sets the softness (compliance) of the servo.
public float Softness { get; set; }
Property Value
- float
Default is DefaultAngularSoftness.
TargetAngle
Gets or sets the desired twist angle relative to the initial zero-twist pose.
public JAngle TargetAngle { get; set; }
Property Value
Remarks
The target must be in [-pi, pi]. The signed angle error is not wrapped: moving from -170 to +170 degrees travels through zero. Revolution counts are not supported.
Exceptions
- ArgumentOutOfRangeException
The value is not finite or is outside [-pi, pi].
Methods
Create()
Called when the world creates this constraint. Override to set DispatchId to the ID returned by registering the constraint's solver methods.
protected override void Create()
DebugDraw(IDebugDrawer)
Draws a debug visualization of this constraint.
public override void DebugDraw(IDebugDrawer drawer)
Parameters
drawerIDebugDrawerThe 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
drawerIDebugDrawersettingsDebugDrawSettings
Initialize(JVector, JAngle)
Initializes both twist axes from the same world-space direction.
public void Initialize(JVector axis, JAngle targetAngle = default)
Parameters
Initialize(JVector, JVector, JAngle)
Initializes separate world-space twist axes and a target relative to the initial pose.
public void Initialize(JVector axis1, JVector axis2, JAngle targetAngle = default)
Parameters
Remarks
The shortest rotation aligning the two axes defines zero twist. Maximum torque defaults to zero. A nonzero target angle starts the servo outside its target configuration.
Exceptions
- ArgumentOutOfRangeException
The target angle is not finite or is outside [-pi, pi].
IterateTwistServo(ref ConstraintData, in TimeStep)
public static void IterateTwistServo(ref ConstraintData constraint, in TimeStep timeStep)
Parameters
constraintConstraintDatatimeStepTimeStep
PrepareForIterationTwistServo(ref ConstraintData, in TimeStep)
public static void PrepareForIterationTwistServo(ref ConstraintData constraint, in TimeStep timeStep)
Parameters
constraintConstraintDatatimeStepTimeStep
ResetWarmStart()
Clears impulses saved from the previous solve, without changing constraint settings.
public override void ResetWarmStart()
Remarks
Use after restoring a saved state or making a sudden change to the bodies, when impulses from their previous state should no longer be reused.
ToString()
Returns a short description of the constraint's ID, connected bodies, and state.
public override string ToString()