2 Commits

3 changed files with 11 additions and 12 deletions

View File

@@ -113,10 +113,10 @@ public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, ILastFr
public void PreDraw()
{
ProjectionMatrix = Matrix4x4.CreateOrthographicViewCentered(Viewport.Width, Viewport.Height);
ViewMatrix =
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);
ViewMatrix = Matrix4x4.Identity
.ApplyScale(Transform.Scale.X.Max(Transform.Scale.Y))
.ApplyScale(Zoom)
.ApplyRotationZ(-Transform.Rotation * Math.DegreeToRadian)
.ApplyTranslation(new Vector3D(-Transform.Position.X, -Transform.Position.Y, 0f));
}
}

View File

@@ -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<ICamera>();
GraphicsDevice graphicsDevice = Universe.FindRequiredBehaviour<MonoGameWindowContainer>().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();

View File

@@ -10,14 +10,10 @@ public class TriangleBatcher : Behaviour, IFirstFrameUpdate, ILastFrameUpdate, I
private static System.Func<IBehaviour, int> GetPriority() => (b) => b.Priority;
private readonly BehaviourCollector<ITriangleBatch> triangleBatches = new();
private ICamera camera = null!;
private readonly ActiveBehaviourCollectorOrdered<int, IDrawableTriangle> drawableShapes = new(GetPriority(), SortByAscendingPriority());
public void FirstActiveFrame()
{
camera = Universe.FindRequiredBehaviour<ICamera>();
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();