mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-08-01 00:08:05 -04:00
* Guard Aspect against NaN and build CameraComponent FoV from current camera rect instead of screen's Getting screen's aspect is actually wrong if we have more than one camera in play (eg splitscreen) Screen.Aspect not being set until playing is our intended behaviour for what I remember Fixes https://github.com/Facepunch/sbox/issues/5319 * Add tests and update comment
34 lines
839 B
C#
34 lines
839 B
C#
namespace EngineTests;
|
|
|
|
[TestClass]
|
|
public class ScreenTest
|
|
{
|
|
[TestMethod]
|
|
public void AspectIsFiniteBeforeScreenSizeIsKnown()
|
|
{
|
|
var oldSize = Screen.Size;
|
|
|
|
try
|
|
{
|
|
// Before first play the swapchain reports (0, 0) — https://github.com/Facepunch/sbox/issues/5319
|
|
Screen.Size = new Vector2( 0, 0 );
|
|
Assert.AreEqual( 1f, Screen.Aspect );
|
|
Assert.IsTrue( float.IsFinite( Screen.CreateVerticalFieldOfView( 90f ) ) );
|
|
|
|
Screen.Size = new Vector2( 1920, 1080 );
|
|
Assert.AreEqual( 1920f / 1080f, Screen.Aspect );
|
|
}
|
|
finally
|
|
{
|
|
Screen.Size = oldSize;
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CreateVerticalFieldOfViewWithExplicitAspect()
|
|
{
|
|
// 90° through the inverse 16:9 aspect gives the classic 58.72° vertical fov
|
|
Assert.AreEqual( 58.7155f, Screen.CreateVerticalFieldOfView( 90f, 1080f / 1920f ), 0.001f );
|
|
}
|
|
}
|