feat(rendering): add Frustum with AABB intersection test
This commit is contained in:
44
VoxelEngine.Tests/FrustumTests.cs
Normal file
44
VoxelEngine.Tests/FrustumTests.cs
Normal 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)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user