diff --git a/src/Jitter2/Collision/DynamicTree.cs b/src/Jitter2/Collision/DynamicTree.cs
index 9d55f34e..d2b4369b 100644
--- a/src/Jitter2/Collision/DynamicTree.cs
+++ b/src/Jitter2/Collision/DynamicTree.cs
@@ -274,6 +274,7 @@ private void UpdateBoundingBoxesCallback(Parallel.Batch batch)
/// The entity to update.
public void Update(T proxy) where T : class, IDynamicTreeProxy
{
+ if (proxy is IUpdatableBoundingBox sh) sh.UpdateWorldBoundingBox();
OverlapCheckRemove(root, proxy.NodePtr);
InternalRemoveProxy(proxy);
InternalAddProxy(proxy);
diff --git a/src/Jitter2/Collision/IDynamicTreeProxy.cs b/src/Jitter2/Collision/IDynamicTreeProxy.cs
index efe9b679..2aad2f1a 100644
--- a/src/Jitter2/Collision/IDynamicTreeProxy.cs
+++ b/src/Jitter2/Collision/IDynamicTreeProxy.cs
@@ -55,7 +55,7 @@ public interface IUpdatableBoundingBox
///
/// Updates the bounding box.
///
- public void UpdateWorldBoundingBox(Real dt);
+ public void UpdateWorldBoundingBox(Real dt = (Real)0.0);
}
///
diff --git a/src/Jitter2/Dynamics/Joints/HingeJoint.cs b/src/Jitter2/Dynamics/Joints/HingeJoint.cs
index a3a4121f..2f1dc020 100644
--- a/src/Jitter2/Dynamics/Joints/HingeJoint.cs
+++ b/src/Jitter2/Dynamics/Joints/HingeJoint.cs
@@ -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);
- }
}
\ No newline at end of file
diff --git a/src/Jitter2/Dynamics/Joints/Joint.cs b/src/Jitter2/Dynamics/Joints/Joint.cs
index 4cf52727..7128dead 100644
--- a/src/Jitter2/Dynamics/Joints/Joint.cs
+++ b/src/Jitter2/Dynamics/Joints/Joint.cs
@@ -26,18 +26,18 @@
namespace Jitter2.Dynamics.Constraints;
-public class Joint
+public class Joint : IDebugDrawable
{
private readonly List constraints = new(4);
public ReadOnlyList Constraints => new ReadOnlyList(constraints);
///
- /// Add a constraint to the internal book keeping
+ /// Add a constraint to the internal bookkeeping
///
protected void Register(Constraint constraint) => constraints.Add(constraint);
///
- /// Remove a constraint from the internal book keeping
+ /// Remove a constraint from the internal bookkeeping
///
protected void Deregister(Constraint constraint) => constraints.Remove(constraint);
@@ -79,4 +79,12 @@ public void Remove()
constraints.Clear();
}
+
+ public virtual void DebugDraw(IDebugDrawer drawer)
+ {
+ foreach (var constraint in constraints)
+ {
+ constraint.DebugDraw(drawer);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/Jitter2/Dynamics/Joints/PrismaticJoint.cs b/src/Jitter2/Dynamics/Joints/PrismaticJoint.cs
index 63060591..7f6b95b6 100644
--- a/src/Jitter2/Dynamics/Joints/PrismaticJoint.cs
+++ b/src/Jitter2/Dynamics/Joints/PrismaticJoint.cs
@@ -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: ..
- }
}
\ No newline at end of file
diff --git a/src/Jitter2/Dynamics/RigidBody.cs b/src/Jitter2/Dynamics/RigidBody.cs
index 0dea875f..564f3b23 100644
--- a/src/Jitter2/Dynamics/RigidBody.cs
+++ b/src/Jitter2/Dynamics/RigidBody.cs
@@ -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);
diff --git a/src/Jitter2/IDebugDrawer.cs b/src/Jitter2/IDebugDrawer.cs
index 0abb982d..de9f7523 100644
--- a/src/Jitter2/IDebugDrawer.cs
+++ b/src/Jitter2/IDebugDrawer.cs
@@ -25,11 +25,21 @@
namespace Jitter2;
+///
+/// Defines an interface for objects that can be debug-drawn.
+///
public interface IDebugDrawable
{
+ ///
+ /// Passes an to draw basic debug information for the object.
+ ///
+ /// The debug drawer used for rendering debug information.
public void DebugDraw(IDebugDrawer drawer);
}
+///
+/// Defines an interface for drawing debug visualization elements.
+///
public interface IDebugDrawer
{
public void DrawSegment(in JVector pA, in JVector pB);
diff --git a/src/Jitter2/LinearMath/Interop.cs b/src/Jitter2/LinearMath/Interop.cs
new file mode 100644
index 00000000..2703e135
--- /dev/null
+++ b/src/Jitter2/LinearMath/Interop.cs
@@ -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(ref Unsafe.AsRef(v));
+
+ public static implicit operator JVector(in Vector3 v) => new(v.X, v.Y, v.Z); // Unsafe.As(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(ref Unsafe.AsRef(q));
+
+ public static implicit operator JQuaternion(in Quaternion q) => new(q.X, q.Y, q.Z, q.W); // Unsafe.As(ref Unsafe.AsRef(q));
+}
\ No newline at end of file
diff --git a/src/Jitter2/LinearMath/JQuaternion.cs b/src/Jitter2/LinearMath/JQuaternion.cs
index 183d2310..3f493080 100644
--- a/src/Jitter2/LinearMath/JQuaternion.cs
+++ b/src/Jitter2/LinearMath/JQuaternion.cs
@@ -31,7 +31,7 @@ namespace Jitter2.LinearMath;
/// Quaternion Q = Xi + Yj + Zk + W. Uses Hamilton's definition of ij=k.
///
[StructLayout(LayoutKind.Explicit, Size = 4*sizeof(Real))]
-public struct JQuaternion : IEquatable
+public partial struct JQuaternion : IEquatable
{
[FieldOffset(0*sizeof(Real))] public Real X;
[FieldOffset(1*sizeof(Real))] public Real Y;
diff --git a/src/Jitter2/LinearMath/JVector.cs b/src/Jitter2/LinearMath/JVector.cs
index d41a3b6d..ff589572 100644
--- a/src/Jitter2/LinearMath/JVector.cs
+++ b/src/Jitter2/LinearMath/JVector.cs
@@ -31,7 +31,7 @@ namespace Jitter2.LinearMath;
/// Represents a three-dimensional vector with components of type .
///
[StructLayout(LayoutKind.Explicit, Size = 3*sizeof(Real))]
-public struct JVector : IEquatable
+public partial struct JVector : IEquatable
{
internal static JVector InternalZero;
internal static JVector Arbitrary;
diff --git a/src/Jitter2/World.cs b/src/Jitter2/World.cs
index 5b7f711f..5866d113 100644
--- a/src/Jitter2/World.cs
+++ b/src/Jitter2/World.cs
@@ -370,12 +370,6 @@ public void Remove(Arbiter arbiter)
arbiter.Handle = JHandle.Zero;
}
- internal void UpdateShape(RigidBodyShape shape)
- {
- shape.UpdateWorldBoundingBox();
- DynamicTree.Update(shape);
- }
-
internal void ActivateBodyNextStep(RigidBody body)
{
body.sleepTime = 0;
diff --git a/src/JitterDemo/Renderer/DebugRenderer.cs b/src/JitterDemo/Renderer/DebugRenderer.cs
index 86d39632..ce4b6c95 100644
--- a/src/JitterDemo/Renderer/DebugRenderer.cs
+++ b/src/JitterDemo/Renderer/DebugRenderer.cs
@@ -54,7 +54,7 @@ void main()
";
private static readonly string fshader = @"
- #version 420 core
+ #version 330 core
uniform vec4 color;