chore: bumped dotnet version to 10
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user