acdream/tests/AcDream.Core.Tests/Rendering/ChaseCameraTests.cs
Erik 84d7d06008 feat(app): Phase B.2 — ChaseCamera (third-person follow camera)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 14:26:20 +02:00

64 lines
2.2 KiB
C#

using System;
using System.Numerics;
using AcDream.App.Rendering;
using Xunit;
namespace AcDream.Core.Tests.Rendering;
public class ChaseCameraTests
{
[Fact]
public void Position_BehindPlayer_WhenYawIsZero()
{
var camera = new ChaseCamera { Aspect = 16f / 9f };
camera.Update(playerPosition: Vector3.Zero, playerYaw: 0f);
// Yaw=0 means facing +X (cos(0)=1, sin(0)=0).
// Camera should be BEHIND the player: negative X direction.
Assert.True(camera.Position.X < -1f, $"Camera X={camera.Position.X} should be behind player (negative X)");
Assert.True(camera.Position.Z > 0f, $"Camera Z={camera.Position.Z} should be above player");
}
[Fact]
public void Position_BehindPlayer_WhenYawIsHalfPi()
{
var camera = new ChaseCamera { Aspect = 16f / 9f };
camera.Update(playerPosition: Vector3.Zero, playerYaw: MathF.PI / 2f);
// Yaw=PI/2 means facing +Y. Camera should be behind: negative Y.
Assert.True(camera.Position.Y < -1f, $"Camera Y={camera.Position.Y} should be behind player (negative Y)");
}
[Fact]
public void Position_FollowsPlayerPosition()
{
var camera = new ChaseCamera { Aspect = 16f / 9f };
var playerPos = new Vector3(100f, 200f, 50f);
camera.Update(playerPosition: playerPos, playerYaw: 0f);
// Camera should be near the player, not at the origin.
Assert.InRange(camera.Position.X, 85f, 100f); // behind but close
Assert.InRange(camera.Position.Y, 195f, 205f); // roughly same Y
}
[Fact]
public void PitchAdjustment_ChangesHeight()
{
var camera = new ChaseCamera { Aspect = 16f / 9f };
camera.Update(playerPosition: Vector3.Zero, playerYaw: 0f);
float z1 = camera.Position.Z;
camera.AdjustPitch(0.2f);
camera.Update(playerPosition: Vector3.Zero, playerYaw: 0f);
float z2 = camera.Position.Z;
Assert.True(z2 > z1, "Increasing pitch should raise the camera");
}
[Fact]
public void ImplementsICamera()
{
ICamera camera = new ChaseCamera { Aspect = 16f / 9f };
camera.ToString(); // just proves interface is implemented
}
}