Skip to content

Commit

Permalink
Merge pull request #171 from notgiven688/tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
notgiven688 authored Aug 25, 2024
2 parents 35434ea + b610677 commit 910604a
Show file tree
Hide file tree
Showing 3 changed files with 22 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
5 changes: 5 additions & 0 deletions src/JitterDemo/Demos/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ public static void BuildRagdoll(JVector position, Action<RigidBody>? action = nu
world.CreateConstraint<TwistAngle>(parts[(int)RagdollParts.Torso], parts[(int)RagdollParts.UpperArmRight]);
shoulderRight1.Initialize(JVector.UnitX, JVector.UnitX, AngularLimit.FromDegree(-20, 60));

shoulderLeft1.Bias = 0.01f;
shoulderRight1.Bias = 0.01f;
hipLeft1.Bias = 0.01f;
hipRight1.Bias = 0.01f;

if (world.BroadPhaseFilter is not IgnoreCollisionBetweenFilter filter)
{
filter = new IgnoreCollisionBetweenFilter();
Expand Down

0 comments on commit 910604a

Please sign in to comment.