Skip to content

Commit

Permalink
Add a Limit property to TwistAngle constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
notgiven688 committed Aug 23, 2024
1 parent 45537db commit b610677
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Jitter2/Dynamics/Constraints/HingeAngle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected override void Create()
/// Initializes the constraint.
/// </summary>
/// <param name="axis">Axis in world space for which relative angular movement is allowed.</param>
public void Initialize(JVector axis, AngularLimit angle)
public void Initialize(JVector axis, AngularLimit limit)
{
ref HingeAngleData data = ref handle.Data;
ref RigidBodyData body1 = ref data.Body1.Data;
Expand All @@ -91,8 +91,8 @@ public void Initialize(JVector axis, AngularLimit angle)
data.BiasFactor = 0.2f;
data.LimitBias = 0.1f;

data.MinAngle = MathF.Sin((float)angle.From / 2.0f);
data.MaxAngle = MathF.Sin((float)angle.To / 2.0f);
data.MinAngle = MathF.Sin((float)limit.From / 2.0f);
data.MaxAngle = MathF.Sin((float)limit.To / 2.0f);

data.Axis = JVector.TransposedTransform(axis, body2.Orientation);

Expand Down
18 changes: 14 additions & 4 deletions src/Jitter2/Dynamics/Constraints/TwistAngle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ protected override void Create()
/// </summary>
/// <param name="axis1">Axis fixed in the local reference frame of the first body, represented in world space.</param>
/// <param name="axis2">Axis fixed in the local reference frame of the second body, represented in world space.</param>
/// <param name="angle">The permissible relative twist between the bodies along the specified axes.</param>
public void Initialize(JVector axis1, JVector axis2, AngularLimit angle)
/// <param name="limit">The permissible relative twist between the bodies along the specified axes.</param>
public void Initialize(JVector axis1, JVector axis2, AngularLimit limit)
{
ref TwistLimitData data = ref handle.Data;
ref RigidBodyData body1 = ref data.Body1.Data;
Expand All @@ -91,8 +91,8 @@ public void Initialize(JVector axis1, JVector axis2, AngularLimit angle)
axis1.Normalize();
axis2.Normalize();

data.Angle1 = MathF.Sin((float)angle.From / 2.0f);
data.Angle2 = MathF.Sin((float)angle.To / 2.0f);
data.Angle1 = MathF.Sin((float)limit.From / 2.0f);
data.Angle2 = MathF.Sin((float)limit.To / 2.0f);

data.B = JVector.TransposedTransform(axis2, body2.Orientation);

Expand All @@ -102,6 +102,16 @@ public void Initialize(JVector axis1, JVector axis2, AngularLimit angle)
data.Q0 = q2.Conjugate() * q1;
}

public AngularLimit Limit
{
set
{
ref TwistLimitData data = ref handle.Data;
data.Angle1 = MathF.Sin((float)value.From / 2.0f);
data.Angle2 = MathF.Sin((float)value.To / 2.0f);
}
}

/// <summary>
/// Initializes the constraint.
/// </summary>
Expand Down

0 comments on commit b610677

Please sign in to comment.