feat(rendering): add Frustum with AABB intersection test

This commit is contained in:
MDietermann
2026-06-01 18:40:16 +02:00
parent 6c808b507b
commit 262933238c
2 changed files with 105 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
using OpenTK.Mathematics;
using VoxelEngine.Rendering;
using Xunit;
namespace VoxelEngine.Tests;
public class FrustumTests
{
// Camera at the origin, default yaw -90° → looks down -Z.
private static Frustum MakeFrustum()
{
var cam = new Camera(new Vector3(0, 0, 0), 16f / 9f);
return Frustum.FromViewProjection(cam.GetViewMatrix() * cam.GetProjectionMatrix());
}
[Fact]
public void AABBInFront_IsVisible()
{
var f = MakeFrustum();
Assert.True(f.Intersects(new Vector3(-2, -2, -22), new Vector3(2, 2, -18)));
}
[Fact]
public void AABBBehindCamera_IsCulled()
{
var f = MakeFrustum();
Assert.False(f.Intersects(new Vector3(-2, -2, 18), new Vector3(2, 2, 22)));
}
[Fact]
public void AABBStraddlingCamera_Intersects()
{
var f = MakeFrustum();
Assert.True(f.Intersects(new Vector3(-2, -2, -5), new Vector3(2, 2, 5)));
}
[Fact]
public void AABBFarToTheSide_IsCulled()
{
var f = MakeFrustum();
// Far along +X at a depth in front of the camera — outside horizontal FOV.
Assert.False(f.Intersects(new Vector3(1000, -2, -5), new Vector3(1004, 2, -1)));
}
}