Center tile heightmap around (0,0).

WorldChunkRefactoring
Martin Felis 2023-04-30 15:33:46 +02:00
parent 37d9497379
commit e5b73930ce
1 changed files with 10 additions and 6 deletions

View File

@ -40,9 +40,9 @@ public class TileWorld : Spatial
Heightmap.Create((int)Size.x, (int)Size.y, false, Image.Format.Rf);
Heightmap.Lock();
foreach (int coord_x in Enumerable.Range(0, (int)Size.x))
foreach (int coord_x in Enumerable.Range(-(int) Size.x / 2, (int)Size.x))
{
foreach (int coord_y in Enumerable.Range(0, (int)Size.y))
foreach (int coord_y in Enumerable.Range(-(int) Size.y / 2, (int)Size.y))
{
SetHeightAtOffset(new Vector2(coord_x, coord_y), 5f);
}
@ -75,8 +75,8 @@ public class TileWorld : Spatial
public bool IsOffsetCoordValid(Vector2 offset_coord)
{
return ((int)Math.Clamp(offset_coord.x, 0, Size.x) == (int)offset_coord.x
&& (int)Math.Clamp(offset_coord.y, 0, Size.y) == (int)offset_coord.y);
return ((int)Math.Clamp(offset_coord.x, -Size.x / 2, Size.x / 2 - 1) == (int)offset_coord.x
&& (int)Math.Clamp(offset_coord.y, -Size.y / 2, Size.y / 2 - 1) == (int)offset_coord.y);
}
@ -98,7 +98,9 @@ public class TileWorld : Spatial
return;
}
Heightmap.SetPixel((int) offset_coord.x, (int) offset_coord.y, new Color(height / HeightScale, 0f, 0f));
Vector2 texture_coord = offset_coord + Size / 2;
Heightmap.SetPixel((int) texture_coord.x, (int) texture_coord.y, new Color(height / HeightScale, 0f, 0f));
}
public float GetHeightAtOffset(Vector2 offset_coord)
@ -108,7 +110,9 @@ public class TileWorld : Spatial
return 0;
}
return Heightmap.GetPixel((int)offset_coord.x, (int)offset_coord.y).r * HeightScale - HeightScale * 0.5f ;
Vector2 texture_coord = offset_coord + Size / 2;
return Heightmap.GetPixel((int)texture_coord.x, (int)texture_coord.y).r * HeightScale - HeightScale * 0.5f ;
}