79 lines
2.2 KiB
C#
79 lines
2.2 KiB
C#
using Engine.Graphics.Camera;
|
|
using Engine.Graphics.Pipeline;
|
|
using OpenTK.Mathematics;
|
|
|
|
namespace Engine.Scene.Component.BuiltIn;
|
|
|
|
/// <summary>
|
|
/// Abstract base class for cameras that provide view and projection matrices.
|
|
/// </summary>
|
|
public abstract class Camera : Component, ICamera
|
|
{
|
|
/// <inheritdoc/>
|
|
public abstract Matrix4 View { get; }
|
|
|
|
/// <inheritdoc/>
|
|
public abstract Matrix4 Projection { get; }
|
|
|
|
/// <inheritdoc/>
|
|
public Vector2i ScreenSize
|
|
{
|
|
get => _screenSize;
|
|
set
|
|
{
|
|
_screenSize = value;
|
|
AspectRatio = (float)value.X / value.Y;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The aspect ratio of the camera, calculated as width divided by height.
|
|
/// </summary>
|
|
public float AspectRatio { get; private set; } = 1;
|
|
|
|
/// <summary>
|
|
/// The near clipping plane distance.
|
|
/// </summary>
|
|
public float NearPlane { get; set; }
|
|
|
|
/// <summary>
|
|
/// The far clipping plane distance.
|
|
/// </summary>
|
|
public float FarPlane { get; set; }
|
|
|
|
/// <summary>
|
|
/// The render layer for the camera.
|
|
/// </summary>
|
|
public RenderLayer RenderLayer { get; set; } = RenderLayer.DEFAULT;
|
|
|
|
|
|
/// <summary>
|
|
/// The screen size of the camera.
|
|
/// </summary>
|
|
private Vector2i _screenSize = new(1, 1);
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="Camera"/> class.
|
|
/// </summary>
|
|
/// <param name="parNearPlane">The near clipping plane distance.</param>
|
|
/// <param name="parFarPlane">The far clipping plane distance.</param>
|
|
protected Camera(float parNearPlane, float parFarPlane)
|
|
{
|
|
NearPlane = parNearPlane;
|
|
FarPlane = parFarPlane;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a screen position to a world position in 3D space.
|
|
/// </summary>
|
|
/// <param name="parScreenPosition">The screen position to convert.</param>
|
|
/// <returns>The corresponding world position.</returns>
|
|
public abstract Vector3 ScreenToWorld(Vector2 parScreenPosition);
|
|
|
|
/// <summary>
|
|
/// Converts a world position to a screen position in 2D space.
|
|
/// </summary>
|
|
/// <param name="parWorldPosition">The world position to convert.</param>
|
|
/// <returns>The corresponding screen position.</returns>
|
|
public abstract Vector2 WorldToScreen(Vector3 parWorldPosition);
|
|
} |