chore: bumped dotnet version to 10

This commit is contained in:
2026-01-23 12:16:07 +03:00
parent 097f1897c2
commit 90e59802c6
32 changed files with 210 additions and 257 deletions

View File

@@ -11,26 +11,21 @@ public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, ILastFr
public Event<MonoGameCamera2D> OnViewportChanged { get; } = new();
public Event<MonoGameCamera2D> OnZoomChanged { get; } = new();
private Matrix _matrixTransform = Matrix.Identity;
private Viewport _viewport = default;
private float _zoom = 1f;
public GraphicsDeviceManager Graphics { get; private set; } = null!;
public ITransform2D Transform { get; private set; } = null!;
public Matrix MatrixTransform
{
get => _matrixTransform;
get;
set
{
if (_matrixTransform == value)
if (field == value)
return;
_matrixTransform = value;
field = value;
OnMatrixTransformChanged.Invoke(this);
}
}
} = Matrix.Identity;
public Vector2D Position
{
@@ -40,31 +35,31 @@ public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, ILastFr
public Viewport Viewport
{
get => _viewport;
get;
set
{
if (_viewport.Equals(value))
if (field.Equals(value))
return;
_viewport = value;
field = value;
OnViewportChanged.Invoke(this);
}
}
} = default;
public float Zoom
{
get => _zoom;
get;
set
{
float newValue = Math.Max(0.1f, value);
if (_zoom == newValue)
if (field == newValue)
return;
_zoom = newValue;
field = newValue;
OnZoomChanged.Invoke(this);
}
}
} = 1f;
public float Rotation
{
@@ -99,6 +94,6 @@ public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, ILastFr
Matrix.CreateRotationZ(Rotation * Math.DegreeToRadian) *
Matrix.CreateScale(Transform.Scale.X.Max(Transform.Scale.Y)) *
Matrix.CreateScale(Zoom) *
Matrix.CreateTranslation(new Vector3(_viewport.Width * .5f, _viewport.Height * .5f, 0f));
Matrix.CreateTranslation(new Vector3(Viewport.Width * .5f, Viewport.Height * .5f, 0f));
}
}

View File

