|
|
@ -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), |
|
|
|