BREAKING CHANGE: 4x4 matrices are now column major
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Integration.MonoGame;
|
||||
|
||||
public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, ILastFrameUpdate, IPreDraw
|
||||
public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, ILastFrameUpdate, IPreDraw, IUpdate
|
||||
{
|
||||
public Event<MonoGameCamera2D> OnViewMatrixChanged { get; } = new();
|
||||
public Event<MonoGameCamera2D> OnProjectionMatrixChanged { get; } = new();
|
||||
@@ -91,12 +92,20 @@ public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, ILastFr
|
||||
|
||||
public void PreDraw()
|
||||
{
|
||||
ProjectionMatrix = Matrix.CreateOrthographicOffCenter(Viewport.X, Viewport.Width, Viewport.Height, Viewport.Y, 0, 1).FromXnaMatrix();
|
||||
ProjectionMatrix = Matrix4x4.CreateOrthographicViewCentered(Viewport.Width, -Viewport.Height);
|
||||
ViewMatrix =
|
||||
Matrix4x4.CreateTranslation(new Vector3D(-Transform.Position.X, Transform.Position.Y, 0f)) *
|
||||
Matrix4x4.CreateRotationZ(Transform.Rotation * Math.DegreeToRadian) *
|
||||
Matrix4x4.CreateScale(Transform.Scale.X.Max(Transform.Scale.Y)) *
|
||||
Matrix4x4.CreateScale(Zoom) *
|
||||
Matrix4x4.CreateTranslation(new Vector3D(Viewport.Width * .5f, Viewport.Height * .5f, 0f));
|
||||
Matrix4x4.CreateTranslation(new Vector3D(-Transform.Position.X, Transform.Position.Y, 0f))
|
||||
.ApplyRotationZ(Transform.Rotation * Math.DegreeToRadian)
|
||||
.ApplyScale(Transform.Scale.X.Max(Transform.Scale.Y))
|
||||
.ApplyScale(Zoom);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
KeyboardInputs keyboardInputs = Universe.FindRequiredBehaviour<KeyboardInputs>();
|
||||
if (keyboardInputs.IsPressed(Keys.Right)) Transform.Position += Transform.Right * Universe.Time.DeltaTime * 100;
|
||||
if (keyboardInputs.IsPressed(Keys.Up)) Transform.Position += Transform.Up * Universe.Time.DeltaTime * 100;
|
||||
if (keyboardInputs.IsPressed(Keys.Down)) Transform.Position += Transform.Down * Universe.Time.DeltaTime * 100;
|
||||
if (keyboardInputs.IsPressed(Keys.Left)) Transform.Position += Transform.Left * Universe.Time.DeltaTime * 100;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,18 +45,10 @@ public class MonoGameTriangleBatch : Behaviour, ITriangleBatch, IFirstFrameUpdat
|
||||
|
||||
public void Begin(Matrix4x4? view = null, Matrix4x4? projection = null)
|
||||
{
|
||||
if (view != null)
|
||||
this.view = view.Value.ToXnaMatrix();
|
||||
else
|
||||
this.view = Matrix.Identity;
|
||||
Viewport viewport = graphicsDevice.Viewport;
|
||||
|
||||
if (projection != null)
|
||||
this.projection = projection.Value.ToXnaMatrix();
|
||||
else
|
||||
{
|
||||
Viewport viewport = graphicsDevice.Viewport;
|
||||
this.projection = Matrix.CreateOrthographicOffCenter(viewport.X, viewport.Width, viewport.Height, viewport.Y, 0, 1);
|
||||
}
|
||||
this.view = (view ?? Matrix4x4.Identity).Transposed.ToXnaMatrix();
|
||||
this.projection = (projection ?? Matrix4x4.CreateOrthographicViewCentered(viewport.Width, viewport.Height)).Transposed.ToXnaMatrix();
|
||||
}
|
||||
|
||||
public void End() => Flush();
|
||||
|
||||
Reference in New Issue
Block a user