@@ -15,12 +15,7 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, ILastFr
public Event<ICamera3D, ICamera3D.FarPlaneChangedArguments> OnFarPlaneChanged { get; } = new();
public Event<ICamera3D, ICamera3D.FieldOfViewChangedArguments> OnFieldOfViewChanged { get; } = new();
private Matrix _view = Matrix.Identity;
private Matrix _projection = Matrix.Identity;
private Viewport _viewport = default;
private float _nearPlane = 0.01f;
private float _farPlane = 100f;
private float _fieldOfView = Math.DegreeToRadian * 70f;
private float fieldOfView = Math.DegreeToRadian * 70f;
private bool isRecalculationNeeded = true;
public GraphicsDeviceManager Graphics { get; private set; } = null!;
@@ -28,41 +23,42 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, ILastFr
public Matrix View
{
get => _view;
get;
set
{
if (_view == value)
if (field == value)
return;
Matrix previousView = _view;
_view = value;
Matrix previousView = field;
field = value;
OnViewChanged.Invoke(this, new(previousView));
}
}
} = Matrix.Identity;
public Matrix Projection
{
get => _projection;
get;
set
{
if (_projection == value)
if (field == value)
return;
Matrix previousProjection = _projection;
_projection = value;
Matrix previousProjection = field;
field = value;
OnProjectionChanged.Invoke(this, new(previousProjection));
}
}
} = Matrix.Identity;
public Viewport Viewport
{
get => _viewport;
get;
set
{
if (_viewport.Equals(value))
if (field.Equals(value))
return;
Viewport previousViewport = _viewport;
_viewport = value;
Viewport previousViewport = field;
field = value;
SetForRecalculation();
OnViewportChanged.Invoke(this, new(previousViewport));
}
@@ -70,40 +66,40 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, ILastFr
public float NearPlane
{
get => _nearPlane;
get;
set
{
float previousNearPlane = _nearPlane;
_nearPlane = value.Max(0.0001f);
float previousNearPlane = field;
field = value.Max(0.0001f);
SetForRecalculation();
OnNearPlaneChanged.Invoke(this, new(previousNearPlane));
}
}
} = 0.01f;
public float FarPlane
{
get => _farPlane;
get;
set
{
float previousFarPlane = _farPlane;
_farPlane = value.Max(NearPlane);
float previousFarPlane = field;
field = value.Max(NearPlane);
SetForRecalculation();
OnFarPlaneChanged.Invoke(this, new(previousFarPlane));
}
}
} = 100f;
public float FieldOfView
{
get => _fieldOfView * Math.RadianToDegree;
get => fieldOfView * Math.RadianToDegree;
set
{
value = value.Max(0.1f) * Math.DegreeToRadian;
if (_fieldOfView == value)
if (fieldOfView == value)
return;
float previousFieldOfView = _fieldOfView;
_fieldOfView = value;
float previousFieldOfView = fieldOfView;
fieldOfView = value;
SetForRecalculation();
OnFieldOfViewChanged.Invoke(this, new(previousFieldOfView));
}
@@ -115,14 +111,14 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, ILastFr
Vector3 nearPoint = new(screenPosition.X, screenPosition.Y, 0f);
Vector3 farPoint = new(screenPosition.X, screenPosition.Y, 1f);
Vector3 worldNear = Viewport.Unproject(nearPoint, _projection, _view, Matrix.Identity);
Vector3 worldFar = Viewport.Unproject(farPoint, _projection, _view, Matrix.Identity);
Vector3 worldNear = Viewport.Unproject(nearPoint, Projection, View, Matrix.Identity);
Vector3 worldFar = Viewport.Unproject(farPoint, Projection, View, Matrix.Identity);
Vector3 direction = Vector3.Normalize(worldFar - worldNear);
return new(worldNear.ToVector3D(), direction.ToVector3D());
}
public Vector2D WorldToScreenPosition(Vector3D worldPosition) => Viewport.Project(worldPosition.ToVector3(), _projection, _view, Matrix.Identity).ToVector3D();
public Vector2D WorldToScreenPosition(Vector3D worldPosition) => Viewport.Project(worldPosition.ToVector3(), Projection, View, Matrix.Identity).ToVector3D();
public void LastActiveFrame() => Transform.OnTransformUpdated.RemoveListener(SetDirtyOnTransformUpdate);
public void FirstActiveFrame()
@@ -167,14 +163,14 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, ILastFr
private void CalculateProjection()
{
float yScale = 1f / (float)Math.Tan(_fieldOfView / 2f);
float yScale = 1f / (float)Math.Tan(fieldOfView / 2f);
float xScale = yScale / Viewport.AspectRatio;
Projection = new Matrix(
xScale, 0, 0, 0,
0, yScale, 0, 0,
0, 0, _farPlane / (_farPlane - _nearPlane), 1,
0, 0, -_nearPlane * _farPlane / (_farPlane - _nearPlane), 0
0, 0, FarPlane / (FarPlane - NearPlane), 1,
0, 0, -NearPlane * FarPlane / (FarPlane - NearPlane), 0
);
}

View File

@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Engine.Integration.MonoGame</RootNamespace>

View File

@@ -1,4 +1,4 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Engine.Core;

View File

@@ -8,12 +8,14 @@ namespace Engine.Integration.MonoGame;
public class TriangleBatch : ITriangleBatch
{
private readonly GraphicsDevice graphicsDevice;
private VertexBuffer vertexBuffer = default!;
private readonly VertexBuffer vertexBuffer = default!;
private readonly VertexPositionColor[] vertices = new VertexPositionColor[1024];
private int verticesIndex = 0;
private Matrix _view;
private Matrix _projection;
private readonly BasicEffect basicEffect;
private Matrix view = Matrix.Identity;
private Matrix projection = Matrix.Identity;
private readonly BasicEffect basicEffect = null!;
private readonly RasterizerState rasterizerState = new() { CullMode = CullMode.None };
public TriangleBatch(GraphicsDevice graphicsDevice)
@@ -42,16 +44,16 @@ public class TriangleBatch : ITriangleBatch
public void Begin(Matrix? view = null, Matrix? projection = null)
{
if (view != null)
_view = view.Value;
this.view = view.Value;
else
_view = Matrix.Identity;
this.view = Matrix.Identity;
if (projection != null)
_projection = projection.Value;
this.projection = projection.Value;
else
{
Viewport viewport = graphicsDevice.Viewport;
_projection = Matrix.CreateOrthographicOffCenter(viewport.X, viewport.Width, viewport.Height, viewport.Y, 0, 1);
this.projection = Matrix.CreateOrthographicOffCenter(viewport.X, viewport.Width, viewport.Height, viewport.Y, 0, 1);
}
}
@@ -63,8 +65,8 @@ public class TriangleBatch : ITriangleBatch
return;
graphicsDevice.RasterizerState = rasterizerState;
basicEffect.Projection = _projection;
basicEffect.View = _view;
basicEffect.Projection = projection;
basicEffect.View = view;
vertexBuffer.SetData(vertices);
graphicsDevice.SetVertexBuffer(vertexBuffer);