Reverted changes to code finding ideal triangle setup

copygirl 2 months ago
parent ea0589bb09
commit 9e8477a734
  1. 15
      terrain/Terrain.cs
  2. 3
      terrain/Tile.cs

@ -62,12 +62,19 @@ public partial class Terrain
SetTexture(tile.TexturePrimary, tile.TextureSecondary, tile.TextureBlend); 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. // 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. // 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].Height - sorted[2].Height); // Difference between lowest and 3rd lowest point.
var minDiff = Abs(sorted[0] - sorted[2]); // Difference between lowest and 3rd lowest point. var maxDiff = Abs(sorted[3].Height - sorted[1].Height); // Difference between highest and 3rd highest point.
var maxDiff = Abs(sorted[3] - sorted[1]); // Difference between highest and 3rd highest point. var first = sorted[(minDiff > maxDiff) ? 0 : 3].Corner;
var first = (Corner)sorted[(minDiff > maxDiff) ? 0 : 3];
if (first is Corner.TopLeft or Corner.BottomRight) { if (first is Corner.TopLeft or Corner.BottomRight) {
AddTriangle(corners.TopLeft , new(0.0f, 0.0f), AddTriangle(corners.TopLeft , new(0.0f, 0.0f),

@ -61,9 +61,6 @@ public struct Corners<T>(T topLeft, T topRight, T bottomRight, T bottomLeft)
} } } }
} }
public readonly T[] ToArray()
=> [ TopLeft, TopRight, BottomRight, BottomLeft ];
public readonly bool Equals(Corners<T> other) public readonly bool Equals(Corners<T> other)
=> TopLeft .Equals(other.TopLeft ) => TopLeft .Equals(other.TopLeft )
&& TopRight .Equals(other.TopRight ) && TopRight .Equals(other.TopRight )

Loading…
Cancel
Save