diff --git a/Engine.Integration/Engine.Integration.MonoGame/MonoGameTriangleBatch.cs b/Engine.Integration/Engine.Integration.MonoGame/MonoGameTriangleBatch.cs index f782028..5e0a5a7 100644 --- a/Engine.Integration/Engine.Integration.MonoGame/MonoGameTriangleBatch.cs +++ b/Engine.Integration/Engine.Integration.MonoGame/MonoGameTriangleBatch.cs @@ -19,8 +19,11 @@ public class MonoGameTriangleBatch : Behaviour, ITriangleBatch, IFirstFrameUpdat private BasicEffect basicEffect = null!; private readonly RasterizerState rasterizerState = new() { CullMode = CullMode.None }; + private ICamera camera = null!; + public void FirstActiveFrame() { + camera = Universe.FindRequiredBehaviour(); GraphicsDevice graphicsDevice = Universe.FindRequiredBehaviour().Window.GraphicsDevice; this.graphicsDevice = graphicsDevice; basicEffect = new(graphicsDevice); @@ -47,8 +50,8 @@ public class MonoGameTriangleBatch : Behaviour, ITriangleBatch, IFirstFrameUpdat { Viewport viewport = graphicsDevice.Viewport; - this.view = (view ?? Matrix4x4.Identity).Transposed.ToXnaMatrix(); - this.projection = (projection ?? Matrix4x4.CreateOrthographicViewCentered(viewport.Width, viewport.Height)).Transposed.ToXnaMatrix(); + this.view = (view ?? camera.ViewMatrix).Transposed.ToXnaMatrix(); + this.projection = (projection ?? camera.ProjectionMatrix).Transposed.ToXnaMatrix(); } public void End() => Flush(); diff --git a/Engine.Systems/Graphics/TriangleBatcher.cs b/Engine.Systems/Graphics/TriangleBatcher.cs index d1c78fd..872f2be 100644 --- a/Engine.Systems/Graphics/TriangleBatcher.cs +++ b/Engine.Systems/Graphics/TriangleBatcher.cs @@ -10,14 +10,10 @@ public class TriangleBatcher : Behaviour, IFirstFrameUpdate, ILastFrameUpdate, I private static System.Func GetPriority() => (b) => b.Priority; private readonly BehaviourCollector triangleBatches = new(); - private ICamera camera = null!; - private readonly ActiveBehaviourCollectorOrdered drawableShapes = new(GetPriority(), SortByAscendingPriority()); public void FirstActiveFrame() { - camera = Universe.FindRequiredBehaviour(); - drawableShapes.Assign(Universe); triangleBatches.Assign(Universe); } @@ -27,7 +23,7 @@ public class TriangleBatcher : Behaviour, IFirstFrameUpdate, ILastFrameUpdate, I for (int i = 0; i < triangleBatches.Count; i++) { ITriangleBatch triangleBatch = triangleBatches[i]; - triangleBatch.Begin(camera.ViewMatrix, camera.ProjectionMatrix); + triangleBatch.Begin(); for (int j = 0; j < drawableShapes.Count; j++) drawableShapes[j].Draw(triangleBatch); triangleBatch.End();