From d0be78d0793bdc6a3989e0f72a9da343a39bbb73 Mon Sep 17 00:00:00 2001 From: Amy <3855802+amylizzle@users.noreply.github.com> Date: Fri, 19 Jul 2024 03:41:33 +0100 Subject: [PATCH] FIxed transforms applying to mousemaps (#1889) --- OpenDreamClient/Rendering/DreamPlane.cs | 2 +- OpenDreamClient/Rendering/DreamViewOverlay.cs | 38 ++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/OpenDreamClient/Rendering/DreamPlane.cs b/OpenDreamClient/Rendering/DreamPlane.cs index ac4b95787c..6ea68051a3 100644 --- a/OpenDreamClient/Rendering/DreamPlane.cs +++ b/OpenDreamClient/Rendering/DreamPlane.cs @@ -92,7 +92,7 @@ public void DrawMouseMap(DrawingHandleWorld handle, DreamViewOverlay overlay, Ve Color targetColor = new Color(colorR, colorG, colorB); //TODO - this could result in mis-clicks due to hash-collision since we ditch a whole byte. overlay.MouseMapLookup[targetColor] = sprite; - handle.SetTransform(DreamViewOverlay.CreateRenderTargetFlipMatrix(renderTargetSize, pos)); + handle.SetTransform(DreamViewOverlay.CalculateDrawingMatrix(sprite.TransformToApply, pos, texture.Size, renderTargetSize)); handle.DrawTextureRect(texture, new Box2(Vector2.Zero, texture.Size), targetColor); } } diff --git a/OpenDreamClient/Rendering/DreamViewOverlay.cs b/OpenDreamClient/Rendering/DreamViewOverlay.cs index 0e65a6111e..b378ed1422 100644 --- a/OpenDreamClient/Rendering/DreamViewOverlay.cs +++ b/OpenDreamClient/Rendering/DreamViewOverlay.cs @@ -405,23 +405,7 @@ public void DrawIcon(DrawingHandleWorld handle, Vector2i renderTargetSize, Rende handle.UseShader(GetBlendAndColorShader(iconMetaData, ignoreColor: true)); - //extract scale component of transform - var transform = iconMetaData.TransformToApply; - Vector2 scaleFactors = new Vector2( - MathF.Sqrt(MathF.Pow(transform.M11,2) + MathF.Pow(transform.M12,2)), - MathF.Sqrt(MathF.Pow(transform.M21,2) + MathF.Pow(transform.M22,2)) - ); - transform.M11 /= scaleFactors.X; - transform.M12 /= scaleFactors.X; - transform.M21 /= scaleFactors.Y; - transform.M22 /= scaleFactors.Y; - - handle.SetTransform( - Matrix3x2.CreateTranslation(-frame.Size/2) //translate to origin - * transform //rotate and translate - * Matrix3x2.CreateTranslation(frame.Size/2) //translate back to original position - * Matrix3x2.CreateScale(scaleFactors) //scale - * CreateRenderTargetFlipMatrix(renderTargetSize, pixelPosition-((scaleFactors-Vector2.One)*frame.Size/2))); //flip and apply scale-corrected translation + handle.SetTransform(CalculateDrawingMatrix(iconMetaData.TransformToApply, pixelPosition, frame.Size, renderTargetSize)); handle.DrawTextureRect(frame, Box2.FromDimensions(Vector2.Zero, frame.Size)); } @@ -778,6 +762,26 @@ public static Matrix3x2 CreateRenderTargetFlipMatrix(Vector2i renderTargetSize, // We must also handle translations here, since RT applies its own transform in an unexpected order return FlipMatrix * Matrix3x2.CreateTranslation(renderPosition.X, renderTargetSize.Y - renderPosition.Y); } + + public static Matrix3x2 CalculateDrawingMatrix(Matrix3x2 transform, Vector2 pixelPosition, Vector2i frameSize, Vector2i renderTargetSize) { + //extract scale component of transform + Vector2 scaleFactors = new Vector2( + MathF.Sqrt(MathF.Pow(transform.M11,2) + MathF.Pow(transform.M12,2)), + MathF.Sqrt(MathF.Pow(transform.M21,2) + MathF.Pow(transform.M22,2)) + ); + transform.M11 /= scaleFactors.X; + transform.M12 /= scaleFactors.X; + transform.M21 /= scaleFactors.Y; + transform.M22 /= scaleFactors.Y; + + return + Matrix3x2.CreateTranslation(-frameSize/2) //translate to origin + * transform //rotate and translate + * Matrix3x2.CreateTranslation(frameSize/2) //translate back to original position + * Matrix3x2.CreateScale(scaleFactors) //scale + * CreateRenderTargetFlipMatrix(renderTargetSize, pixelPosition-((scaleFactors-Vector2.One)*frameSize/2)); //flip and apply scale-corrected translation + + } } internal sealed class RendererMetaData : IComparable {