From bcb9925953740f20b0ade715031fd0ec6c017e42 Mon Sep 17 00:00:00 2001 From: routersys Date: Thu, 2 Jul 2026 12:52:00 +0900 Subject: [PATCH] =?UTF-8?q?=E6=8F=8F=E7=94=BB=E3=82=B3=E3=83=9E=E3=83=B3?= =?UTF-8?q?=E3=83=89=E3=81=8B=E3=82=89=E5=A4=89=E6=8F=9B=E8=A1=8C=E5=88=97?= =?UTF-8?q?=E3=82=92=E6=B1=82=E3=82=81=E3=82=8BDrawTransform=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript/DrawTransform.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 LuaScript/DrawTransform.cs diff --git a/LuaScript/DrawTransform.cs b/LuaScript/DrawTransform.cs new file mode 100644 index 0000000..a0614aa --- /dev/null +++ b/LuaScript/DrawTransform.cs @@ -0,0 +1,29 @@ +using System; +using System.Numerics; + +namespace LuaScript +{ + internal static class DrawTransform + { + public static bool TryResolve(in DrawCommand command, int srcW, int srcH, out Matrix3x2 matrix) + { + if (command.Poly is { } poly) + return DrawPolyMath.TrySolveAffine(poly, out matrix); + + double aspect = Math.Clamp(command.Aspect, -1d, 1d); + double zx = command.Zoom * (1d + aspect); + double zy = command.Zoom * (1d - aspect); + if (zx == 0d || zy == 0d) + { + matrix = Matrix3x2.Identity; + return false; + } + + matrix = + Matrix3x2.CreateTranslation(-srcW * 0.5f, -srcH * 0.5f) * + Matrix3x2.CreateScale((float)zx, (float)zy) * + Matrix3x2.CreateTranslation((float)command.Ox, (float)command.Oy); + return true; + } + } +}