diff --git a/native/Ymir.Box3D/ymir_box3d_soa.c b/native/Ymir.Box3D/ymir_box3d_soa.c
index 861d15e..af2fe78 100644
--- a/native/Ymir.Box3D/ymir_box3d_soa.c
+++ b/native/Ymir.Box3D/ymir_box3d_soa.c
@@ -71,7 +71,7 @@ typedef struct ymir_box3d_soa_body_desc
float density;
float friction;
float restitution;
- float reserved_float;
+ float rolling_resistance; // Box3D's surface rolling resistance, >= 0; spheres and capsules roll without it
} ymir_box3d_soa_body_desc;
// A joint between two bodies, given in world space at creation: the frame has its origin at `anchor`
@@ -362,7 +362,8 @@ static int32_t ymir_soa_check_body(const ymir_box3d_soa_world* world, const ymir
{
if (d->kind > YMIR_SOA_KIND_BOX || !ymir_soa_finite3(d->position) || !ymir_soa_finite3(d->velocity) ||
!ymir_soa_finite3(d->size) || !ymir_soa_finite(d->friction) || !ymir_soa_finite(d->restitution) ||
- !ymir_soa_finite(d->density) || d->friction < 0.0f || d->restitution < 0.0f)
+ !ymir_soa_finite(d->density) || !ymir_soa_finite(d->rolling_resistance) || d->friction < 0.0f ||
+ d->restitution < 0.0f || d->rolling_resistance < 0.0f)
{
return YMIR_SOA_INVALID_ARGUMENT;
}
@@ -455,6 +456,7 @@ YMIR_EXPORT int32_t YMIR_CALL ymir_box3d_soa_add_body(
}
shape_def.baseMaterial.friction = d->friction;
shape_def.baseMaterial.restitution = d->restitution;
+ shape_def.baseMaterial.rollingResistance = d->rolling_resistance;
b3ShapeId shape;
if (d->kind == YMIR_SOA_KIND_SPHERE)
diff --git a/src/Ymir.Box3D/Box3DSoaWorld.cs b/src/Ymir.Box3D/Box3DSoaWorld.cs
index 17817b8..c6eee77 100644
--- a/src/Ymir.Box3D/Box3DSoaWorld.cs
+++ b/src/Ymir.Box3D/Box3DSoaWorld.cs
@@ -30,7 +30,7 @@ internal struct Box3DSoaBodyDesc
public float RotationX, RotationY, RotationZ, RotationW;
public float VelocityX, VelocityY, VelocityZ;
public float Size0, Size1, Size2;
- public float Density, Friction, Restitution, ReservedFloat;
+ public float Density, Friction, Restitution, RollingResistance;
}
/// Native layout of ymir_box3d_soa_joint_desc.
@@ -264,9 +264,9 @@ internal sealed class Box3DSoaWorld : IDisposable
public int AddSphere(
ulong stableId, (float X, float Y, float Z) position, float radius, float density,
(float X, float Y, float Z) velocity = default, float friction = 0.6f, float restitution = 0f,
- int parent = -1, int limb = 0) =>
+ int parent = -1, int limb = 0, float rollingResistance = 0f) =>
AddBody(Describe(Box3DSoaKind.Sphere, stableId, position, default, (radius, 0f, 0f), density,
- velocity, friction, restitution, parent, limb));
+ velocity, friction, restitution, parent, limb, rollingResistance));
/// Adds a static axis-aligned box centred at .
public int AddStaticBox(
@@ -283,9 +283,9 @@ internal sealed class Box3DSoaWorld : IDisposable
public int AddCapsule(
ulong stableId, (float X, float Y, float Z) position, float radius, float halfLength, float density,
(float X, float Y, float Z, float W) rotation = default, float friction = 0.6f, float restitution = 0f,
- int parent = -1, int limb = 0) =>
+ int parent = -1, int limb = 0, float rollingResistance = 0f) =>
AddBody(Describe(Box3DSoaKind.Capsule, stableId, position, rotation, (radius, halfLength, 0f), density,
- default, friction, restitution, parent, limb));
+ default, friction, restitution, parent, limb, rollingResistance));
/// Adds a dynamic box with the given half extents; rotation as for .
public int AddBox(
@@ -319,7 +319,7 @@ internal sealed class Box3DSoaWorld : IDisposable
private static Box3DSoaBodyDesc Describe(
Box3DSoaKind kind, ulong stableId, (float X, float Y, float Z) position,
(float X, float Y, float Z, float W) rotation, (float, float, float) size, float density,
- (float X, float Y, float Z) velocity, float friction, float restitution, int parent, int limb)
+ (float X, float Y, float Z) velocity, float friction, float restitution, int parent, int limb, float rollingResistance = 0f)
{
if (rotation == default) rotation = (0f, 0f, 0f, 1f);
return new Box3DSoaBodyDesc
@@ -329,7 +329,7 @@ internal sealed class Box3DSoaWorld : IDisposable
RotationX = rotation.X, RotationY = rotation.Y, RotationZ = rotation.Z, RotationW = rotation.W,
VelocityX = velocity.X, VelocityY = velocity.Y, VelocityZ = velocity.Z,
Size0 = size.Item1, Size1 = size.Item2, Size2 = size.Item3,
- Density = density, Friction = friction, Restitution = restitution,
+ Density = density, Friction = friction, Restitution = restitution, RollingResistance = rollingResistance,
};
}
diff --git a/src/Ymir.Box3D/Properties/AssemblyInfo.cs b/src/Ymir.Box3D/Properties/AssemblyInfo.cs
index bd44821..263a317 100644
--- a/src/Ymir.Box3D/Properties/AssemblyInfo.cs
+++ b/src/Ymir.Box3D/Properties/AssemblyInfo.cs
@@ -3,3 +3,4 @@ using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Ymir.Core")]
[assembly: InternalsVisibleTo("Ymir.Box3D.Soa.Tests")]
[assembly: InternalsVisibleTo("Lodur.Body.Ymir")]
+[assembly: InternalsVisibleTo("Lodur.Tests")]