ScriptGlue: Added Camera component and throwing mono exceptions from beef

This commit is contained in:
Simon Lübeß
2024-01-15 01:22:52 +01:00
parent ceb4241216
commit 60b45828c2
4 changed files with 439 additions and 6 deletions
+162
View File
@@ -0,0 +1,162 @@
using System;
namespace GlitchyEngine.Core;
/// <summary>
/// The type of projection used by a camera.
/// </summary>
public enum ProjectionType : byte
{
/// <summary>
/// An orthographic projection.
/// </summary>
Orthographic = 0,
/// <summary>
/// A perspective projection.
/// </summary>
Perspective = 1,
/// <summary>
/// A perspective projection where the far plane is infinitely far away from the camera.
/// </summary>
InfinitePerspective = 2
}
/// <summary>
/// A component representing a camera that is attached to the entity.
/// </summary>
public class Camera : Component
{
/// <summary>
/// The projection type of the <see cref="Camera"/>.
/// </summary>
public ProjectionType ProjectionType
{
get
{
ScriptGlue.Camera_GetProjectionType(_uuid, out ProjectionType projectionType);
return projectionType;
}
set => ScriptGlue.Camera_SetProjectionType(_uuid, value);
}
/// <summary>
/// Gets or sets the Y field of view in perspective mode.
/// </summary>
public float PerspectiveFovY
{
get
{
ScriptGlue.Camera_GetPerspectiveFovY(_uuid, out float fovY);
return fovY;
}
set => ScriptGlue.Camera_SetPerspectiveFovY(_uuid, value);
}
/// <summary>
/// Gets or sets the X field of view in perspective mode.
/// </summary>
public float PerspectiveFovX
{
get => PerspectiveFovY * AspectRatio;
set => PerspectiveFovY = value / AspectRatio;
}
/// <summary>
/// Gets or sets the near plane distance in perspective mode.
/// </summary>
public float PerspectiveNearPlane
{
get
{
ScriptGlue.Camera_GetPerspectiveNearPlane(_uuid, out float nearPlane);
return nearPlane;
}
set => ScriptGlue.Camera_SetPerspectiveNearPlane(_uuid, value);
}
/// <summary>
/// Gets or sets the far plane distance in perspective mode.
/// </summary>
public float PerspectiveFarPlane
{
get
{
ScriptGlue.Camera_GetPerspectiveFarPlane(_uuid, out float farPlane);
return farPlane;
}
set => ScriptGlue.Camera_SetPerspectiveFarPlane(_uuid, value);
}
/// <summary>
/// Gets or sets the orthographic height.
/// </summary>
public float OrthographicHeight
{
get
{
ScriptGlue.Camera_GetOrthographicHeight(_uuid, out float height);
return height;
}
set => ScriptGlue.Camera_SetOrthographicHeight(_uuid, value);
}
/// <summary>
/// Gets or sets the near plane distance in orthographic mode.
/// </summary>
public float OrthographicNearPlane
{
get
{
ScriptGlue.Camera_GetOrthographicNearPlane(_uuid, out float nearPlane);
return nearPlane;
}
set => ScriptGlue.Camera_SetOrthographicNearPlane(_uuid, value);
}
/// <summary>
/// Gets or sets the far plane distance in orthographic mode.
/// </summary>
public float OrthographicFarPlane
{
get
{
ScriptGlue.Camera_GetOrthographicFarPlane(_uuid, out float farPlane);
return farPlane;
}
set => ScriptGlue.Camera_SetOrthographicFarPlane(_uuid, value);
}
/// <summary>
/// Gets or sets the aspect ratio.
/// </summary>
/// <exception cref="ArgumentException">The setter throws an <see cref="ArgumentException"/>, when <see langword="value"/> is zero.</exception>
public float AspectRatio
{
get
{
ScriptGlue.Camera_GetAspectRatio(_uuid, out float aspectRatio);
return aspectRatio;
}
set
{
if (value == 0)
throw new ArgumentException($"{AspectRatio} must not be zero.");
ScriptGlue.Camera_SetAspectRatio(_uuid, value);
}
}
/// <summary>
/// Gets or sets a value indicating whether the aspect ratio is fixed.
/// </summary>
public bool FixedAspectRatio
{
get
{
ScriptGlue.Camera_GetFixedAspectRatio(_uuid, out bool fixedAspectRatio);
return fixedAspectRatio;
}
set => ScriptGlue.Camera_SetFixedAspectRatio(_uuid, value);
}
}
+51
View File
@@ -109,6 +109,57 @@ internal static class ScriptGlue
#endregion RigidBody2D
#region Camera
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_GetProjectionType(UUID entityId, out ProjectionType projectionType);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_SetProjectionType(UUID entityId, in ProjectionType projectionType);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_GetPerspectiveFovY(UUID entityId, out float fovY);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_SetPerspectiveFovY(UUID entityId, float fovY);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_GetPerspectiveNearPlane(UUID entityId, out float nearPlane);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_SetPerspectiveNearPlane(UUID entityId, float nearPlane);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_GetPerspectiveFarPlane(UUID entityId, out float farPlane);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_SetPerspectiveFarPlane(UUID entityId, float farPlane);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_GetOrthographicHeight(UUID entityId, out float height);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_SetOrthographicHeight(UUID entityId, float height);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_GetOrthographicNearPlane(UUID entityId, out float nearPlane);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_SetOrthographicNearPlane(UUID entityId, float nearPlane);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_GetOrthographicFarPlane(UUID entityId, out float farPlane);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_SetOrthographicFarPlane(UUID entityId, float farPlane);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_GetAspectRatio(UUID entityId, out float aspectRatio);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_SetAspectRatio(UUID entityId, float aspectRatio);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_GetFixedAspectRatio(UUID entityId, out bool fixedAspectRatio);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Camera_SetFixedAspectRatio(UUID entityId, bool fixedAspectRatio);
#endregion
#region Physics2D
[MethodImpl(MethodImplOptions.InternalCall)]