acdream/tests/AcDream.App.Tests/Rendering/PhysicsCameraCollisionProbeTests.cs
2026-05-29 19:01:21 +02:00

43 lines
1.4 KiB
C#

using System.Numerics;
using AcDream.App.Rendering;
using AcDream.Core.Physics;
using Xunit;
namespace AcDream.App.Tests.Rendering;
public class PhysicsCameraCollisionProbeTests
{
// The probe must convert the desired eye path (where the SPHERE CENTER
// should travel) into the foot-capsule path InitPath expects (which offsets
// sphere0 up by radius), then invert it on the result. Verify the round trip.
[Fact]
public void SpherePathOffset_RoundTrips()
{
var p = new Vector3(10f, 20f, 30f);
const float r = 0.3f;
var path = PhysicsCameraCollisionProbe.ToSpherePath(p, r);
Assert.Equal(p.Z - r, path.Z, 5);
Assert.Equal(p.X, path.X, 5);
Assert.Equal(p.Y, path.Y, 5);
var back = PhysicsCameraCollisionProbe.FromSpherePath(path, r);
Assert.Equal(p.X, back.X, 5);
Assert.Equal(p.Y, back.Y, 5);
Assert.Equal(p.Z, back.Z, 5);
}
// cellId == 0 means "no starting cell" — the probe must short-circuit and
// return the desired eye without touching the engine.
[Fact]
public void SweepEye_NoStartingCell_ReturnsDesiredEyeUnchanged()
{
var probe = new PhysicsCameraCollisionProbe(new PhysicsEngine());
var pivot = new Vector3(0f, 0f, 1.5f);
var eye = new Vector3(-2f, 0f, 2.2f);
var result = probe.SweepEye(pivot, eye, cellId: 0, selfEntityId: 0);
Assert.Equal(eye, result);
}
}