Skip to content

Commit

Permalink
Add IDebugDrawable interface to Joint class
Browse files Browse the repository at this point in the history
  • Loading branch information
notgiven688 committed Feb 23, 2025
1 parent 3c895bc commit 1b69ddb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Jitter2/Dynamics/Joints/Joint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@

namespace Jitter2.Dynamics.Constraints;

public class Joint
public class Joint : IDebugDrawable
{
private readonly List<Constraint> constraints = new(4);
public ReadOnlyList<Constraint> Constraints => new ReadOnlyList<Constraint>(constraints);

/// <summary>
/// Add a constraint to the internal book keeping
/// Add a constraint to the internal bookkeeping
/// </summary>
protected void Register(Constraint constraint) => constraints.Add(constraint);

/// <summary>
/// Remove a constraint from the internal book keeping
/// Remove a constraint from the internal bookkeeping
/// </summary>
protected void Deregister(Constraint constraint) => constraints.Remove(constraint);

Expand Down Expand Up @@ -79,4 +79,12 @@ public void Remove()

constraints.Clear();
}

public virtual void DebugDraw(IDebugDrawer drawer)
{
foreach (var constraint in constraints)
{
constraint.DebugDraw(drawer);
}
}
}
10 changes: 10 additions & 0 deletions src/Jitter2/IDebugDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,21 @@

namespace Jitter2;

/// <summary>
/// Defines an interface for objects that can be debug-drawn.
/// </summary>
public interface IDebugDrawable
{
/// <summary>
/// Passes an <see cref="IDebugDrawer"/> to draw basic debug information for the object.
/// </summary>
/// <param name="drawer">The debug drawer used for rendering debug information.</param>
public void DebugDraw(IDebugDrawer drawer);
}

/// <summary>
/// Defines an interface for drawing debug visualization elements.
/// </summary>
public interface IDebugDrawer
{
public void DrawSegment(in JVector pA, in JVector pB);
Expand Down

0 comments on commit 1b69ddb

Please sign in to comment.