fix(world): match retail portal passage and exit warp
This commit is contained in:
parent
eab23cbdd1
commit
842bd89c16
11 changed files with 355 additions and 28 deletions
|
|
@ -54,7 +54,7 @@ public sealed class PortalTunnelAssetTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void PortalTunnelCamera_UsesRetailEyeAndRotatesAroundAcUpAxis()
|
||||
public void PortalTunnelCamera_RollsAroundForwardAxisWithoutLeavingPassage()
|
||||
{
|
||||
var camera = new PortalTunnelCamera
|
||||
{
|
||||
|
|
@ -68,30 +68,103 @@ public sealed class PortalTunnelAssetTests
|
|||
|
||||
camera.DirectionDegrees = 90f;
|
||||
Assert.True(System.Numerics.Matrix4x4.Invert(camera.View, out var rotatedWorld));
|
||||
System.Numerics.Vector3 forward = System.Numerics.Vector3.Normalize(
|
||||
System.Numerics.Vector3.TransformNormal(-System.Numerics.Vector3.UnitZ, rotatedWorld));
|
||||
System.Numerics.Vector3 up = System.Numerics.Vector3.Normalize(
|
||||
System.Numerics.Vector3.TransformNormal(System.Numerics.Vector3.UnitY, rotatedWorld));
|
||||
Assert.Equal(0f, up.X, precision: 5);
|
||||
|
||||
// Frame::rotate(identity, (0, pi/2, 0)): local +Y remains the
|
||||
// camera's forward direction; local +Z rolls onto global +X.
|
||||
Assert.Equal(0f, forward.X, precision: 5);
|
||||
Assert.Equal(1f, forward.Y, precision: 5);
|
||||
Assert.Equal(0f, forward.Z, precision: 5);
|
||||
Assert.Equal(1f, up.X, precision: 5);
|
||||
Assert.Equal(0f, up.Y, precision: 5);
|
||||
Assert.Equal(1f, up.Z, precision: 5);
|
||||
Assert.Equal(0f, up.Z, precision: 5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TeleportViewPlane_FadeOutPortsRetailDistanceFovAndNearPlane()
|
||||
{
|
||||
var baseProjection = System.Numerics.Matrix4x4.CreatePerspectiveFieldOfView(
|
||||
MathF.PI / 3f,
|
||||
16f / 9f,
|
||||
0.1f,
|
||||
5000f);
|
||||
var controller = new TeleportViewPlaneController();
|
||||
controller.Begin(baseProjection);
|
||||
|
||||
controller.Update(new TeleportAnimSnapshot(
|
||||
TeleportAnimState.TunnelFadeOut,
|
||||
FadeAlpha: 0.5f,
|
||||
ShowTunnel: true,
|
||||
ShowPleaseWait: false));
|
||||
System.Numerics.Matrix4x4 projection = controller.Apply(baseProjection);
|
||||
|
||||
float gameDistance = baseProjection.M22;
|
||||
float expectedDistance = gameDistance
|
||||
+ (TeleportViewPlaneController.TransitionViewPlaneDistance - gameDistance) * 0.5f;
|
||||
float expectedNear = MathF.Max(0.1f, expectedDistance * 0.25f);
|
||||
float actualNear = projection.M43 / projection.M33;
|
||||
|
||||
Assert.True(controller.Enabled);
|
||||
Assert.Equal(expectedDistance, controller.CurrentViewPlaneDistance, precision: 5);
|
||||
Assert.Equal(expectedDistance, projection.M22, precision: 5);
|
||||
Assert.Equal(expectedNear, actualNear, precision: 5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TeleportViewPlane_WorldFadeInStartsAtRetailWideProjectionAndRestoresGameProjection()
|
||||
{
|
||||
var baseProjection = System.Numerics.Matrix4x4.CreatePerspectiveFieldOfView(
|
||||
MathF.PI / 3f,
|
||||
16f / 9f,
|
||||
0.1f,
|
||||
5000f);
|
||||
var controller = new TeleportViewPlaneController();
|
||||
controller.Begin(baseProjection);
|
||||
|
||||
controller.Update(new TeleportAnimSnapshot(
|
||||
TeleportAnimState.WorldFadeIn,
|
||||
FadeAlpha: 1f,
|
||||
ShowTunnel: false,
|
||||
ShowPleaseWait: false));
|
||||
System.Numerics.Matrix4x4 wideProjection = controller.Apply(baseProjection);
|
||||
|
||||
Assert.Equal(
|
||||
TeleportViewPlaneController.TransitionViewPlaneDistance,
|
||||
wideProjection.M22,
|
||||
precision: 5);
|
||||
Assert.Equal(0.1f, wideProjection.M43 / wideProjection.M33, precision: 5);
|
||||
|
||||
controller.Update(new TeleportAnimSnapshot(
|
||||
TeleportAnimState.Off,
|
||||
FadeAlpha: 0f,
|
||||
ShowTunnel: false,
|
||||
ShowPleaseWait: false));
|
||||
|
||||
Assert.False(controller.Enabled);
|
||||
Assert.Equal(baseProjection, controller.Apply(baseProjection));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(45f)]
|
||||
[InlineData(60f)]
|
||||
[InlineData(90f)]
|
||||
public void PortalTunnelCamera_UsesActiveSmartBoxFieldOfView(float degrees)
|
||||
public void PortalTunnelCamera_UsesActiveSmartBoxFieldOfViewAndNearPlane(float degrees)
|
||||
{
|
||||
float expected = degrees * (MathF.PI / 180f);
|
||||
var smartBoxProjection = System.Numerics.Matrix4x4.CreatePerspectiveFieldOfView(
|
||||
expected,
|
||||
16f / 9f,
|
||||
0.1f,
|
||||
0.35f,
|
||||
5000f);
|
||||
var camera = new PortalTunnelCamera();
|
||||
|
||||
camera.UseSmartBoxFov(smartBoxProjection);
|
||||
|
||||
Assert.Equal(expected, camera.FovRadians, precision: 5);
|
||||
Assert.Equal(0.35f, camera.Near, precision: 5);
|
||||
}
|
||||
|
||||
private static string? ResolveDatDir()
|
||||
|
|
|
|||
|
|
@ -8,6 +8,46 @@ namespace AcDream.App.Tests.Rendering;
|
|||
|
||||
public class RetailChaseCameraTests
|
||||
{
|
||||
[Fact]
|
||||
public void ResetViewerToPlayer_TeleportReseedsViewerAndReextendsFromPlayer()
|
||||
{
|
||||
bool savedColl = CameraDiagnostics.CollideCamera;
|
||||
float savedT = CameraDiagnostics.TranslationStiffness;
|
||||
float savedR = CameraDiagnostics.RotationStiffness;
|
||||
try
|
||||
{
|
||||
CameraDiagnostics.CollideCamera = false;
|
||||
CameraDiagnostics.TranslationStiffness = 0.45f;
|
||||
CameraDiagnostics.RotationStiffness = 0.45f;
|
||||
|
||||
var camera = new RetailChaseCamera();
|
||||
camera.Update(
|
||||
Vector3.Zero, 0f, Vector3.Zero, true, Vector3.UnitZ, 1f / 60f,
|
||||
cellId: 0x100u);
|
||||
|
||||
var destination = new Vector3(200f, -300f, 12f);
|
||||
float yaw = MathF.PI / 2f;
|
||||
camera.ResetViewerToPlayer(destination, yaw);
|
||||
|
||||
Assert.Equal(destination, camera.Position);
|
||||
Assert.Equal(0u, camera.ViewerCellId);
|
||||
|
||||
camera.Update(
|
||||
destination, yaw, Vector3.Zero, true, Vector3.UnitZ, 1f / 60f,
|
||||
cellId: 0x12340100u);
|
||||
|
||||
float firstStep = Vector3.Distance(camera.Position, destination);
|
||||
Assert.InRange(firstStep, 0.001f, 0.3f);
|
||||
Assert.Equal(0x12340100u, camera.ViewerCellId);
|
||||
}
|
||||
finally
|
||||
{
|
||||
CameraDiagnostics.CollideCamera = savedColl;
|
||||
CameraDiagnostics.TranslationStiffness = savedT;
|
||||
CameraDiagnostics.RotationStiffness = savedR;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Heading source ────────────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue