Skip to content

Commit

Permalink
Improved precision a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Jan 30, 2025
1 parent 000688a commit 4d1f49c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
7 changes: 3 additions & 4 deletions CentrED/Map/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, TileObject> AllTiles = new();
Expand Down
3 changes: 1 addition & 2 deletions CentrED/Map/TileObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion CentrED/Renderer/Shaders/MapEffect.fx
Original file line number Diff line number Diff line change
Expand Up @@ -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 :)

Expand Down
Binary file modified CentrED/Renderer/Shaders/MapEffect.fxc
Binary file not shown.

0 comments on commit 4d1f49c

Please sign in to comment.