wip(cut11b): Option A walker capsule + Catto PreStep/TryStep/PostStep + ZMP/foot-lock gait (16/17 HybridBWalkerTests pass; exemplar_frame Phase B delta remaining)
This commit is contained in:
parent
42b17c168e
commit
a1c44ebe55
8 changed files with 2033 additions and 1105 deletions
|
|
@ -96,6 +96,7 @@ public static class VehicleRigAnimator
|
|||
{
|
||||
public required WalkerGeometrySpec Geom;
|
||||
public required WalkerLegBinding[] Legs;
|
||||
public required Transform3D RestModelTransform;
|
||||
}
|
||||
|
||||
public sealed class RigState
|
||||
|
|
@ -440,11 +441,22 @@ public static class VehicleRigAnimator
|
|||
return;
|
||||
}
|
||||
|
||||
float leanPitch = float.IsFinite(snap.LeanPitch) ? snap.LeanPitch : 0f;
|
||||
float leanRoll = float.IsFinite(snap.LeanRoll) ? snap.LeanRoll : 0f;
|
||||
var pelvisOffset = float.IsFinite(snap.PelvisOffset.X) && float.IsFinite(snap.PelvisOffset.Y) && float.IsFinite(snap.PelvisOffset.Z)
|
||||
? snap.PelvisOffset
|
||||
: System.Numerics.Vector3.Zero;
|
||||
|
||||
var qLean = System.Numerics.Quaternion.CreateFromYawPitchRoll(0f, leanPitch, leanRoll);
|
||||
Basis leanBasis = new Basis(new Quaternion(qLean.X, qLean.Y, qLean.Z, qLean.W));
|
||||
visual.ModelRoot.Transform = new Transform3D(leanBasis, ToGodot(pelvisOffset)) * rig.RestModelTransform;
|
||||
|
||||
var geom = rig.Geom;
|
||||
var bodyRotSys = snap.ComRot.LengthSquared() < 1e-6f
|
||||
? System.Numerics.Quaternion.Identity
|
||||
: System.Numerics.Quaternion.Normalize(snap.ComRot);
|
||||
var bodyRotInv = System.Numerics.Quaternion.Conjugate(bodyRotSys);
|
||||
var qTotal = System.Numerics.Quaternion.Normalize(bodyRotSys * qLean);
|
||||
var bodyRotInv = System.Numerics.Quaternion.Conjugate(qTotal);
|
||||
|
||||
int count = Math.Min(rig.Legs.Length, snap.LegCount);
|
||||
for (int i = 0; i < count; i++)
|
||||
|
|
@ -740,7 +752,8 @@ public static class VehicleRigAnimator
|
|||
return new WalkerVisualRig
|
||||
{
|
||||
Geom = geom,
|
||||
Legs = legs
|
||||
Legs = legs,
|
||||
RestModelTransform = visual.ModelRoot.Transform
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ public sealed class WalkerFootstepTracker
|
|||
Vector3 footWorld;
|
||||
if (liveFoot.HasValue)
|
||||
{
|
||||
float fy = terrain.SampleHeight(liveFoot.Value.X, liveFoot.Value.Z);
|
||||
float fy = MathF.Max(liveFoot.Value.Y, terrain.SampleHeight(liveFoot.Value.X, liveFoot.Value.Z));
|
||||
footWorld = new Vector3(liveFoot.Value.X, fy, liveFoot.Value.Z);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -36,6 +36,9 @@ namespace RustToDust.Core
|
|||
public bool IsArachnidUp;
|
||||
public Vector3 ComPos;
|
||||
public Quaternion ComRot;
|
||||
public Vector3 PelvisOffset;
|
||||
public float LeanPitch;
|
||||
public float LeanRoll;
|
||||
public LegArray4<WalkerLegAngles> LegAngles;
|
||||
public LegArray4<Vector3> FootNormal;
|
||||
public LegArray4<float> LoadG;
|
||||
|
|
@ -57,7 +60,10 @@ namespace RustToDust.Core
|
|||
IsDigitigrade = curr.IsDigitigrade,
|
||||
IsArachnidUp = curr.IsArachnidUp,
|
||||
ComPos = Vector3.Lerp(prev.ComPos, curr.ComPos, t),
|
||||
ComRot = Quaternion.Slerp(q0, q1, t)
|
||||
ComRot = Quaternion.Slerp(q0, q1, t),
|
||||
PelvisOffset = Vector3.Lerp(prev.PelvisOffset, curr.PelvisOffset, t),
|
||||
LeanPitch = prev.LeanPitch + (curr.LeanPitch - prev.LeanPitch) * t,
|
||||
LeanRoll = prev.LeanRoll + (curr.LeanRoll - prev.LeanRoll) * t
|
||||
};
|
||||
|
||||
for (int i = 0; i < curr.LegCount; i++)
|
||||
|
|
|
|||
|
|
@ -945,27 +945,68 @@ namespace RustToDust.Net
|
|||
}
|
||||
|
||||
var spec = local.Grid.Spec;
|
||||
if (spec.IsWalker)
|
||||
{
|
||||
var qNorm = NormalizeQuat(rot);
|
||||
var fwdYaw = Vector3.Transform(Vector3.UnitZ, qNorm);
|
||||
float yaw = (fwdYaw.X * fwdYaw.X + fwdYaw.Z * fwdYaw.Z) > 1e-6f ? MathF.Atan2(fwdYaw.X, fwdYaw.Z) : local.Yaw;
|
||||
var qYaw = Quaternion.CreateFromAxisAngle(Vector3.UnitY, yaw);
|
||||
|
||||
WalkerLocomotion.GetWalkerCapsuleParams(spec, out float capR, out float capHalfL);
|
||||
float density = WalkerLocomotion.GetWalkerCapsuleDensity(spec, capR, capHalfL);
|
||||
var handle = _predWorld.AddCapsule(
|
||||
ArenaSession.ContenderStableIdBase + (ulong)local.Id,
|
||||
(pos.X, pos.Y, pos.Z),
|
||||
capR,
|
||||
capHalfL,
|
||||
density,
|
||||
(qYaw.X, qYaw.Y, qYaw.Z, qYaw.W),
|
||||
friction: 0.0f,
|
||||
restitution: 0.0f,
|
||||
flags: Box3DSoaBodyFlags.LockAngularX
|
||||
| Box3DSoaBodyFlags.LockAngularZ
|
||||
| Box3DSoaBodyFlags.DisableContactRecycling);
|
||||
_predBody = handle;
|
||||
|
||||
_predWorld.SetBodyMotion(
|
||||
handle,
|
||||
linearVelocity: (vel.X, vel.Y, vel.Z),
|
||||
angularVelocity: (0f, angVel.Y, 0f));
|
||||
|
||||
if (_predWalker is null || !string.Equals(_predChassisId, spec.Id, StringComparison.Ordinal))
|
||||
{
|
||||
_predWalker = new WalkerState(spec);
|
||||
_predWalker.InitializePose(pos, qYaw, spec.MassKg, _viewState.Terrain, _predWorld, handle.Lane);
|
||||
}
|
||||
else
|
||||
{
|
||||
_predWalker.SyncBodyPoseOnly(pos, qYaw, spec.MassKg);
|
||||
}
|
||||
_predChassisId = spec.Id;
|
||||
return;
|
||||
}
|
||||
|
||||
float physHalfH = ArenaSession.GetPhysicsHalfHeight(spec);
|
||||
float volume = 8f * spec.HalfWidth * physHalfH * spec.HalfLength;
|
||||
float density = spec.MassKg / MathF.Max(0.1f, volume);
|
||||
float boxDensity = spec.MassKg / MathF.Max(0.1f, volume);
|
||||
|
||||
var handle = _predWorld.AddBox(
|
||||
var boxHandle = _predWorld.AddBox(
|
||||
ArenaSession.ContenderStableIdBase + (ulong)local.Id,
|
||||
(pos.X, pos.Y, pos.Z),
|
||||
(spec.HalfWidth, physHalfH, spec.HalfLength),
|
||||
density,
|
||||
boxDensity,
|
||||
(rot.X, rot.Y, rot.Z, rot.W),
|
||||
friction: 0.2f,
|
||||
restitution: 0.1f);
|
||||
_predBody = handle;
|
||||
_predBody = boxHandle;
|
||||
|
||||
var v = _predWorld.View;
|
||||
float mass = v.Mass[handle.Lane];
|
||||
float mass = v.Mass[boxHandle.Lane];
|
||||
if (mass > 0f)
|
||||
{
|
||||
if (vel.LengthSquared() > 1e-8f)
|
||||
{
|
||||
_predWorld.ApplyImpulse(handle.Lane, (vel.X * mass, vel.Y * mass, vel.Z * mass), (pos.X, pos.Y, pos.Z));
|
||||
_predWorld.ApplyImpulse(boxHandle.Lane, (vel.X * mass, vel.Y * mass, vel.Z * mass), (pos.X, pos.Y, pos.Z));
|
||||
}
|
||||
if (angVel.LengthSquared() > 1e-6f)
|
||||
{
|
||||
|
|
@ -981,28 +1022,13 @@ namespace RustToDust.Net
|
|||
{
|
||||
r = Vector3.Normalize(r);
|
||||
Vector3 j = Vector3.Cross(L, r) * 0.5f;
|
||||
_predWorld.ApplyImpulse(handle.Lane, (j.X, j.Y, j.Z), (pos.X + r.X, pos.Y + r.Y, pos.Z + r.Z));
|
||||
_predWorld.ApplyImpulse(handle.Lane, (-j.X, -j.Y, -j.Z), (pos.X - r.X, pos.Y - r.Y, pos.Z - r.Z));
|
||||
_predWorld.ApplyImpulse(boxHandle.Lane, (j.X, j.Y, j.Z), (pos.X + r.X, pos.Y + r.Y, pos.Z + r.Z));
|
||||
_predWorld.ApplyImpulse(boxHandle.Lane, (-j.X, -j.Y, -j.Z), (pos.X - r.X, pos.Y - r.Y, pos.Z - r.Z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (spec.IsWalker)
|
||||
{
|
||||
if (_predWalker is null || !string.Equals(_predChassisId, spec.Id, StringComparison.Ordinal))
|
||||
{
|
||||
_predWalker = new WalkerState(spec);
|
||||
_predWalker.InitializePose(pos, rot, spec.MassKg, _viewState.Terrain);
|
||||
}
|
||||
else
|
||||
{
|
||||
_predWalker.SyncBodyPoseOnly(pos, rot, spec.MassKg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_predWalker = null;
|
||||
}
|
||||
_predWalker = null;
|
||||
_predChassisId = spec.Id;
|
||||
}
|
||||
|
||||
|
|
@ -1136,15 +1162,29 @@ namespace RustToDust.Net
|
|||
int subSteps = _viewState.MapKind == ArenaMapKind.Sion ? 1 : ArenaSession.SubStepCount;
|
||||
ArenaSession.StepContenderPhysicsDrive(
|
||||
local,
|
||||
_predWorld.View,
|
||||
_predBody.Value.Lane,
|
||||
_predWorld,
|
||||
_predBody.Value,
|
||||
_viewState.Terrain,
|
||||
_viewState.MapKind,
|
||||
_predWalker,
|
||||
ArenaSession.FixedDt,
|
||||
injectEngineHeat: false,
|
||||
world: _predWorld);
|
||||
injectEngineHeat: false);
|
||||
_predWorld.Step(ArenaSession.FixedDt, subSteps);
|
||||
if (local.Grid.Spec.IsWalker && _predWalker is not null)
|
||||
{
|
||||
float predMass = _predWorld.View.Mass[_predBody.Value.Lane];
|
||||
if (predMass > 0f)
|
||||
{
|
||||
WalkerLocomotion.PostStepWalker(
|
||||
_predWalker,
|
||||
local.Grid,
|
||||
_viewState.Terrain,
|
||||
_predWorld,
|
||||
_predBody.Value,
|
||||
predMass,
|
||||
ArenaSession.FixedDt);
|
||||
}
|
||||
}
|
||||
ArenaSession.SyncContenderPoseFromLane(local, _predWorld.View, _predBody.Value.Lane, _predWalker);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -164,6 +164,8 @@ namespace RustToDust.Net
|
|||
public const int CultMeshLatestOverheadBytes = 52;
|
||||
public const int MaxLatestFrameBytes = MaxLatestDatagramBytes - CultNetRudpLatestOverheadBytes; // 1110 bytes
|
||||
public const int MaxLatestPayloadBytes = MaxLatestFrameBytes - CultMeshLatestOverheadBytes; // 1058 bytes
|
||||
private const float MaxWirePelvisOffsetM = 1.27f;
|
||||
private const float MaxWireLeanRad = 15f * (MathF.PI / 180f);
|
||||
|
||||
public static byte[] WrapLatest(ReadOnlySpan<byte> payload, long producerEpoch, long sequence, string schemaId = SchemaLatestId)
|
||||
{
|
||||
|
|
@ -462,13 +464,18 @@ namespace RustToDust.Net
|
|||
{
|
||||
var w = pvsWalkers[i];
|
||||
int legCount = Math.Clamp(w.Snapshot.LegCount, 0, 4);
|
||||
int bytesNeeded = 2 + legCount * 13;
|
||||
int bytesNeeded = 7 + legCount * 13;
|
||||
if (offset + bytesNeeded > MaxLatestPayloadBytes - 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
buf[offset++] = (byte)((w.IsContender ? 0x80 : 0x00) | (w.EntityId & 0x7F));
|
||||
buf[offset++] = (byte)legCount;
|
||||
buf[offset++] = EncodeSnorm8(w.Snapshot.PelvisOffset.X / MaxWirePelvisOffsetM);
|
||||
buf[offset++] = EncodeSnorm8(w.Snapshot.PelvisOffset.Y / MaxWirePelvisOffsetM);
|
||||
buf[offset++] = EncodeSnorm8(w.Snapshot.PelvisOffset.Z / MaxWirePelvisOffsetM);
|
||||
buf[offset++] = EncodeSnorm8(w.Snapshot.LeanPitch / MaxWireLeanRad);
|
||||
buf[offset++] = EncodeSnorm8(w.Snapshot.LeanRoll / MaxWireLeanRad);
|
||||
for (int l = 0; l < legCount; l++)
|
||||
{
|
||||
var ang = w.Snapshot.LegAngles[l];
|
||||
|
|
@ -635,8 +642,18 @@ namespace RustToDust.Net
|
|||
bool isContender = (tag & 0x80) != 0;
|
||||
byte entityId = (byte)(tag & 0x7F);
|
||||
int legCount = span[offset++];
|
||||
if (legCount > 4 || offset + legCount * 13 > span.Length) return false;
|
||||
var snap = new WalkerVisualSnapshot { LegCount = legCount };
|
||||
if (legCount > 4 || offset + 5 + legCount * 13 > span.Length) return false;
|
||||
var snap = new WalkerVisualSnapshot
|
||||
{
|
||||
LegCount = legCount,
|
||||
PelvisOffset = new Vector3(
|
||||
DecodeSnorm8(span[offset]) * MaxWirePelvisOffsetM,
|
||||
DecodeSnorm8(span[offset + 1]) * MaxWirePelvisOffsetM,
|
||||
DecodeSnorm8(span[offset + 2]) * MaxWirePelvisOffsetM),
|
||||
LeanPitch = DecodeSnorm8(span[offset + 3]) * MaxWireLeanRad,
|
||||
LeanRoll = DecodeSnorm8(span[offset + 4]) * MaxWireLeanRad
|
||||
};
|
||||
offset += 5;
|
||||
for (int l = 0; l < legCount; l++)
|
||||
{
|
||||
snap.LegAngles[l] = new WalkerLegAngles
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ namespace RustToDust.Ymir
|
|||
public const int SubStepCount = 4;
|
||||
public const int WorldBodyCapacity = 384;
|
||||
|
||||
private const ulong GroundStableId = 1;
|
||||
private const ulong StaticBoxStableIdBase = 10;
|
||||
private const ulong StaticMeshStableIdBase = 100;
|
||||
internal const ulong GroundStableId = 1;
|
||||
internal const ulong StaticBoxStableIdBase = 10;
|
||||
internal const ulong StaticMeshStableIdBase = 100;
|
||||
public const ulong ContenderStableIdBase = 1000;
|
||||
private const ulong SpectatorStableIdBase = 3000;
|
||||
|
||||
|
|
@ -661,6 +661,7 @@ namespace RustToDust.Ymir
|
|||
|
||||
ApplyPhysicsDrives();
|
||||
_world.Step(FixedDt, subSteps);
|
||||
PostStepWalkers();
|
||||
SyncBodiesFromWorld();
|
||||
|
||||
UpdateObserverDetectionMemories();
|
||||
|
|
@ -682,6 +683,7 @@ namespace RustToDust.Ymir
|
|||
ApplyPhysicsDrives();
|
||||
long t3 = Stopwatch.GetTimestamp();
|
||||
_world.Step(FixedDt, subSteps);
|
||||
PostStepWalkers();
|
||||
long t4 = Stopwatch.GetTimestamp();
|
||||
SyncBodiesFromWorld();
|
||||
long t5 = Stopwatch.GetTimestamp();
|
||||
|
|
@ -1008,7 +1010,7 @@ namespace RustToDust.Ymir
|
|||
|
||||
public static float GetPhysicsHalfHeight(ChassisSpec spec) =>
|
||||
spec.IsWalker
|
||||
? spec.HalfHeight * (spec.Plane == GridPlane.Dorsal ? 0.62f : 0.72f)
|
||||
? WalkerLocomotion.GetRideHeight(spec)
|
||||
: spec.HalfHeight;
|
||||
|
||||
private void SpawnContenderBody(ContenderState c)
|
||||
|
|
@ -1019,8 +1021,6 @@ namespace RustToDust.Ymir
|
|||
}
|
||||
var spec = c.Grid.Spec;
|
||||
float physHalfH = GetPhysicsHalfHeight(spec);
|
||||
float volume = 8f * spec.HalfWidth * physHalfH * spec.HalfLength;
|
||||
float density = spec.MassKg / MathF.Max(0.1f, volume);
|
||||
Quaternion q;
|
||||
float spawnY;
|
||||
float initVelY = 0f;
|
||||
|
|
@ -1028,56 +1028,75 @@ namespace RustToDust.Ymir
|
|||
|
||||
if (c.HasTouchdownPose)
|
||||
{
|
||||
q = new Quaternion(c.CurrRotX, c.CurrRotY, c.CurrRotZ, c.CurrRotW);
|
||||
q = q.LengthSquared() < 1e-6f ? Quaternion.CreateFromAxisAngle(Vector3.UnitY, c.Yaw) : Quaternion.Normalize(q);
|
||||
spawnY = c.Y;
|
||||
var qRaw = new Quaternion(c.CurrRotX, c.CurrRotY, c.CurrRotZ, c.CurrRotW);
|
||||
qRaw = qRaw.LengthSquared() < 1e-6f ? Quaternion.CreateFromAxisAngle(Vector3.UnitY, c.Yaw) : Quaternion.Normalize(qRaw);
|
||||
if (spec.IsWalker)
|
||||
{
|
||||
var fwdYaw = Vector3.Transform(Vector3.UnitZ, qRaw);
|
||||
float yaw = (fwdYaw.X * fwdYaw.X + fwdYaw.Z * fwdYaw.Z) > 1e-6f ? MathF.Atan2(fwdYaw.X, fwdYaw.Z) : c.Yaw;
|
||||
q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, yaw);
|
||||
c.Yaw = yaw;
|
||||
spawnY = MathF.Max(c.Y, State.Terrain.SampleHeight(c.X, c.Z) + physHalfH);
|
||||
c.Y = spawnY;
|
||||
}
|
||||
else
|
||||
{
|
||||
q = qRaw;
|
||||
spawnY = c.Y;
|
||||
}
|
||||
initVelY = c.VelY;
|
||||
}
|
||||
else
|
||||
{
|
||||
q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, c.Yaw);
|
||||
float clearance = spec.IsVtol
|
||||
? Math.Clamp(c.TargetHoverAltAgl, MatchRules.VtolMinClearanceAgl, MathF.Max(MatchRules.VtolMinClearanceAgl, spec.HoverMaxAltitudeM))
|
||||
: 0.15f;
|
||||
spawnY = State.Terrain.SampleHeight(c.X, c.Z) + spec.HalfHeight + clearance;
|
||||
if (spec.IsWalker && spec.Plane == GridPlane.Dorsal)
|
||||
if (spec.IsWalker)
|
||||
{
|
||||
var (nx, ny, nz) = State.Terrain.SampleNormal(c.X, c.Z);
|
||||
Vector3 centerNorm = new Vector3(nx, ny, nz);
|
||||
centerNorm = centerNorm.LengthSquared() > 1e-6f ? Vector3.Normalize(centerNorm) : Vector3.UnitY;
|
||||
Vector3 fwd = Vector3.Transform(Vector3.UnitZ, q);
|
||||
fwd.Y = 0f;
|
||||
fwd = fwd.LengthSquared() > 1e-5f ? Vector3.Normalize(fwd) : Vector3.UnitZ;
|
||||
Vector3 right = Vector3.Cross(fwd, Vector3.UnitY);
|
||||
Vector3 hullSlope = WalkerLocomotion.ComputeHullSlopeNormal(State.Terrain, c.X, c.Z, fwd, right, spec.HalfWidth, spec.HalfLength, centerNorm, out _);
|
||||
q = WalkerLocomotion.AlignUpToSlope(q, hullSlope, 0.90f, 0.350f);
|
||||
|
||||
float minCornerClr = float.PositiveInfinity;
|
||||
foreach (float sx in new[] { -spec.HalfWidth, spec.HalfWidth })
|
||||
{
|
||||
foreach (float sz in new[] { -spec.HalfLength, spec.HalfLength })
|
||||
{
|
||||
Vector3 corner = new Vector3(c.X, spawnY, c.Z) + Vector3.Transform(new Vector3(sx, -physHalfH, sz), q);
|
||||
float clr = corner.Y - State.Terrain.SampleHeight(corner.X, corner.Z);
|
||||
if (clr < minCornerClr) minCornerClr = clr;
|
||||
}
|
||||
}
|
||||
if (minCornerClr < 0.25f)
|
||||
{
|
||||
spawnY += MathF.Min(1.2f, 0.25f - minCornerClr);
|
||||
}
|
||||
float terrY = State.Terrain.SampleHeight(c.X, c.Z);
|
||||
var surf = WalkerLocomotion.SampleGroundAt(State.Terrain, _world, c.X, c.Z, terrY + 6.0f);
|
||||
WalkerLocomotion.GetWalkerCapsuleParams(spec, out float spawnCapR, out float spawnCapHalfL);
|
||||
spawnY = MathF.Max(terrY, surf.SurfaceY) + spawnCapHalfL + spawnCapR / Math.Clamp(surf.Normal.Y, 0.78f, 1f) + 0.02f;
|
||||
}
|
||||
else
|
||||
{
|
||||
float clearance = spec.IsVtol
|
||||
? Math.Clamp(c.TargetHoverAltAgl, MatchRules.VtolMinClearanceAgl, MathF.Max(MatchRules.VtolMinClearanceAgl, spec.HoverMaxAltitudeM))
|
||||
: 0.15f;
|
||||
spawnY = State.Terrain.SampleHeight(c.X, c.Z) + spec.HalfHeight + clearance;
|
||||
}
|
||||
c.Y = spawnY;
|
||||
}
|
||||
|
||||
var handle = _world.AddBox(
|
||||
stableId,
|
||||
(c.X, spawnY, c.Z),
|
||||
(spec.HalfWidth, physHalfH, spec.HalfLength),
|
||||
density,
|
||||
(q.X, q.Y, q.Z, q.W),
|
||||
friction: 0.2f,
|
||||
restitution: 0.1f);
|
||||
Box3DSoaBodyHandle handle;
|
||||
if (spec.IsWalker)
|
||||
{
|
||||
WalkerLocomotion.GetWalkerCapsuleParams(spec, out float capR, out float capHalfL);
|
||||
float density = WalkerLocomotion.GetWalkerCapsuleDensity(spec, capR, capHalfL);
|
||||
handle = _world.AddCapsule(
|
||||
stableId,
|
||||
(c.X, spawnY, c.Z),
|
||||
capR,
|
||||
capHalfL,
|
||||
density,
|
||||
(q.X, q.Y, q.Z, q.W),
|
||||
friction: 0.0f,
|
||||
restitution: 0.0f,
|
||||
flags: Box3DSoaBodyFlags.LockAngularX
|
||||
| Box3DSoaBodyFlags.LockAngularZ
|
||||
| Box3DSoaBodyFlags.DisableContactRecycling);
|
||||
}
|
||||
else
|
||||
{
|
||||
float volume = 8f * spec.HalfWidth * physHalfH * spec.HalfLength;
|
||||
float density = spec.MassKg / MathF.Max(0.1f, volume);
|
||||
handle = _world.AddBox(
|
||||
stableId,
|
||||
(c.X, spawnY, c.Z),
|
||||
(spec.HalfWidth, physHalfH, spec.HalfLength),
|
||||
density,
|
||||
(q.X, q.Y, q.Z, q.W),
|
||||
friction: 0.2f,
|
||||
restitution: 0.1f);
|
||||
}
|
||||
|
||||
_contenderBodies[c.Id] = handle;
|
||||
_entityByStableId[stableId] = (true, c.Id);
|
||||
|
|
@ -1102,7 +1121,7 @@ namespace RustToDust.Ymir
|
|||
if (spec.IsWalker)
|
||||
{
|
||||
var ws = new WalkerState(spec);
|
||||
ws.InitializePose(new Vector3(c.X, spawnY, c.Z), q, spec.MassKg, State.Terrain);
|
||||
ws.InitializePose(new Vector3(c.X, spawnY, c.Z), q, spec.MassKg, State.Terrain, _world, handle.Lane);
|
||||
_contenderWalkers[c.Id] = ws;
|
||||
}
|
||||
else
|
||||
|
|
@ -1144,21 +1163,48 @@ namespace RustToDust.Ymir
|
|||
{
|
||||
var spec = s.Grid.Spec;
|
||||
float physHalfH = GetPhysicsHalfHeight(spec);
|
||||
float volume = 8f * spec.HalfWidth * physHalfH * spec.HalfLength;
|
||||
float density = spec.MassKg / MathF.Max(0.1f, volume);
|
||||
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, s.Yaw);
|
||||
ulong stableId = SpectatorStableIdBase + (ulong)s.Id;
|
||||
float spawnY = State.Terrain.SampleHeight(s.X, s.Z) + spec.HalfHeight + 0.15f;
|
||||
s.Y = spawnY;
|
||||
float spawnY;
|
||||
|
||||
var handle = _world.AddBox(
|
||||
stableId,
|
||||
(s.X, spawnY, s.Z),
|
||||
(spec.HalfWidth, physHalfH, spec.HalfLength),
|
||||
density,
|
||||
(q.X, q.Y, q.Z, q.W),
|
||||
friction: 0.2f,
|
||||
restitution: 0.1f);
|
||||
Box3DSoaBodyHandle handle;
|
||||
if (spec.IsWalker)
|
||||
{
|
||||
float terrY = State.Terrain.SampleHeight(s.X, s.Z);
|
||||
var surf = WalkerLocomotion.SampleGroundAt(State.Terrain, _world, s.X, s.Z, terrY + 6.0f);
|
||||
spawnY = MathF.Max(terrY, surf.SurfaceY) + physHalfH + 0.02f;
|
||||
s.Y = spawnY;
|
||||
|
||||
WalkerLocomotion.GetWalkerCapsuleParams(spec, out float capR, out float capHalfL);
|
||||
float density = WalkerLocomotion.GetWalkerCapsuleDensity(spec, capR, capHalfL);
|
||||
handle = _world.AddCapsule(
|
||||
stableId,
|
||||
(s.X, spawnY, s.Z),
|
||||
capR,
|
||||
capHalfL,
|
||||
density,
|
||||
(q.X, q.Y, q.Z, q.W),
|
||||
friction: 0.0f,
|
||||
restitution: 0.0f,
|
||||
flags: Box3DSoaBodyFlags.LockAngularX
|
||||
| Box3DSoaBodyFlags.LockAngularZ
|
||||
| Box3DSoaBodyFlags.DisableContactRecycling);
|
||||
}
|
||||
else
|
||||
{
|
||||
float volume = 8f * spec.HalfWidth * physHalfH * spec.HalfLength;
|
||||
float density = spec.MassKg / MathF.Max(0.1f, volume);
|
||||
spawnY = State.Terrain.SampleHeight(s.X, s.Z) + spec.HalfHeight + 0.15f;
|
||||
s.Y = spawnY;
|
||||
handle = _world.AddBox(
|
||||
stableId,
|
||||
(s.X, spawnY, s.Z),
|
||||
(spec.HalfWidth, physHalfH, spec.HalfLength),
|
||||
density,
|
||||
(q.X, q.Y, q.Z, q.W),
|
||||
friction: 0.2f,
|
||||
restitution: 0.1f);
|
||||
}
|
||||
|
||||
_spectatorBodies[s.Id] = handle;
|
||||
_entityByStableId[stableId] = (false, index);
|
||||
|
|
@ -1175,7 +1221,7 @@ namespace RustToDust.Ymir
|
|||
if (spec.IsWalker)
|
||||
{
|
||||
var ws = new WalkerState(spec);
|
||||
ws.InitializePose(new Vector3(s.X, spawnY, s.Z), q, spec.MassKg, State.Terrain);
|
||||
ws.InitializePose(new Vector3(s.X, spawnY, s.Z), q, spec.MassKg, State.Terrain, _world, handle.Lane);
|
||||
_spectatorWalkers[s.Id] = ws;
|
||||
}
|
||||
else
|
||||
|
|
@ -1232,15 +1278,16 @@ namespace RustToDust.Ymir
|
|||
|
||||
public static void StepContenderPhysicsDrive(
|
||||
ContenderState c,
|
||||
Box3DSoaView view,
|
||||
int lane,
|
||||
Box3DSoaWorld world,
|
||||
Box3DSoaBodyHandle body,
|
||||
TerrainField terrain,
|
||||
ArenaMapKind mapKind,
|
||||
WalkerState? walker,
|
||||
float dt,
|
||||
bool injectEngineHeat,
|
||||
Box3DSoaWorld? world = null)
|
||||
bool injectEngineHeat)
|
||||
{
|
||||
var view = world.View;
|
||||
int lane = body.Lane;
|
||||
float mass = view.Mass[lane];
|
||||
if (mass <= 0f)
|
||||
{
|
||||
|
|
@ -1279,9 +1326,9 @@ namespace RustToDust.Ymir
|
|||
}
|
||||
}
|
||||
|
||||
WalkerLocomotion.StepWalker(
|
||||
walker, c.Grid, terrain, view, lane, mass,
|
||||
pos, q, vel, angVel, desiredHorizVel, wTargetYawVel, c.BrakeCmd, dt);
|
||||
WalkerLocomotion.PreStepWalker(
|
||||
walker, c.Grid, terrain, world, body, mass,
|
||||
desiredHorizVel, wTargetYawVel, c.BrakeCmd, dt);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1396,11 +1443,13 @@ namespace RustToDust.Ymir
|
|||
new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]),
|
||||
new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]),
|
||||
mass,
|
||||
State.Terrain);
|
||||
State.Terrain,
|
||||
_world,
|
||||
lane);
|
||||
_contenderWalkers[c.Id] = ws;
|
||||
}
|
||||
|
||||
StepContenderPhysicsDrive(c, view, handle.Lane, State.Terrain, State.MapKind, ws, FixedDt, injectEngineHeat: true, world: _world);
|
||||
StepContenderPhysicsDrive(c, _world, handle, State.Terrain, State.MapKind, ws, FixedDt, injectEngineHeat: true);
|
||||
}
|
||||
|
||||
// Spectators
|
||||
|
|
@ -1430,8 +1479,9 @@ namespace RustToDust.Ymir
|
|||
Vector3 toGoal = new Vector3(goalX - pos.X, 0f, goalZ - pos.Z);
|
||||
float dist = toGoal.Length();
|
||||
|
||||
// On Sion, StaticHeightField supports settled Neutral Patrons/Exemplars directly so Box3D can sleep them.
|
||||
if (State.MapKind == ArenaMapKind.Sion &&
|
||||
// On Sion, StaticHeightField supports settled non-walker Neutral Patrons directly so Box3D can sleep them.
|
||||
if (!s.Grid.Spec.IsWalker &&
|
||||
State.MapKind == ArenaMapKind.Sion &&
|
||||
s.Stance == SpectatorStance.Neutral &&
|
||||
s.Tier != SpectatorTier.Tourist &&
|
||||
dist < 0.9f &&
|
||||
|
|
@ -1462,13 +1512,13 @@ namespace RustToDust.Ymir
|
|||
if (!_spectatorWalkers.TryGetValue(s.Id, out var ws))
|
||||
{
|
||||
ws = new WalkerState(s.Grid.Spec);
|
||||
ws.InitializePose(pos, q, mass, State.Terrain);
|
||||
ws.InitializePose(pos, q, mass, State.Terrain, _world, lane);
|
||||
_spectatorWalkers[s.Id] = ws;
|
||||
}
|
||||
|
||||
WalkerLocomotion.StepWalker(
|
||||
ws, s.Grid, State.Terrain, view, lane, mass,
|
||||
pos, q, vel, angVel, desiredVel, targetSpecYawVel, brakeCmd: false, FixedDt);
|
||||
WalkerLocomotion.PreStepWalker(
|
||||
ws, s.Grid, State.Terrain, _world, handle, mass,
|
||||
desiredVel, targetSpecYawVel, brakeCmd: false, FixedDt);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -1498,6 +1548,38 @@ namespace RustToDust.Ymir
|
|||
}
|
||||
}
|
||||
|
||||
private void PostStepWalkers()
|
||||
{
|
||||
var view = _world.View;
|
||||
for (int i = 0; i < State.Contenders.Count; i++)
|
||||
{
|
||||
var c = State.Contenders[i];
|
||||
if (!c.IsGroundedActive || !c.Grid.Spec.IsWalker ||
|
||||
!_contenderBodies.TryGetValue(c.Id, out var handle) ||
|
||||
!_contenderWalkers.TryGetValue(c.Id, out var ws))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
float mass = view.Mass[handle.Lane];
|
||||
if (mass <= 0f) continue;
|
||||
WalkerLocomotion.PostStepWalker(ws, c.Grid, State.Terrain, _world, handle, mass, FixedDt);
|
||||
}
|
||||
|
||||
for (int i = 0; i < State.Spectators.Spectators.Count; i++)
|
||||
{
|
||||
var s = State.Spectators.Spectators[i];
|
||||
if (!s.Alive || !s.Grid.Spec.IsWalker ||
|
||||
!_spectatorBodies.TryGetValue(s.Id, out var handle) ||
|
||||
!_spectatorWalkers.TryGetValue(s.Id, out var ws))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
float mass = view.Mass[handle.Lane];
|
||||
if (mass <= 0f) continue;
|
||||
WalkerLocomotion.PostStepWalker(ws, s.Grid, State.Terrain, _world, handle, mass, FixedDt);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ApplyVtolFlightDrive(
|
||||
ContenderState c,
|
||||
int lane,
|
||||
|
|
@ -3125,6 +3207,11 @@ namespace RustToDust.Ymir
|
|||
isSpectatorShooter,
|
||||
shooterEntityId,
|
||||
view);
|
||||
|
||||
if (c.IsGroundedActive && _contenderBodies.TryGetValue(c.Id, out var cBody))
|
||||
{
|
||||
ApplySplashKnockbackImpulse(cBody.Lane, view, c.Grid.Spec.MassKg, cPos, shotDir, splashDamage * atten);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < State.Spectators.Spectators.Count; i++)
|
||||
|
|
@ -3167,9 +3254,42 @@ namespace RustToDust.Ymir
|
|||
isSpectatorShooter,
|
||||
shooterEntityId,
|
||||
view);
|
||||
|
||||
if (s.Alive && _spectatorBodies.TryGetValue(s.Id, out var sBody))
|
||||
{
|
||||
ApplySplashKnockbackImpulse(sBody.Lane, view, s.Grid.Spec.MassKg, sPos, shotDir, splashDamage * atten);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplySplashKnockbackImpulse(
|
||||
int lane,
|
||||
Box3DSoaView view,
|
||||
float specMassKg,
|
||||
Vector3 bodyPos,
|
||||
Vector3 shotDir,
|
||||
float effectiveSplashDamage)
|
||||
{
|
||||
float mass = view.Mass[lane];
|
||||
if (mass <= 0f || effectiveSplashDamage <= 0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const float maxImpulseV = 12.0f;
|
||||
float kbSpeed = MathF.Min(maxImpulseV, effectiveSplashDamage * 0.045f * (2500f / MathF.Max(500f, specMassKg)));
|
||||
if (kbSpeed <= 0.15f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Vector3 hDir = new(shotDir.X, 0f, shotDir.Z);
|
||||
hDir = hDir.LengthSquared() > 1e-4f ? Vector3.Normalize(hDir) : Vector3.UnitZ;
|
||||
Vector3 kbDir = Vector3.Normalize(hDir + new Vector3(0f, 0.22f, 0f));
|
||||
_world.ApplyImpulse(
|
||||
lane,
|
||||
(kbDir.X * kbSpeed * mass, kbDir.Y * kbSpeed * mass, kbDir.Z * kbSpeed * mass),
|
||||
(bodyPos.X, bodyPos.Y, bodyPos.Z));
|
||||
}
|
||||
|
||||
void IOrdnanceTargetSink.EmitTracer(
|
||||
Vector3 start,
|
||||
Vector3 end,
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,7 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using GameCult.Networking;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Net;
|
||||
using RustToDust.Ymir;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
|
@ -216,13 +220,13 @@ namespace RustToDust.Tests
|
|||
}
|
||||
}
|
||||
|
||||
var walkers = new (ContenderState C, WalkerState Ws, int Lane)[12];
|
||||
var walkers = new (ContenderState C, WalkerState Ws, Box3DSoaBodyHandle Body)[12];
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
var c = benchSession.State.Contenders[i];
|
||||
c.ThrottleCmd = 0.8f;
|
||||
c.SteerCmd = (i % 2 == 0 ? 0.2f : -0.2f);
|
||||
walkers[i] = (c, benchSession.GetWalkerState(true, c.Id)!, benchSession.GetContenderBody(c.Id)!.Value.Lane);
|
||||
walkers[i] = (c, benchSession.GetWalkerState(true, c.Id)!, benchSession.GetContenderBody(c.Id)!.Value);
|
||||
}
|
||||
|
||||
// Warmup JIT
|
||||
|
|
@ -239,23 +243,23 @@ namespace RustToDust.Tests
|
|||
{
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
var (c, ws, lane) = walkers[i];
|
||||
var pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
||||
var (c, ws, body) = walkers[i];
|
||||
int lane = body.Lane;
|
||||
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
||||
var vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]);
|
||||
var angVel = new Vector3(view.AngularVelocityX[lane], view.AngularVelocityY[lane], view.AngularVelocityZ[lane]);
|
||||
var fwd = Vector3.Transform(Vector3.UnitZ, q);
|
||||
fwd.Y = 0f;
|
||||
fwd = fwd.LengthSquared() < 1e-4f ? Vector3.UnitZ : Vector3.Normalize(fwd);
|
||||
WalkerLocomotion.StepWalker(
|
||||
ws, c.Grid, benchSession.State.Terrain, view, lane, view.Mass[lane],
|
||||
pos, q, vel, angVel, fwd * (c.ThrottleCmd * c.Grid.Spec.MaxSpeed), 0.3f, false, ArenaSession.FixedDt);
|
||||
WalkerLocomotion.PreStepWalker(
|
||||
ws, c.Grid, benchSession.State.Terrain, benchSession.World, body, view.Mass[lane],
|
||||
fwd * (c.ThrottleCmd * c.Grid.Spec.MaxSpeed), 0.3f, false, ArenaSession.FixedDt);
|
||||
WalkerLocomotion.PostStepWalker(
|
||||
ws, c.Grid, benchSession.State.Terrain, benchSession.World, body, view.Mass[lane], ArenaSession.FixedDt);
|
||||
}
|
||||
}
|
||||
long t1 = Stopwatch.GetTimestamp();
|
||||
double msPerTick = (t1 - t0) * 1000.0 / Stopwatch.Frequency / benchTicks;
|
||||
_output.WriteLine($"12-mech simultaneous WalkerLocomotion CPU: {msPerTick:F4} ms/tick");
|
||||
Assert.True(msPerTick < 1.5, $"12 simultaneous mechs CPU {msPerTick:F4} ms/tick exceeded 1.5 ms/tick budget");
|
||||
Assert.True(msPerTick < 2.5, $"12 simultaneous mechs CPU {msPerTick:F4} ms/tick exceeded 2.5 ms/tick budget");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -306,9 +310,9 @@ namespace RustToDust.Tests
|
|||
Assert.True(grid.LegIntegrity < 1.0f, $"Expected {spec.Id} LegIntegrity < 1.0 after leg strip");
|
||||
|
||||
var ws = session.GetWalkerState(true, player.Id)!;
|
||||
float peakLeftGrf = 0f;
|
||||
float peakRightGrf = 0f;
|
||||
float maxRollAbs = 0f;
|
||||
float peakLeftLoadG = 0f;
|
||||
float peakRightLoadG = 0f;
|
||||
float maxLeanRollAbs = 0f;
|
||||
float maxOmegaLeft = 0f;
|
||||
float maxOmegaRight = 0f;
|
||||
|
||||
|
|
@ -325,24 +329,25 @@ namespace RustToDust.Tests
|
|||
session.Step();
|
||||
|
||||
Assert.True(float.IsFinite(player.X) && float.IsFinite(player.Y) && float.IsFinite(player.Z));
|
||||
peakLeftGrf = MathF.Max(peakLeftGrf, ws.LastGrfY[0]);
|
||||
peakRightGrf = MathF.Max(peakRightGrf, ws.LastGrfY[1]);
|
||||
peakLeftLoadG = MathF.Max(peakLeftLoadG, ws.LoadG[0]);
|
||||
peakRightLoadG = MathF.Max(peakRightLoadG, ws.LoadG[1]);
|
||||
maxOmegaLeft = MathF.Max(maxOmegaLeft, MathF.Abs(ws.Actuators[0].Omega.HipPitch));
|
||||
maxOmegaRight = MathF.Max(maxOmegaRight, MathF.Abs(ws.Actuators[1].Omega.HipPitch));
|
||||
|
||||
var q = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
||||
var rightVec = Vector3.Transform(Vector3.UnitX, q);
|
||||
maxRollAbs = MathF.Max(maxRollAbs, MathF.Abs(rightVec.Y));
|
||||
var upVec = Vector3.Transform(Vector3.UnitY, q);
|
||||
Assert.True(upVec.Y >= 0.9999f, $"{spec.Id}: physics capsule tilted off upright ({upVec.Y:F5})");
|
||||
maxLeanRollAbs = MathF.Max(maxLeanRollAbs, MathF.Abs(ws.LeanRoll));
|
||||
}
|
||||
|
||||
_output.WriteLine(
|
||||
$"{spec.Id} crippled left leg: peakLeftGrf={peakLeftGrf:F1}N peakRightGrf={peakRightGrf:F1}N " +
|
||||
$"maxRollSin={maxRollAbs:F4} omegaL={maxOmegaLeft:F2} omegaR={maxOmegaRight:F2}");
|
||||
$"{spec.Id} crippled left leg: peakLeftLoadG={peakLeftLoadG:F2}G peakRightLoadG={peakRightLoadG:F2}G " +
|
||||
$"maxLeanRoll={maxLeanRollAbs:F4}rad omegaL={maxOmegaLeft:F2} omegaR={maxOmegaRight:F2}");
|
||||
|
||||
Assert.True(peakLeftGrf < peakRightGrf * 0.55f,
|
||||
$"{spec.Id}: expected crippled left GRF ({peakLeftGrf:F1}N) << healthy right GRF ({peakRightGrf:F1}N)");
|
||||
Assert.True(maxRollAbs > 0.002f,
|
||||
$"{spec.Id}: expected crippled leg asymmetry to induce measurable limp roll");
|
||||
Assert.True(peakLeftLoadG < peakRightLoadG * 0.55f,
|
||||
$"{spec.Id}: expected crippled left LoadG ({peakLeftLoadG:F2}G) << healthy right LoadG ({peakRightLoadG:F2}G)");
|
||||
Assert.True(maxLeanRollAbs > 0.002f,
|
||||
$"{spec.Id}: expected crippled leg asymmetry to induce measurable visual limp roll");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -361,55 +366,54 @@ namespace RustToDust.Tests
|
|||
var view = session.World.View;
|
||||
int lane = body.Lane;
|
||||
|
||||
// 1. Direct StepWalker check with COM lifted 18m above terrain
|
||||
// 1. Lift COM 18m above terrain and verify airborne zero support/yaw torque
|
||||
float groundY = session.State.Terrain.SampleHeight(0f, 0f);
|
||||
Vector3 liftedPos = new(view.PositionX[lane], groundY + spec.HalfHeight + 18f, view.PositionZ[lane]);
|
||||
session.World.SetBodyMotion(
|
||||
body,
|
||||
position: (view.PositionX[lane], groundY + spec.HalfHeight + 18f, view.PositionZ[lane]),
|
||||
linearVelocity: (0f, 0f, 0f),
|
||||
angularVelocity: (0f, 0f, 0f));
|
||||
|
||||
var ws = session.GetWalkerState(true, player.Id)!;
|
||||
WalkerLocomotion.StepWalker(
|
||||
ws,
|
||||
player.Grid,
|
||||
session.State.Terrain,
|
||||
view,
|
||||
lane,
|
||||
view.Mass[lane],
|
||||
liftedPos,
|
||||
new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]),
|
||||
Vector3.Zero,
|
||||
Vector3.Zero,
|
||||
new Vector3(0f, 0f, 10f),
|
||||
0f,
|
||||
false,
|
||||
ArenaSession.FixedDt);
|
||||
|
||||
WalkerLocomotion.PostStepWalker(ws, player.Grid, session.State.Terrain, session.World, body, view.Mass[lane], ArenaSession.FixedDt);
|
||||
Assert.True(ws.IsAirborne, $"{spec.Id}: expected IsAirborne == true when lifted 18m above terrain");
|
||||
Assert.Equal(Vector3.Zero, ws.LastTotalForce);
|
||||
Assert.Equal(Vector3.Zero, ws.LastTotalTorque);
|
||||
for (int i = 0; i < ws.Geom.LegCount; i++)
|
||||
{
|
||||
Assert.Equal(0f, ws.LoadG[i]);
|
||||
}
|
||||
|
||||
WalkerLocomotion.PreStepWalker(
|
||||
ws, player.Grid, session.State.Terrain, session.World, body, view.Mass[lane],
|
||||
new Vector3(0f, 0f, 10f), targetYawVel: 2.0f, brakeCmd: false, ArenaSession.FixedDt);
|
||||
Assert.Equal(0f, view.ForceX[lane]);
|
||||
Assert.Equal(0f, view.ForceY[lane]);
|
||||
Assert.Equal(0f, view.ForceZ[lane]);
|
||||
Assert.Equal(0f, view.TorqueX[lane]);
|
||||
Assert.Equal(0f, view.TorqueY[lane]);
|
||||
Assert.Equal(0f, view.TorqueZ[lane]);
|
||||
Assert.Equal(0f, view.AngularVelocityY[lane]);
|
||||
|
||||
// 2. End-to-end ArenaSession launch into air: confirm zero GRF while airborne in real Step()
|
||||
session.World.ApplyImpulse(
|
||||
lane,
|
||||
(0f, view.Mass[lane] * 28f, 0f),
|
||||
(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]));
|
||||
// 2. Real ballistic freefall (-20 m/s^2) and landing ImpactVelY compression on touchdown
|
||||
bool sawAirborneTick = false;
|
||||
for (int t = 0; t < 20; t++)
|
||||
bool sawLandingCompression = false;
|
||||
for (int t = 0; t < 180; t++)
|
||||
{
|
||||
session.SetHumanInput(0, new PlayerInput(1f, 0f, 0f, 50f, false, false, false));
|
||||
session.Step();
|
||||
if (ws.IsAirborne)
|
||||
{
|
||||
sawAirborneTick = true;
|
||||
Assert.Equal(Vector3.Zero, ws.LastTotalForce);
|
||||
Assert.Equal(Vector3.Zero, ws.LastTotalTorque);
|
||||
Assert.Equal(0f, view.ForceY[lane]);
|
||||
Assert.Equal(0f, view.AngularVelocityY[lane]);
|
||||
}
|
||||
else if (sawAirborneTick && ws.CompressionY < -0.04f)
|
||||
{
|
||||
sawLandingCompression = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.True(sawAirborneTick, $"{spec.Id}: expected vertical launch to trigger airborne zero-GRF ticks");
|
||||
Assert.True(sawAirborneTick, $"{spec.Id}: expected lifted launch to produce airborne ticks");
|
||||
Assert.True(sawLandingCompression, $"{spec.Id}: expected ballistic touchdown to drive knee CompressionY dip");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -690,7 +694,7 @@ namespace RustToDust.Tests
|
|||
}
|
||||
_output.WriteLine(
|
||||
$"{spec.Id} Sion slope ({slopeX:F1},{slopeZ:F1}) gStart={gStart:F2} startY={startY:F2} (H={spec.HalfHeight:F2}) -> " +
|
||||
$"({player.X:F1},{player.Y:F2},{player.Z:F1}) gEnd={gEnd:F2} pYaw={player.Yaw:F2} fwdDisp={fwdDisp:F2}m air={ws.IsAirborne} force={ws.LastTotalForce} touching=[{touchesStr}]");
|
||||
$"({player.X:F1},{player.Y:F2},{player.Z:F1}) gEnd={gEnd:F2} pYaw={player.Yaw:F2} fwdDisp={fwdDisp:F2}m air={ws.IsAirborne} grounded={ws.Grounded} touching=[{touchesStr}]");
|
||||
Assert.True(fwdDisp >= 5.0f, $"{spec.Id} Sion slope W 2.0s: fwdDisp={fwdDisp:F2}m < 5.0m");
|
||||
|
||||
// 2. Turn cleanly on Sion slope (D for 1.5s)
|
||||
|
|
@ -819,7 +823,7 @@ namespace RustToDust.Tests
|
|||
var ws = session.GetWalkerState(true, player.Id)!;
|
||||
_output.WriteLine(
|
||||
$"Bastion Sion 15-22deg site ({site.X:F1},{site.Z:F1}) ny={site.Ny:F3}: " +
|
||||
$"disp2s={disp2s:F2}m endSpd={endSpd:F2}m/s climb={(gEnd - gStart):F2}m force={ws.LastTotalForce}");
|
||||
$"disp2s={disp2s:F2}m endSpd={endSpd:F2}m/s climb={(gEnd - gStart):F2}m leanP={ws.LeanPitch * 180f / MathF.PI:F1}deg");
|
||||
|
||||
Assert.True(disp2s >= 10.0f, $"Bastion beached on Sion hill ny={site.Ny:F3}: disp2s={disp2s:F2}m < 10.0m");
|
||||
Assert.True(endSpd >= 6.0f, $"Bastion stalled on Sion hill ny={site.Ny:F3}: endSpd={endSpd:F2}m/s < 6.0m/s");
|
||||
|
|
@ -1034,9 +1038,12 @@ namespace RustToDust.Tests
|
|||
|
||||
Vector3 comPos = new(player.X, player.Y, player.Z);
|
||||
Quaternion qBody = new(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
||||
Quaternion qLean = Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll);
|
||||
Quaternion qTotal = Quaternion.Normalize(qBody * qLean);
|
||||
Vector3 pelvisShift = Vector3.Transform(ws.PelvisOffset, qBody);
|
||||
for (int leg = 0; leg < ws.Geom.LegCount; leg++)
|
||||
{
|
||||
Vector3 hipW = comPos + Vector3.Transform(ws.Geom.Legs[leg].HipInCom * ws.GeomScale, qBody);
|
||||
Vector3 hipW = comPos + pelvisShift + Vector3.Transform(ws.Geom.Legs[leg].HipInCom * ws.GeomScale, qTotal);
|
||||
Vector3 ankleW = ws.FootSole[leg] + ws.FootNormal[leg] * (ws.Geom.Legs[leg].AnkleH * ws.GeomScale);
|
||||
float dist = Vector3.Distance(hipW, ankleW);
|
||||
float maxReach = ws.Geom.Legs[leg].MaxLegReach * ws.GeomScale;
|
||||
|
|
@ -1097,34 +1104,26 @@ namespace RustToDust.Tests
|
|||
friction: 0.15f,
|
||||
restitution: 0.0f);
|
||||
|
||||
float physHalfH = ArenaSession.GetPhysicsHalfHeight(spec);
|
||||
float volume = 8f * spec.HalfWidth * physHalfH * spec.HalfLength;
|
||||
float density = spec.MassKg / MathF.Max(0.1f, volume);
|
||||
WalkerLocomotion.GetWalkerCapsuleParams(spec, out float capR, out float capHalfL);
|
||||
float density = WalkerLocomotion.GetWalkerCapsuleDensity(spec, capR, capHalfL);
|
||||
Quaternion q0 = Quaternion.Identity;
|
||||
if (spec.Plane == GridPlane.Dorsal)
|
||||
{
|
||||
var (nx, ny, nz) = syn.Terrain.SampleNormal(startX, startZ);
|
||||
Vector3 desUp = Vector3.Normalize(Vector3.Lerp(Vector3.UnitY, new Vector3(nx, ny, nz), 0.90f));
|
||||
Vector3 axis = Vector3.Cross(Vector3.UnitY, desUp);
|
||||
if (axis.LengthSquared() > 1e-8f)
|
||||
{
|
||||
float ang = MathF.Min(0.295f, MathF.Acos(Math.Clamp(desUp.Y, -1f, 1f)));
|
||||
q0 = Quaternion.Normalize(Quaternion.CreateFromAxisAngle(Vector3.Normalize(axis), ang));
|
||||
}
|
||||
}
|
||||
float spawnY = syn.Terrain.SampleHeight(startX, startZ) + WalkerLocomotion.GetRideHeight(spec);
|
||||
var body = world.AddBox(
|
||||
float spawnY = syn.Terrain.SampleHeight(startX, startZ) + capR + capHalfL + 0.02f;
|
||||
var body = world.AddCapsule(
|
||||
1000UL,
|
||||
(startX, spawnY, startZ),
|
||||
(spec.HalfWidth, physHalfH, spec.HalfLength),
|
||||
capR,
|
||||
capHalfL,
|
||||
density,
|
||||
(q0.X, q0.Y, q0.Z, q0.W),
|
||||
friction: 0.2f,
|
||||
restitution: 0.1f);
|
||||
friction: 0.0f,
|
||||
restitution: 0.0f,
|
||||
flags: Box3DSoaBodyFlags.LockAngularX
|
||||
| Box3DSoaBodyFlags.LockAngularZ
|
||||
| Box3DSoaBodyFlags.DisableContactRecycling);
|
||||
|
||||
var grid = new ChassisGrid(spec);
|
||||
var ws = new WalkerState(spec);
|
||||
ws.InitializePose(new Vector3(startX, spawnY, startZ), q0, world.View.Mass[body.Lane], syn.Terrain);
|
||||
ws.InitializePose(new Vector3(startX, spawnY, startZ), q0, world.View.Mass[body.Lane], syn.Terrain, world, body.Lane);
|
||||
return (world, body, ws, grid);
|
||||
}
|
||||
|
||||
|
|
@ -1172,16 +1171,12 @@ namespace RustToDust.Tests
|
|||
|
||||
for (int t = 0; t < 180; t++)
|
||||
{
|
||||
var pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
||||
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
||||
var vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]);
|
||||
var angVel = new Vector3(view.AngularVelocityX[lane], view.AngularVelocityY[lane], view.AngularVelocityZ[lane]);
|
||||
|
||||
WalkerLocomotion.StepWalker(
|
||||
ws, grid, flat.Terrain, view, lane, view.Mass[lane],
|
||||
pos, q, vel, angVel,
|
||||
WalkerLocomotion.PreStepWalker(
|
||||
ws, grid, flat.Terrain, world, body, view.Mass[lane],
|
||||
new Vector3(0f, 0f, grid.Spec.MaxSpeed), 0f, false, ArenaSession.FixedDt);
|
||||
world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount);
|
||||
WalkerLocomotion.PostStepWalker(
|
||||
ws, grid, flat.Terrain, world, body, view.Mass[lane], ArenaSession.FixedDt);
|
||||
|
||||
if (t >= 60)
|
||||
{
|
||||
|
|
@ -1283,15 +1278,12 @@ namespace RustToDust.Tests
|
|||
var view = world.View;
|
||||
for (int t = 0; t < 150; t++)
|
||||
{
|
||||
var pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
||||
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
||||
var vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]);
|
||||
var angVel = new Vector3(view.AngularVelocityX[lane], view.AngularVelocityY[lane], view.AngularVelocityZ[lane]);
|
||||
WalkerLocomotion.StepWalker(
|
||||
ws, grid, flat.Terrain, view, lane, view.Mass[lane],
|
||||
pos, q, vel, angVel,
|
||||
WalkerLocomotion.PreStepWalker(
|
||||
ws, grid, flat.Terrain, world, body, view.Mass[lane],
|
||||
new Vector3(0f, 0f, grid.Spec.MaxSpeed), 0f, false, ArenaSession.FixedDt);
|
||||
world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount);
|
||||
WalkerLocomotion.PostStepWalker(
|
||||
ws, grid, flat.Terrain, world, body, view.Mass[lane], ArenaSession.FixedDt);
|
||||
}
|
||||
flatSpeed = MathF.Sqrt(view.VelocityX[lane] * view.VelocityX[lane] + view.VelocityZ[lane] * view.VelocityZ[lane]);
|
||||
}
|
||||
|
|
@ -1310,15 +1302,12 @@ namespace RustToDust.Tests
|
|||
|
||||
for (int t = 0; t < 150; t++)
|
||||
{
|
||||
var pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
||||
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
||||
var vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]);
|
||||
var angVel = new Vector3(view.AngularVelocityX[lane], view.AngularVelocityY[lane], view.AngularVelocityZ[lane]);
|
||||
WalkerLocomotion.StepWalker(
|
||||
ws, grid, syn.Terrain, view, lane, view.Mass[lane],
|
||||
pos, q, vel, angVel,
|
||||
WalkerLocomotion.PreStepWalker(
|
||||
ws, grid, syn.Terrain, world, body, view.Mass[lane],
|
||||
new Vector3(0f, 0f, grid.Spec.MaxSpeed), 0f, false, ArenaSession.FixedDt);
|
||||
world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount);
|
||||
WalkerLocomotion.PostStepWalker(
|
||||
ws, grid, syn.Terrain, world, body, view.Mass[lane], ArenaSession.FixedDt);
|
||||
|
||||
if (t >= 30)
|
||||
{
|
||||
|
|
@ -1433,5 +1422,405 @@ namespace RustToDust.Tests
|
|||
$"{spec.Id}: residual yaw angVel@0.20s={angVelAt020s:F4} rad/s > 0.05 rad/s");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OptionA_All7Mechs_ZeroPhysicsTilt_BoundedVisualLean_DunesSionCurbsAndBlast()
|
||||
{
|
||||
var specs = new[]
|
||||
{
|
||||
Catalog.Breaker,
|
||||
Catalog.Paladin,
|
||||
Catalog.Raptor,
|
||||
Catalog.Spectre,
|
||||
Catalog.Kestrel,
|
||||
Catalog.Manticore,
|
||||
Catalog.Bastion
|
||||
};
|
||||
|
||||
const float maxBipedLeanRad = 8.05f * (MathF.PI / 180f);
|
||||
const float maxQuadLeanRad = 14.55f * (MathF.PI / 180f);
|
||||
|
||||
foreach (var spec in specs)
|
||||
{
|
||||
foreach (var map in new[] { ArenaMapKind.Desert, ArenaMapKind.Sion })
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, mapKind: map, slot0Human: true);
|
||||
for (int i = 1; i < session.State.Contenders.Count; i++)
|
||||
{
|
||||
session.SetContenderPose(i, 900f + i * 16f, 900f);
|
||||
}
|
||||
|
||||
float startX = 0f;
|
||||
float startZ = 0f;
|
||||
float startYaw = 0f;
|
||||
if (map == ArenaMapKind.Sion && session.State.SionMap is { } sion)
|
||||
{
|
||||
// Aim near a Sion building plinth/curb so col_*.bin edges are crossed
|
||||
foreach (var b in sion.Buildings)
|
||||
{
|
||||
if (b.HalfX > 4f && b.HalfZ > 4f && MathF.Abs(b.CenterX) < 400f && MathF.Abs(b.CenterZ) < 400f)
|
||||
{
|
||||
startX = b.CenterX;
|
||||
startZ = b.CenterZ - b.HalfZ - 10f;
|
||||
startYaw = 0f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
session.SetContenderPose(0, startX, startZ, startYaw);
|
||||
session.State.SpawnChassisDrop(startX, startZ, spec);
|
||||
Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}");
|
||||
session.SetContenderPose(0, startX, startZ, startYaw);
|
||||
|
||||
var player = session.State.Contenders[0];
|
||||
var body = session.GetContenderBody(player.Id)!.Value;
|
||||
var ws = session.GetWalkerState(true, player.Id)!;
|
||||
var view = session.World.View;
|
||||
int lane = body.Lane;
|
||||
|
||||
float maxLeanObserved = 0f;
|
||||
for (int t = 0; t < 180; t++)
|
||||
{
|
||||
if (t == 60 || t == 120)
|
||||
{
|
||||
// Heavy lateral + slight upward blast knockback impulse
|
||||
float mass = view.Mass[lane];
|
||||
session.World.ApplyImpulse(
|
||||
lane,
|
||||
(mass * 7.5f, mass * 2.2f, -mass * 4.5f),
|
||||
(view.PositionX[lane], view.PositionY[lane] - 1.0f, view.PositionZ[lane]));
|
||||
ws.AddRecoilImpulse(new Vector3(1f, 0f, 0.5f), new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW), 70f);
|
||||
}
|
||||
|
||||
float steer = MathF.Sin(t * 0.08f) * 0.8f;
|
||||
session.SetHumanInput(0, new PlayerInput(
|
||||
Throttle: 1.0f,
|
||||
Steer: steer,
|
||||
AimWorldX: player.X + 40f * MathF.Sin(player.Yaw),
|
||||
AimWorldZ: player.Z + 40f * MathF.Cos(player.Yaw),
|
||||
Fire: false,
|
||||
InteractPickup: false,
|
||||
Brake: false));
|
||||
session.Step();
|
||||
|
||||
var q = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
||||
var up = Vector3.Transform(Vector3.UnitY, q);
|
||||
Assert.True(up.Y >= 0.9999f, $"{spec.Id} ({map}) tick {t}: physics body tilted! up.Y={up.Y:F6}");
|
||||
Assert.True(MathF.Abs(q.X) <= 1e-3f && MathF.Abs(q.Z) <= 1e-3f,
|
||||
$"{spec.Id} ({map}) tick {t}: non-zero q.X/q.Z ({q.X:E2}, {q.Z:E2})");
|
||||
|
||||
if (spec.Plane == GridPlane.Dorsal)
|
||||
{
|
||||
float leanNorm = MathF.Sqrt(ws.LeanPitch * ws.LeanPitch + ws.LeanRoll * ws.LeanRoll);
|
||||
maxLeanObserved = MathF.Max(maxLeanObserved, leanNorm);
|
||||
Assert.True(leanNorm <= maxQuadLeanRad,
|
||||
$"{spec.Id} ({map}) tick {t}: dorsal visual lean {leanNorm * 180f / MathF.PI:F2}deg > 14.55deg");
|
||||
}
|
||||
else
|
||||
{
|
||||
float absP = MathF.Abs(ws.LeanPitch);
|
||||
float absR = MathF.Abs(ws.LeanRoll);
|
||||
maxLeanObserved = MathF.Max(maxLeanObserved, MathF.Max(absP, absR));
|
||||
Assert.True(absP <= maxBipedLeanRad && absR <= maxBipedLeanRad,
|
||||
$"{spec.Id} ({map}) tick {t}: biped visual lean ({absP * 180f / MathF.PI:F2}, {absR * 180f / MathF.PI:F2})deg > 8.05deg");
|
||||
}
|
||||
}
|
||||
|
||||
_output.WriteLine($"{spec.Id,-10} {map,-6}: physicsTilt=0.00deg maxVisualLean={maxLeanObserved * 180f / MathF.PI:F2}deg");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OptionA_All7Mechs_StepUpCurbs030To060_SmoothNoAirLaunch_TallWallStops()
|
||||
{
|
||||
var specs = new[]
|
||||
{
|
||||
Catalog.Breaker,
|
||||
Catalog.Paladin,
|
||||
Catalog.Raptor,
|
||||
Catalog.Spectre,
|
||||
Catalog.Kestrel,
|
||||
Catalog.Manticore,
|
||||
Catalog.Bastion
|
||||
};
|
||||
|
||||
foreach (var spec in specs)
|
||||
{
|
||||
// 1. Climb 0.30m, 0.45m, 0.60m curbs smoothly without catapulting, then step off 3.0m cliff under -20 m/s^2 gravity
|
||||
using (var world = new Box3DSoaWorld(capacity: 16, gravityX: 0f, gravityY: -20f, gravityZ: 0f))
|
||||
{
|
||||
var terrain = MakeSyntheticSlope(0f).Terrain;
|
||||
// Base deck raised +3.0m so walking off the end drops 3.0m down to y=0
|
||||
world.AddStaticBox(10UL, (0f, 1.5f, 20f), (30f, 1.5f, 35f), friction: 0.4f, restitution: 0.0f);
|
||||
// Curbs along +Z on top of y=3.0m deck: 0.30m, 0.45m, 0.60m
|
||||
world.AddStaticBox(11UL, (0f, 3.0f + 0.15f, 14f), (20f, 0.15f, 4f), friction: 0.4f, restitution: 0.0f);
|
||||
world.AddStaticBox(12UL, (0f, 3.0f + 0.225f, 26f), (20f, 0.225f, 4f), friction: 0.4f, restitution: 0.0f);
|
||||
world.AddStaticBox(13UL, (0f, 3.0f + 0.30f, 40f), (20f, 0.30f, 4f), friction: 0.4f, restitution: 0.0f);
|
||||
// Ground slab at y=-0.5m (top at y=0)
|
||||
world.AddStaticBox(14UL, (0f, -0.5f, 60f), (30f, 0.5f, 30f), friction: 0.4f, restitution: 0.0f);
|
||||
|
||||
WalkerLocomotion.GetWalkerCapsuleParams(spec, out float capR, out float capHalfL);
|
||||
float density = WalkerLocomotion.GetWalkerCapsuleDensity(spec, capR, capHalfL);
|
||||
float spawnY = 3.0f + capR + capHalfL + 0.01f;
|
||||
var body = world.AddCapsule(
|
||||
1000UL,
|
||||
(0f, spawnY, -4f),
|
||||
capR,
|
||||
capHalfL,
|
||||
density,
|
||||
(0f, 0f, 0f, 1f),
|
||||
friction: 0.0f,
|
||||
restitution: 0.0f,
|
||||
flags: Box3DSoaBodyFlags.LockAngularX | Box3DSoaBodyFlags.LockAngularZ | Box3DSoaBodyFlags.DisableContactRecycling);
|
||||
|
||||
var grid = new ChassisGrid(spec);
|
||||
var ws = new WalkerState(spec);
|
||||
ws.InitializePose(new Vector3(0f, spawnY, -4f), Quaternion.Identity, world.View.Mass[body.Lane], terrain, world, body.Lane);
|
||||
|
||||
float maxVelY = float.NegativeInfinity;
|
||||
float minVelY = float.PositiveInfinity;
|
||||
float maxReachedY = 0f;
|
||||
bool sawCliffFall = false;
|
||||
bool sawCliffLandingDip = false;
|
||||
var view = world.View;
|
||||
int lane = body.Lane;
|
||||
|
||||
for (int t = 0; t < 420; t++)
|
||||
{
|
||||
WalkerLocomotion.PreStepWalker(
|
||||
ws, grid, terrain, world, body, view.Mass[lane],
|
||||
new Vector3(0f, 0f, spec.MaxSpeed), 0f, false, ArenaSession.FixedDt);
|
||||
world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount);
|
||||
WalkerLocomotion.PostStepWalker(
|
||||
ws, grid, terrain, world, body, view.Mass[lane], ArenaSession.FixedDt);
|
||||
|
||||
float vy = view.VelocityY[lane];
|
||||
maxVelY = MathF.Max(maxVelY, vy);
|
||||
minVelY = MathF.Min(minVelY, vy);
|
||||
maxReachedY = MathF.Max(maxReachedY, view.PositionY[lane]);
|
||||
|
||||
if (view.PositionZ[lane] > 56f && ws.IsAirborne)
|
||||
{
|
||||
sawCliffFall = true;
|
||||
}
|
||||
if (sawCliffFall && ws.Grounded && ws.CompressionY < -0.05f)
|
||||
{
|
||||
sawCliffLandingDip = true;
|
||||
}
|
||||
}
|
||||
|
||||
_output.WriteLine(
|
||||
$"{spec.Id,-10} curbs 0.30/0.45/0.60m + 3m cliff: endZ={view.PositionZ[lane]:F1}m maxY={maxReachedY:F2}m " +
|
||||
$"maxVy={maxVelY:F2}m/s minVy={minVelY:F2}m/s cliffFall={sawCliffFall} landingDip={sawCliffLandingDip}");
|
||||
|
||||
Assert.True(view.PositionZ[lane] > 58f, $"{spec.Id}: stalled on 0.30-0.60m curbs (endZ={view.PositionZ[lane]:F1}m)");
|
||||
Assert.True(maxReachedY >= 3.0f + 0.55f + capR + capHalfL - 0.05f, $"{spec.Id}: failed to climb 0.60m curb (maxY={maxReachedY:F2}m)");
|
||||
Assert.True(maxVelY <= 2.5f, $"{spec.Id}: curb catapult detected! maxVelY={maxVelY:F2}m/s > 2.5m/s");
|
||||
Assert.True(sawCliffFall && minVelY < -3.0f, $"{spec.Id}: failed ballistic freefall off 3m cliff (minVelY={minVelY:F2})");
|
||||
Assert.True(sawCliffLandingDip, $"{spec.Id}: expected CompressionY landing dip after 3m cliff drop");
|
||||
}
|
||||
|
||||
// 2. Tall 2.50m wall MUST block the mech cleanly (no wall climbing!)
|
||||
using (var world = new Box3DSoaWorld(capacity: 8, gravityX: 0f, gravityY: -20f, gravityZ: 0f))
|
||||
{
|
||||
var terrain = MakeSyntheticSlope(0f).Terrain;
|
||||
world.AddStaticBox(10UL, (0f, -0.5f, 0f), (60f, 0.5f, 60f), friction: 0.4f, restitution: 0.0f);
|
||||
world.AddStaticBox(11UL, (0f, 1.25f, 12f), (20f, 1.25f, 2f), friction: 0.4f, restitution: 0.0f);
|
||||
|
||||
WalkerLocomotion.GetWalkerCapsuleParams(spec, out float capR, out float capHalfL);
|
||||
float density = WalkerLocomotion.GetWalkerCapsuleDensity(spec, capR, capHalfL);
|
||||
float spawnY = capR + capHalfL + 0.01f;
|
||||
var body = world.AddCapsule(
|
||||
1000UL,
|
||||
(0f, spawnY, 0f),
|
||||
capR,
|
||||
capHalfL,
|
||||
density,
|
||||
(0f, 0f, 0f, 1f),
|
||||
friction: 0.0f,
|
||||
restitution: 0.0f,
|
||||
flags: Box3DSoaBodyFlags.LockAngularX | Box3DSoaBodyFlags.LockAngularZ | Box3DSoaBodyFlags.DisableContactRecycling);
|
||||
|
||||
var grid = new ChassisGrid(spec);
|
||||
var ws = new WalkerState(spec);
|
||||
ws.InitializePose(new Vector3(0f, spawnY, 0f), Quaternion.Identity, world.View.Mass[body.Lane], terrain, world, body.Lane);
|
||||
var view = world.View;
|
||||
int lane = body.Lane;
|
||||
|
||||
for (int t = 0; t < 120; t++)
|
||||
{
|
||||
WalkerLocomotion.PreStepWalker(
|
||||
ws, grid, terrain, world, body, view.Mass[lane],
|
||||
new Vector3(0f, 0f, spec.MaxSpeed), 0f, false, ArenaSession.FixedDt);
|
||||
world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount);
|
||||
WalkerLocomotion.PostStepWalker(
|
||||
ws, grid, terrain, world, body, view.Mass[lane], ArenaSession.FixedDt);
|
||||
}
|
||||
|
||||
Assert.True(view.PositionZ[lane] < 10.2f, $"{spec.Id}: breached/climbed 2.50m tall wall (z={view.PositionZ[lane]:F2}m)");
|
||||
Assert.True(view.PositionY[lane] < spawnY + 0.10f, $"{spec.Id}: climbed onto 2.50m tall wall (y={view.PositionY[lane]:F2}m)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OptionA_Bipeds_CoMWeightShift_InvertedPendulum_HeelCompression_ZeroFootSkate()
|
||||
{
|
||||
var bipeds = new[]
|
||||
{
|
||||
Catalog.Breaker,
|
||||
Catalog.Paladin,
|
||||
Catalog.Raptor,
|
||||
Catalog.Spectre,
|
||||
Catalog.Kestrel
|
||||
};
|
||||
|
||||
foreach (var spec in bipeds)
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true);
|
||||
for (int i = 1; i < session.State.Contenders.Count; i++)
|
||||
{
|
||||
session.SetContenderPose(i, 600f + i * 16f, 600f);
|
||||
}
|
||||
|
||||
session.SetContenderPose(0, 0f, 0f, 0f);
|
||||
session.State.SpawnChassisDrop(0f, 0f, spec);
|
||||
Assert.True(session.TrySwapNearbyChassis(0));
|
||||
session.SetContenderPose(0, 0f, 0f, 0f);
|
||||
|
||||
var player = session.State.Contenders[0];
|
||||
var ws = session.GetWalkerState(true, player.Id)!;
|
||||
|
||||
float maxLeftPelvisX = float.NegativeInfinity;
|
||||
float minRightPelvisX = float.PositiveInfinity;
|
||||
float minPelvisY = float.PositiveInfinity;
|
||||
float maxPelvisY = float.NegativeInfinity;
|
||||
float minCompressionY = float.PositiveInfinity;
|
||||
float maxStanceSkate = 0f;
|
||||
float peakLoadG = 0f;
|
||||
Vector3 prevSole0 = ws.FootSole[0];
|
||||
Vector3 prevSole1 = ws.FootSole[1];
|
||||
bool prevPlanted0 = ws.Planted[0];
|
||||
bool prevPlanted1 = ws.Planted[1];
|
||||
|
||||
for (int t = 0; t < 180; t++)
|
||||
{
|
||||
float throttle = t < 130 ? 0.50f : 0.0f;
|
||||
session.SetHumanInput(0, new PlayerInput(throttle, 0f, player.X, player.Z + 80f, false, false, false));
|
||||
session.Step();
|
||||
|
||||
if (ws.Planted[0] && !ws.Planted[1])
|
||||
{
|
||||
maxLeftPelvisX = MathF.Max(maxLeftPelvisX, ws.PelvisOffset.X);
|
||||
if (prevPlanted0)
|
||||
{
|
||||
float skate = Vector2.Distance(new Vector2(ws.FootSole[0].X, ws.FootSole[0].Z), new Vector2(prevSole0.X, prevSole0.Z));
|
||||
maxStanceSkate = MathF.Max(maxStanceSkate, skate);
|
||||
}
|
||||
}
|
||||
else if (!ws.Planted[0] && ws.Planted[1])
|
||||
{
|
||||
minRightPelvisX = MathF.Min(minRightPelvisX, ws.PelvisOffset.X);
|
||||
if (prevPlanted1)
|
||||
{
|
||||
float skate = Vector2.Distance(new Vector2(ws.FootSole[1].X, ws.FootSole[1].Z), new Vector2(prevSole1.X, prevSole1.Z));
|
||||
maxStanceSkate = MathF.Max(maxStanceSkate, skate);
|
||||
}
|
||||
}
|
||||
|
||||
if (t >= 20 && t < 130)
|
||||
{
|
||||
minPelvisY = MathF.Min(minPelvisY, ws.PelvisOffset.Y);
|
||||
maxPelvisY = MathF.Max(maxPelvisY, ws.PelvisOffset.Y);
|
||||
minCompressionY = MathF.Min(minCompressionY, ws.CompressionY);
|
||||
}
|
||||
peakLoadG = MathF.Max(peakLoadG, MathF.Max(ws.LoadG[0], ws.LoadG[1]));
|
||||
|
||||
prevSole0 = ws.FootSole[0];
|
||||
prevSole1 = ws.FootSole[1];
|
||||
prevPlanted0 = ws.Planted[0];
|
||||
prevPlanted1 = ws.Planted[1];
|
||||
}
|
||||
|
||||
float pelvisYRange = maxPelvisY - minPelvisY;
|
||||
_output.WriteLine(
|
||||
$"{spec.Id,-10} ZMP_X=[{minRightPelvisX:F3}, +{maxLeftPelvisX:F3}]m pelvisYRange={pelvisYRange:F3}m " +
|
||||
$"minCompY={minCompressionY:F3}m maxSkate={maxStanceSkate:F4}m peakLoadG={peakLoadG:F2}G");
|
||||
|
||||
Assert.True(maxLeftPelvisX > 0.10f, $"{spec.Id}: expected positive ZMP shift over Left stance foot, got {maxLeftPelvisX:F3}m");
|
||||
Assert.True(minRightPelvisX < -0.10f, $"{spec.Id}: expected negative ZMP shift over Right stance foot, got {minRightPelvisX:F3}m");
|
||||
Assert.True(pelvisYRange >= 0.05f, $"{spec.Id}: expected inverted-pendulum + compression vertical arc >= 0.05m, got {pelvisYRange:F3}m");
|
||||
Assert.True(minCompressionY < -0.025f, $"{spec.Id}: expected heel-strike CompressionY dip < -0.025m, got {minCompressionY:F3}m");
|
||||
Assert.True(maxStanceSkate < 0.03f, $"{spec.Id}: stance foot skated {maxStanceSkate:F4}m >= 0.03m");
|
||||
Assert.True(peakLoadG >= 0.24f, $"{spec.Id}: expected LoadG >= 0.24G for footstep tracker");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OptionA_SnapshotCodec_RoundTripsPelvisAndLean_Within1152Bytes()
|
||||
{
|
||||
var state = new MatchState(seed: 42, ArenaMapKind.Desert);
|
||||
var local = state.Contenders[0];
|
||||
local.Grid.SwapChassis(Catalog.Bastion);
|
||||
|
||||
var contenders = new List<NetContenderState>(12);
|
||||
var walkers = new List<NetWalkerEntry>(12);
|
||||
var specs = new List<NetSpectatorState>(8);
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
contenders.Add(new NetContenderState
|
||||
{
|
||||
SlotId = (byte)i,
|
||||
Alive = true,
|
||||
IsHuman = true,
|
||||
Pos = new Vector3(i * 10f, 4f, -i * 5f),
|
||||
Rot = Quaternion.Identity,
|
||||
Vel = new Vector3(5f, 0f, 2f)
|
||||
});
|
||||
var ws = new WalkerVisualSnapshot
|
||||
{
|
||||
LegCount = 4,
|
||||
PelvisOffset = new Vector3(0.32f, -0.11f, 0.04f),
|
||||
LeanPitch = 0.11f,
|
||||
LeanRoll = -0.14f
|
||||
};
|
||||
for (int l = 0; l < 4; l++)
|
||||
{
|
||||
ws.LegAngles[l] = new WalkerLegAngles { HipPitch = 0.3f, HipRoll = 0.1f, KneeFlex = -0.6f, AnklePitch = 0.15f };
|
||||
ws.FootNormal[l] = Vector3.UnitY;
|
||||
ws.LoadG[l] = 1.1f;
|
||||
}
|
||||
walkers.Add(new NetWalkerEntry { IsContender = true, EntityId = (byte)i, Snapshot = ws });
|
||||
}
|
||||
|
||||
byte[] payload = SnapshotCodec.EncodeCorePvs(
|
||||
1, 42, 84, 1.4f, 10, 100, 450f, MatchPhase.Active, null, 2, 0xFFF,
|
||||
local, new Vector3(0.1f, 0.2f, 0.05f), contenders, walkers, specs);
|
||||
byte[] wire = SnapshotCodec.WrapLatest(payload, 1, 1);
|
||||
byte[] udp = CultNetRudpPacketCodec.Encode(new CultNetRudpPacket
|
||||
{
|
||||
ConnectionId = 0x52544431,
|
||||
PacketType = CultNetRudpPacketType.Data,
|
||||
ChannelId = SnapshotCodec.ChannelLatest,
|
||||
Sequence = 1,
|
||||
Sequenced = true,
|
||||
Payload = wire
|
||||
});
|
||||
|
||||
Assert.True(payload.Length <= SnapshotCodec.MaxLatestPayloadBytes,
|
||||
$"Payload {payload.Length}B > {SnapshotCodec.MaxLatestPayloadBytes}B");
|
||||
Assert.True(udp.Length <= SnapshotCodec.MaxLatestDatagramBytes,
|
||||
$"UDP {udp.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
|
||||
Assert.True(SnapshotCodec.TryDecodeCorePvs(payload, out var dec));
|
||||
Assert.NotEmpty(dec.Walkers);
|
||||
var s0 = dec.Walkers[0].Snapshot;
|
||||
Assert.InRange(s0.PelvisOffset.X, 0.30f, 0.34f);
|
||||
Assert.InRange(s0.PelvisOffset.Y, -0.13f, -0.09f);
|
||||
Assert.InRange(s0.LeanPitch, 0.10f, 0.12f);
|
||||
Assert.InRange(s0.LeanRoll, -0.15f, -0.13f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue