From 9e8477a734e08883d7e57c4bb22621900ed4eef9 Mon Sep 17 00:00:00 2001 From: copygirl Date: Thu, 3 Oct 2024 21:15:46 +0200 Subject: [PATCH] Reverted changes to code finding ideal triangle setup --- terrain/Terrain.cs | 15 +++++++++++---- terrain/Tile.cs | 3 --- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/terrain/Terrain.cs b/terrain/Terrain.cs index 365fd7f..32b38ef 100644 --- a/terrain/Terrain.cs +++ b/terrain/Terrain.cs @@ -62,12 +62,19 @@ public partial class Terrain SetTexture(tile.TexturePrimary, tile.TextureSecondary, tile.TextureBlend); + var sorted = new (Corner Corner, float Height)[] { + (Corner.TopLeft , tile.Height.TopLeft ), + (Corner.TopRight , tile.Height.TopRight ), + (Corner.BottomRight, tile.Height.BottomRight), + (Corner.BottomLeft , tile.Height.BottomLeft ), + }; + Array.Sort(sorted, (a, b) => a.Height.CompareTo(b.Height)); + // Find the "ideal way" to split the quad for the tile into two triangles. // This is done by finding the corner with the least variance between its neighboring corners. - var sorted = tile.Height.ToArray(); Array.Sort(sorted); - var minDiff = Abs(sorted[0] - sorted[2]); // Difference between lowest and 3rd lowest point. - var maxDiff = Abs(sorted[3] - sorted[1]); // Difference between highest and 3rd highest point. - var first = (Corner)sorted[(minDiff > maxDiff) ? 0 : 3]; + var minDiff = Abs(sorted[0].Height - sorted[2].Height); // Difference between lowest and 3rd lowest point. + var maxDiff = Abs(sorted[3].Height - sorted[1].Height); // Difference between highest and 3rd highest point. + var first = sorted[(minDiff > maxDiff) ? 0 : 3].Corner; if (first is Corner.TopLeft or Corner.BottomRight) { AddTriangle(corners.TopLeft , new(0.0f, 0.0f), diff --git a/terrain/Tile.cs b/terrain/Tile.cs index 37eed4b..e825120 100644 --- a/terrain/Tile.cs +++ b/terrain/Tile.cs @@ -61,9 +61,6 @@ public struct Corners(T topLeft, T topRight, T bottomRight, T bottomLeft) } } } - public readonly T[] ToArray() - => [ TopLeft, TopRight, BottomRight, BottomLeft ]; - public readonly bool Equals(Corners other) => TopLeft .Equals(other.TopLeft ) && TopRight .Equals(other.TopRight )