SoA world: rolling resistance on the body descriptor
A bare sphere or capsule rolls on without it, so a fallen head never settles. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
02276363fc
commit
b96ad34b0b
3 changed files with 12 additions and 9 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>Native layout of <c>ymir_box3d_soa_joint_desc</c>.</summary>
|
||||
|
|
@ -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));
|
||||
|
||||
/// <summary>Adds a static axis-aligned box centred at <paramref name="position"/>.</summary>
|
||||
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));
|
||||
|
||||
/// <summary>Adds a dynamic box with the given half extents; rotation as for <see cref="AddCapsule"/>.</summary>
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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")]
|
||||
|
|
|
|||
Loading…
Reference in a new issue