From b2715189561990c794cda88dc20d6d65156ddbd5 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 19 Oct 2021 22:06:49 +0200 Subject: [PATCH] Exposed Camera's RoundPosition --- CHANGELOG.md | 3 +++ MLEM/Cameras/Camera.cs | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5da4032..2fccb82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ Additions - Added GenericFont SplitStringSeparate which differentiates between existing newline characters and splits due to maximum width - Added StaticSpriteBatch class +Improvements +- Exposed Camera's RoundPosition + ### MLEM.Ui Additions - Allow specifying a maximum amount of characters for a TextField diff --git a/MLEM/Cameras/Camera.cs b/MLEM/Cameras/Camera.cs index f84f292..7f119ba 100644 --- a/MLEM/Cameras/Camera.cs +++ b/MLEM/Cameras/Camera.cs @@ -58,7 +58,7 @@ namespace MLEM.Cameras { get { var sc = this.ActualScale; var pos = -this.Position * sc; - if (this.roundPosition) + if (this.RoundPosition) pos = pos.FloorCopy(); return Matrix.CreateScale(sc, sc, 1) * Matrix.CreateTranslation(new Vector3(pos, 0)); } @@ -82,9 +82,13 @@ namespace MLEM.Cameras { /// The viewport of this camera, based on the game's and this camera's /// public Vector2 ScaledViewport => new Vector2(this.Viewport.Width, this.Viewport.Height) / this.ActualScale; + /// + /// Whether the camera's should be rounded to full integers when calculating the . + /// If this value is true, the occurence of rendering fragments due to floating point rounding might be reduced. + /// + public bool RoundPosition; private Rectangle Viewport => this.graphicsDevice.Viewport.Bounds; - private readonly bool roundPosition; private readonly GraphicsDevice graphicsDevice; private float scale = 1; @@ -92,11 +96,11 @@ namespace MLEM.Cameras { /// Creates a new camera. /// /// The game's graphics device - /// If this is true, the camera's and related properties will be rounded to full integers. + /// Whether the camera's should be rounded to full integers when calculating the public Camera(GraphicsDevice graphicsDevice, bool roundPosition = true) { this.graphicsDevice = graphicsDevice; this.AutoScaleReferenceSize = this.Viewport.Size; - this.roundPosition = roundPosition; + this.RoundPosition = roundPosition; } ///