Skip to content

Commit

Permalink
Merge pull request #219 from notgiven688/dev
Browse files Browse the repository at this point in the history
Various
  • Loading branch information
notgiven688 authored Feb 24, 2025
2 parents afe8237 + e3048bc commit 5a422ec
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/Jitter2/Collision/DynamicTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ private void UpdateBoundingBoxesCallback(Parallel.Batch batch)
/// <param name="proxy">The entity to update.</param>
public void Update<T>(T proxy) where T : class, IDynamicTreeProxy
{
if (proxy is IUpdatableBoundingBox sh) sh.UpdateWorldBoundingBox();
OverlapCheckRemove(root, proxy.NodePtr);
InternalRemoveProxy(proxy);
InternalAddProxy(proxy);
Expand Down
2 changes: 1 addition & 1 deletion src/Jitter2/Collision/IDynamicTreeProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public interface IUpdatableBoundingBox
/// <summary>
/// Updates the bounding box.
/// </summary>
public void UpdateWorldBoundingBox(Real dt);
public void UpdateWorldBoundingBox(Real dt = (Real)0.0);
}

/// <summary>
Expand Down
6 changes: 0 additions & 6 deletions src/Jitter2/Dynamics/Joints/HingeJoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,4 @@ public HingeJoint(World world, RigidBody body1, RigidBody body2, JVector hingeCe
this(world, body1, body2, hingeCenter, hingeAxis, AngularLimit.Full, hasMotor)
{
}

public void DebugDraw(IDebugDrawer drawer)
{
HingeAngle.DebugDraw(drawer);
BallSocket.DebugDraw(drawer);
}
}
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);
}
}
}
6 changes: 0 additions & 6 deletions src/Jitter2/Dynamics/Joints/PrismaticJoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,4 @@ public PrismaticJoint(World world, RigidBody body1, RigidBody body2, JVector cen
Register(Motor);
}
}

public void DebugDraw(IDebugDrawer drawer)
{
Slider.DebugDraw(drawer);
// TODO: ..
}
}
5 changes: 3 additions & 2 deletions src/Jitter2/Dynamics/RigidBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,10 @@ public JQuaternion Orientation
private void Move()
{
UpdateWorldInertia();
foreach (RigidBodyShape shape in shapes)

foreach (var shape in shapes)
{
World.UpdateShape(shape);
World.DynamicTree.Update(shape);
}

World.ActivateBodyNextStep(this);
Expand Down
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
20 changes: 20 additions & 0 deletions src/Jitter2/LinearMath/Interop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Jitter2.LinearMath;

using System.Numerics;

// Enables implicit conversion between JVector/JQuaternion and .NET's own numeric types (Vector3 and Quaternion).
// This allows seamless interoperability with .NET libraries that use these types.

public partial struct JVector
{
public static implicit operator Vector3(in JVector v) => new((float)v.X, (float)v.Y, (float)v.Z); // Unsafe.As<JVector, Vector3>(ref Unsafe.AsRef(v));

public static implicit operator JVector(in Vector3 v) => new(v.X, v.Y, v.Z); // Unsafe.As<Vector3, JVector>(ref Unsafe.AsRef(v));
}

public partial struct JQuaternion
{
public static implicit operator Quaternion(in JQuaternion q) => new((float)q.X, (float)q.Y, (float)q.Z, (float)q.W); // Unsafe.As<JQuaternion, Quaternion>(ref Unsafe.AsRef(q));

public static implicit operator JQuaternion(in Quaternion q) => new(q.X, q.Y, q.Z, q.W); // Unsafe.As<Quaternion, JQuaternion>(ref Unsafe.AsRef(q));
}
2 changes: 1 addition & 1 deletion src/Jitter2/LinearMath/JQuaternion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Jitter2.LinearMath;
/// Quaternion Q = Xi + Yj + Zk + W. Uses Hamilton's definition of ij=k.
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 4*sizeof(Real))]
public struct JQuaternion : IEquatable<JQuaternion>
public partial struct JQuaternion : IEquatable<JQuaternion>
{
[FieldOffset(0*sizeof(Real))] public Real X;
[FieldOffset(1*sizeof(Real))] public Real Y;
Expand Down
2 changes: 1 addition & 1 deletion src/Jitter2/LinearMath/JVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Jitter2.LinearMath;
/// Represents a three-dimensional vector with components of type <see cref="Real"/>.
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 3*sizeof(Real))]
public struct JVector : IEquatable<JVector>
public partial struct JVector : IEquatable<JVector>
{
internal static JVector InternalZero;
internal static JVector Arbitrary;
Expand Down
6 changes: 0 additions & 6 deletions src/Jitter2/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,6 @@ public void Remove(Arbiter arbiter)
arbiter.Handle = JHandle<ContactData>.Zero;
}

internal void UpdateShape(RigidBodyShape shape)
{
shape.UpdateWorldBoundingBox();
DynamicTree.Update(shape);
}

internal void ActivateBodyNextStep(RigidBody body)
{
body.sleepTime = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/JitterDemo/Renderer/DebugRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void main()
";

private static readonly string fshader = @"
#version 420 core
#version 330 core
uniform vec4 color;
Expand Down

0 comments on commit 5a422ec

Please sign in to comment.