cut11b: close Soul Pass 4 HipRoll lerp wrap and minSwingRadial/maxTickDisp ground clamp
This commit is contained in:
parent
4a61834327
commit
60a1de513e
3 changed files with 168 additions and 2 deletions
|
|
@ -18,10 +18,21 @@ namespace RustToDust.Core
|
|||
public float HockFlex;
|
||||
public float AnklePitch;
|
||||
|
||||
public static float WrapAnglePi(float rad)
|
||||
{
|
||||
if (!float.IsFinite(rad))
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
while (rad > MathF.PI) rad -= MathF.Tau;
|
||||
while (rad <= -MathF.PI) rad += MathF.Tau;
|
||||
return rad;
|
||||
}
|
||||
|
||||
public static WalkerLegAngles Lerp(in WalkerLegAngles a, in WalkerLegAngles b, float t) => new()
|
||||
{
|
||||
HipPitch = a.HipPitch + (b.HipPitch - a.HipPitch) * t,
|
||||
HipRoll = a.HipRoll + (b.HipRoll - a.HipRoll) * t,
|
||||
HipRoll = WrapAnglePi(a.HipRoll + WrapAnglePi(b.HipRoll - a.HipRoll) * t),
|
||||
KneeFlex = a.KneeFlex + (b.KneeFlex - a.KneeFlex) * t,
|
||||
HockFlex = a.HockFlex + (b.HockFlex - a.HockFlex) * t,
|
||||
AnklePitch = a.AnklePitch + (b.AnklePitch - a.AnklePitch) * t
|
||||
|
|
|
|||
|
|
@ -1987,6 +1987,19 @@ namespace RustToDust.Ymir
|
|||
: (f0W.LengthSquared() > 1e-5f ? Vector2.Normalize(new Vector2(f0W.X, f0W.Z)) : Vector2.UnitY);
|
||||
desiredSole.X = curHip.X + outDir.X * minSwingRadial;
|
||||
desiredSole.Z = curHip.Z + outDir.Y * minSwingRadial;
|
||||
var pushedHit = SampleGroundAt(terrain, world, desiredSole.X, desiredSole.Z, comPos.Y + 0.8f);
|
||||
float pushedUnderY = MathF.Min(pushedHit.SurfaceY, ws.FootSole[i].Y + maxSwingStep * 0.90f);
|
||||
float pushedMinY = pushedUnderY + 0.10f * scale * legEnv;
|
||||
if (desiredSole.Y < pushedMinY)
|
||||
{
|
||||
float swingMaxR = geom.Legs[i].MaxLegReach * scale * 0.995f;
|
||||
Vector3 swingHip = comPos + Vector3.Transform(ws.PelvisOffset, qYaw) + Vector3.Transform(geom.Legs[i].HipInCom * scale, qYaw);
|
||||
Vector3 candAnk = new Vector3(desiredSole.X, pushedMinY, desiredSole.Z) + pushedHit.Normal * (geom.Legs[i].AnkleH * scale);
|
||||
if ((candAnk - swingHip).Length() <= swingMaxR)
|
||||
{
|
||||
desiredSole.Y = pushedMinY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Vector3 swingStep = desiredSole - ws.FootSole[i];
|
||||
|
|
@ -2351,9 +2364,18 @@ namespace RustToDust.Ymir
|
|||
if (tickLen > maxTickDisp && tickLen > 1e-5f)
|
||||
{
|
||||
Vector3 capped = startS + tickDelta * (maxTickDisp / tickLen);
|
||||
float tickMaxR = maxReach * 1.025f + 0.029f;
|
||||
var capGround = SampleGroundAt(terrain, world, capped.X, capped.Z, comPos.Y + 0.8f);
|
||||
if (capped.Y < capGround.SurfaceY &&
|
||||
capGround.SurfaceY <= startS.Y + maxTickDisp * 0.95f &&
|
||||
MathF.Abs((capGround.SurfaceY + capGround.Normal.Y * ankleH) - hipTotalW.Y) < tickMaxR * 0.98f)
|
||||
{
|
||||
ProjectSoleAboveGroundWithinReach(hipTotalW, comPos, ankleH, tickMaxR, terrain, world, comPos.Y + 0.8f, 0f, ref capped, out Vector3 capNorm);
|
||||
ws.FootNormal[i] = capNorm;
|
||||
}
|
||||
Vector3 cappedAnk = capped + ws.FootNormal[i] * ankleH;
|
||||
float cappedDist = (cappedAnk - hipTotalW).Length();
|
||||
if (cappedDist > maxReach * 1.025f + 0.029f && cappedDist > 1e-5f)
|
||||
if (cappedDist > tickMaxR && cappedDist > 1e-5f)
|
||||
{
|
||||
capped = (hipTotalW + (cappedAnk - hipTotalW) * (maxReach / cappedDist)) - ws.FootNormal[i] * ankleH;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2527,5 +2527,138 @@ namespace RustToDust.Tests
|
|||
Assert.True(maxFlatKneeFlex < 2.90f, $"Manticore flat knee near saturation {maxFlatKneeFlex:F3} rad");
|
||||
Assert.True(maxKneeFlex < 3.05f, $"Manticore knee saturated at {maxKneeFlex:F3} rad");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SoulPass4_WalkerSnapshotInterpolate_HipRollShortestAngleAcrossPi()
|
||||
{
|
||||
var prev = new WalkerVisualSnapshot
|
||||
{
|
||||
LegCount = 4,
|
||||
GeomScale = 1f,
|
||||
IsArachnidUp = true,
|
||||
ComPos = Vector3.Zero,
|
||||
ComRot = Quaternion.Identity
|
||||
};
|
||||
var curr = prev;
|
||||
prev.LegAngles[0] = new WalkerLegAngles { HipRoll = -2.877f, HipPitch = 0.4f, KneeFlex = 1.2f };
|
||||
curr.LegAngles[0] = new WalkerLegAngles { HipRoll = +3.111f, HipPitch = 0.6f, KneeFlex = 1.4f };
|
||||
prev.FootNormal[0] = Vector3.UnitY;
|
||||
curr.FootNormal[0] = Vector3.UnitY;
|
||||
|
||||
var mid = WalkerVisualSnapshot.Interpolate(in prev, in curr, 0.5f);
|
||||
float distToPi = MathF.Abs(MathF.PI - MathF.Abs(mid.LegAngles[0].HipRoll));
|
||||
Assert.True(distToPi <= 0.15f,
|
||||
$"HipRoll interpolated the long way through 0: mid={mid.LegAngles[0].HipRoll:F4} (distToPi={distToPi:F4})");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SoulPass4_ManticoreDuneDownhillAndSionValley_MinSoleRelAboveGround()
|
||||
{
|
||||
// 1. Desert DuneDownhill (tallest DuneRidge crest -> downhill sprint + turn)
|
||||
using (var desert = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true))
|
||||
{
|
||||
for (int i = 1; i < desert.State.Contenders.Count; i++)
|
||||
{
|
||||
desert.SetContenderPose(i, 900f + i * 16f, 900f);
|
||||
}
|
||||
|
||||
TerrainBrush? ridge = null;
|
||||
float bestH = float.NegativeInfinity;
|
||||
foreach (var b in desert.State.Terrain.Brushes)
|
||||
{
|
||||
if (b.Kind == TerrainBrushKind.DuneRidge && b.HeightDelta > bestH)
|
||||
{
|
||||
bestH = b.HeightDelta;
|
||||
ridge = b;
|
||||
}
|
||||
}
|
||||
Assert.True(ridge.HasValue);
|
||||
var r = ridge!.Value;
|
||||
desert.SetContenderPose(0, r.X, r.Z, 0f);
|
||||
desert.State.SpawnChassisDrop(r.X, r.Z, Catalog.Manticore);
|
||||
Assert.True(desert.TrySwapNearbyChassis(0));
|
||||
desert.SetContenderPose(0, r.X, r.Z, 0f);
|
||||
|
||||
var player = desert.State.Contenders[0];
|
||||
var ws = desert.GetWalkerState(true, player.Id)!;
|
||||
float minSoleRel = float.PositiveInfinity;
|
||||
for (int t = 0; t < 180; t++)
|
||||
{
|
||||
float steer = MathF.Sin(t * 0.08f) * 0.55f;
|
||||
float aimYaw = player.Yaw + steer * 0.6f;
|
||||
desert.SetHumanInput(0, new PlayerInput(
|
||||
1.0f, steer,
|
||||
player.X + 40f * MathF.Sin(aimYaw),
|
||||
player.Z + 40f * MathF.Cos(aimYaw),
|
||||
false, false, false));
|
||||
desert.Step();
|
||||
|
||||
for (int i = 0; i < ws.Geom.LegCount; i++)
|
||||
{
|
||||
float gY = desert.QueryDropSurface(ws.FootSole[i].X, ws.FootSole[i].Z, 0f, player.Y + 1.0f).SurfaceY;
|
||||
minSoleRel = MathF.Min(minSoleRel, ws.FootSole[i].Y - gY);
|
||||
}
|
||||
}
|
||||
_output.WriteLine($"Manticore Desert DuneDownhill: minSoleRel={minSoleRel:F4}m");
|
||||
Assert.True(minSoleRel >= -0.05f, $"Manticore Desert DuneDownhill sole dipped underground: {minSoleRel:F4}m < -0.05m");
|
||||
}
|
||||
|
||||
// 2. Sion Valley (low valley/slope clear of buildings with turning sprint)
|
||||
using (var sion = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true))
|
||||
{
|
||||
for (int i = 1; i < sion.State.Contenders.Count; i++)
|
||||
{
|
||||
sion.SetContenderPose(i, 900f + i * 16f, 900f);
|
||||
}
|
||||
|
||||
var sionMap = sion.State.SionMap!;
|
||||
(float X, float Z, float Yaw) valleySite = default;
|
||||
float bestMinNy = 1f;
|
||||
for (float r = 40f; r <= 900f; r += 25f)
|
||||
{
|
||||
for (int a = 0; a < 48; a++)
|
||||
{
|
||||
float ang = a * (MathF.Tau / 48f);
|
||||
float x = MathF.Cos(ang) * r;
|
||||
float z = MathF.Sin(ang) * r;
|
||||
if (sionMap.IsInsideAnyBuildingXz(x, z, 28f)) continue;
|
||||
var (nx, ny, nz) = sion.State.Terrain.SampleNormal(x, z);
|
||||
if (ny >= 0.78f && ny <= 0.90f && ny < bestMinNy)
|
||||
{
|
||||
bestMinNy = ny;
|
||||
valleySite = (x, z, MathF.Atan2(nx, nz)); // start facing downhill into valley
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sion.SetContenderPose(0, valleySite.X, valleySite.Z, valleySite.Yaw);
|
||||
sion.State.SpawnChassisDrop(valleySite.X, valleySite.Z, Catalog.Manticore);
|
||||
Assert.True(sion.TrySwapNearbyChassis(0));
|
||||
sion.SetContenderPose(0, valleySite.X, valleySite.Z, valleySite.Yaw);
|
||||
|
||||
var player = sion.State.Contenders[0];
|
||||
var ws = sion.GetWalkerState(true, player.Id)!;
|
||||
float minSoleRel = float.PositiveInfinity;
|
||||
for (int t = 0; t < 180; t++)
|
||||
{
|
||||
float steer = MathF.Sin(t * 0.08f) * 0.55f;
|
||||
float aimYaw = player.Yaw + steer * 0.6f;
|
||||
sion.SetHumanInput(0, new PlayerInput(
|
||||
1.0f, steer,
|
||||
player.X + 40f * MathF.Sin(aimYaw),
|
||||
player.Z + 40f * MathF.Cos(aimYaw),
|
||||
false, false, false));
|
||||
sion.Step();
|
||||
|
||||
for (int i = 0; i < ws.Geom.LegCount; i++)
|
||||
{
|
||||
float gY = sion.QueryDropSurface(ws.FootSole[i].X, ws.FootSole[i].Z, 0f, player.Y + 1.0f).SurfaceY;
|
||||
minSoleRel = MathF.Min(minSoleRel, ws.FootSole[i].Y - gY);
|
||||
}
|
||||
}
|
||||
_output.WriteLine($"Manticore Sion Valley: minSoleRel={minSoleRel:F4}m");
|
||||
Assert.True(minSoleRel >= -0.05f, $"Manticore Sion Valley sole dipped underground: {minSoleRel:F4}m < -0.05m");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue