From 4d1f49c30dfad3e5d6a1d12c48dcfbeeae28b3e8 Mon Sep 17 00:00:00 2001 From: kaczy Date: Thu, 30 Jan 2025 19:29:20 +0100 Subject: [PATCH] Improved precision a little bit --- CentrED/Map/MapManager.cs | 7 +++---- CentrED/Map/TileObject.cs | 3 +-- CentrED/Renderer/Shaders/MapEffect.fx | 2 +- CentrED/Renderer/Shaders/MapEffect.fxc | Bin 6676 -> 6676 bytes 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/CentrED/Map/MapManager.cs b/CentrED/Map/MapManager.cs index ac196c3..3619028 100644 --- a/CentrED/Map/MapManager.cs +++ b/CentrED/Map/MapManager.cs @@ -349,13 +349,12 @@ public Point TilePosition Client.InternalSetPos((ushort)value.X, (ushort)value.Y); } } - - //Math.Cos(MathHelper.ToRadians(-45)), Math.Sin is negative - private const float RotationConst = 0.70710676573223719f; + + private static readonly float RSQRT2 = (float)(1 / Math.Sqrt(2)); public static Vector2 ScreenToMapCoordinates(float x, float y) { - return new Vector2(x * RotationConst - y * -RotationConst, x * -RotationConst + y * RotationConst); + return new Vector2(x * RSQRT2 - y * -RSQRT2, x * -RSQRT2 + y * RSQRT2); } public Dictionary AllTiles = new(); diff --git a/CentrED/Map/TileObject.cs b/CentrED/Map/TileObject.cs index 19e86e4..107b8e5 100644 --- a/CentrED/Map/TileObject.cs +++ b/CentrED/Map/TileObject.cs @@ -2,9 +2,8 @@ public abstract class TileObject : MapObject { - public const float TILE_SIZE = 31.11f; + public static readonly float TILE_SIZE = (float)(44 / Math.Sqrt(2)); public const float TILE_Z_SCALE = 4.0f; - public const float INVERSE_SQRT2 = 0.70711f; public BaseTile Tile; public bool? Walkable; diff --git a/CentrED/Renderer/Shaders/MapEffect.fx b/CentrED/Renderer/Shaders/MapEffect.fx index 100a513..971579a 100644 --- a/CentrED/Renderer/Shaders/MapEffect.fx +++ b/CentrED/Renderer/Shaders/MapEffect.fx @@ -4,7 +4,7 @@ #define LIGHT 3 #define RGB 255 -static const float TileSize = 31.11; +static const float TileSize = 44 * rsqrt(2); static const float3 LIGHT_DIRECTION = float3(0.0f, 1.0f, 1.0f); static const float Brightlight = 1.5f; //This can be parametrized, but 1.5f is default :) diff --git a/CentrED/Renderer/Shaders/MapEffect.fxc b/CentrED/Renderer/Shaders/MapEffect.fxc index 50dad4fa952763123b43808b8b283b9ddea1a66d..068268ffd0015833fb9344b92a8af5020e1dfd4a 100644 GIT binary patch delta 19 bcmbPYGR0&=02^ELGG^Oz&o+m#?Gpw7O0Nf+ delta 19 bcmbPYGR0&=02^EWN@iP+hnvIL_6Y+3MkxmV