using NativeEngine;
namespace Sandbox;
///
/// Access screen dimension etc.
///
public static class Screen
{
///
/// The total size of the game screen
///
public static Vector2 Size { get; internal set; }
///
/// The width of the game screen. Equal to Screen.x
///
public static float Width => Size.x;
///
/// The height of the game screen. Equal to Screen.y
///
public static float Height => Size.y;
///
/// The aspect ratio of the screen. Equal to Width/Height
///
public static float Aspect => Width / Height;
///
/// The desktop's dpi scale on the current monitor.
///
public static float DesktopScale { get; private set; } = 1.0f;
internal static void UpdateFromEngine()
{
ThreadSafe.AssertIsMainThread();
var width = 1024;
var height = 1024;
if ( !Application.IsUnitTest )
{
g_pEngineServiceMgr.GetEngineSwapChainSize( out width, out height );
}
var newSize = new Vector2( width, height );
if ( newSize == Size )
return;
Size = new Vector2( width, height );
RenderTarget.Flush();
DesktopScale = EngineGlobal.GetDiagonalDpi() / 96.0f;
}
///
/// Converts a vertical field of view to a horizontal field of view based on the screen aspect ratio.
///
public static float CreateVerticalFieldOfView( float fieldOfView )
{
return CreateVerticalFieldOfView( fieldOfView, Aspect );
}
///
/// Converts a vertical field of view to a horizontal field of view based on the given aspect ratio.
///
public static float CreateVerticalFieldOfView( float fieldOfView, float aspectRatio )
{
float t = MathF.Tan( fieldOfView.DegreeToRadian() * 0.5f );
return MathF.Atan( t * aspectRatio ).RadianToDegree() * 2.0f;
}
}