Body regions: Head, the head body's centre
Office emitters are sensed at the head. RegionCount is 3; the connected pain box still replays the base world hash, break tick and hand track. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2026b7cb63
commit
978202009c
2 changed files with 15 additions and 7 deletions
|
|
@ -12,7 +12,7 @@ namespace Lodur.Body.Ymir
|
|||
/// <summary>The body regions perception senses at, in the order of the point arrays <see cref="HumanoidRagdoll.ReadRegions"/> fills.</summary>
|
||||
public enum Region
|
||||
{
|
||||
HandL, HandR
|
||||
HandL, HandR, Head
|
||||
}
|
||||
|
||||
/// <summary>The ragdoll's bodies, also the limb label written into the world's limb lane.</summary>
|
||||
|
|
@ -32,7 +32,7 @@ namespace Lodur.Body.Ymir
|
|||
{
|
||||
public const int MuscleCount = 12;
|
||||
public const int LimbCount = 13;
|
||||
public const int RegionCount = 2;
|
||||
public const int RegionCount = 3;
|
||||
|
||||
private const float Density = 1000f;
|
||||
private const float Friction = 0.8f;
|
||||
|
|
@ -148,7 +148,7 @@ namespace Lodur.Body.Ymir
|
|||
/// <summary>
|
||||
/// Writes each <see cref="Region"/>'s world point into the caller's arrays, one entry per region: a hand is the
|
||||
/// tip of its lower-arm capsule, the capsule's centre plus its rotation applied to (0, -(half length + radius), 0).
|
||||
/// The ragdoll has no hand body, so perception senses at this point. Allocates nothing.
|
||||
/// The ragdoll has no hand body, so perception senses at this point. The head is the head body's centre. Allocates nothing.
|
||||
/// </summary>
|
||||
public void ReadRegions(Span<float> x, Span<float> y, Span<float> z)
|
||||
{
|
||||
|
|
@ -158,7 +158,7 @@ namespace Lodur.Body.Ymir
|
|||
}
|
||||
|
||||
var v = _world.View;
|
||||
for (var r = 0; r < RegionCount; r++)
|
||||
for (var r = 0; r < (int)Region.Head; r++)
|
||||
{
|
||||
var i = _bodyLane[(int)(r == (int)Region.HandL ? Limb.LowerArmL : Limb.LowerArmR)];
|
||||
new Quat(v.RotationX[i], v.RotationY[i], v.RotationZ[i], v.RotationW[i])
|
||||
|
|
@ -167,6 +167,11 @@ namespace Lodur.Body.Ymir
|
|||
y[r] = v.PositionY[i] + dy;
|
||||
z[r] = v.PositionZ[i] + dz;
|
||||
}
|
||||
|
||||
var head = _bodyLane[(int)Limb.Head];
|
||||
x[(int)Region.Head] = v.PositionX[head];
|
||||
y[(int)Region.Head] = v.PositionY[head];
|
||||
z[(int)Region.Head] = v.PositionZ[head];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ internal sealed class ConnectedPainBox : IDisposable
|
|||
public readonly HumanoidRagdoll Ragdoll;
|
||||
public readonly Actor Actor;
|
||||
public readonly BoxStimulus[] Sources = { new BoxStimulus(Box.X, Box.Y, Box.Z, 0.12f, 0.12f, 0.12f) };
|
||||
public readonly float[] X = new float[2], Y = new float[2], Z = new float[2];
|
||||
public readonly float[] X = new float[HumanoidRagdoll.RegionCount], Y = new float[HumanoidRagdoll.RegionCount], Z = new float[HumanoidRagdoll.RegionCount];
|
||||
public readonly float[] Strength = new float[HumanoidRagdoll.MuscleCount];
|
||||
public readonly Quat[] Target = new Quat[HumanoidRagdoll.MuscleCount];
|
||||
private SplitMix64 _rng;
|
||||
|
|
@ -82,12 +82,15 @@ public sealed class ConnectedPainBoxTests
|
|||
public void ReadRegions_puts_the_hands_at_the_lower_arm_tips_at_the_creation_pose()
|
||||
{
|
||||
using var s = new RagdollScenario(seed: 1);
|
||||
var x = new float[2]; var y = new float[2]; var z = new float[2];
|
||||
var x = new float[HumanoidRagdoll.RegionCount]; var y = new float[HumanoidRagdoll.RegionCount]; var z = new float[HumanoidRagdoll.RegionCount];
|
||||
s.Ragdoll.ReadRegions(x, y, z);
|
||||
Assert.Equal(0.21f, x[(int)Region.HandL], 3);
|
||||
Assert.Equal(-0.21f, x[(int)Region.HandR], 3);
|
||||
Assert.Equal(0.96f, y[(int)Region.HandR], 3);
|
||||
Assert.Equal(0f, z[(int)Region.HandR], 3);
|
||||
Assert.Equal(0f, x[(int)Region.Head], 3); // the head body's centre, within a millimetre
|
||||
Assert.Equal(1.74f, y[(int)Region.Head], 3);
|
||||
Assert.Equal(0f, z[(int)Region.Head], 3);
|
||||
Assert.Throws<ArgumentException>(() => s.Ragdoll.ReadRegions(new float[1], y, z));
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +98,7 @@ public sealed class ConnectedPainBoxTests
|
|||
public void ReadRegions_allocates_nothing()
|
||||
{
|
||||
using var s = new RagdollScenario(seed: 1);
|
||||
var x = new float[2]; var y = new float[2]; var z = new float[2];
|
||||
var x = new float[HumanoidRagdoll.RegionCount]; var y = new float[HumanoidRagdoll.RegionCount]; var z = new float[HumanoidRagdoll.RegionCount];
|
||||
s.Ragdoll.ReadRegions(x, y, z);
|
||||
var before = GC.GetAllocatedBytesForCurrentThread();
|
||||
for (var i = 0; i < 1000; i++) s.Ragdoll.ReadRegions(x, y, z);
|
||||
|
|
|
|||
Loading…
Reference in a new issue