Center tile heightmap around (0,0).
parent
37d9497379
commit
e5b73930ce
|
@ -40,9 +40,9 @@ public class TileWorld : Spatial
|
||||||
Heightmap.Create((int)Size.x, (int)Size.y, false, Image.Format.Rf);
|
Heightmap.Create((int)Size.x, (int)Size.y, false, Image.Format.Rf);
|
||||||
Heightmap.Lock();
|
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);
|
SetHeightAtOffset(new Vector2(coord_x, coord_y), 5f);
|
||||||
}
|
}
|
||||||
|
@ -75,8 +75,8 @@ public class TileWorld : Spatial
|
||||||
|
|
||||||
public bool IsOffsetCoordValid(Vector2 offset_coord)
|
public bool IsOffsetCoordValid(Vector2 offset_coord)
|
||||||
{
|
{
|
||||||
return ((int)Math.Clamp(offset_coord.x, 0, Size.x) == (int)offset_coord.x
|
return ((int)Math.Clamp(offset_coord.x, -Size.x / 2, Size.x / 2 - 1) == (int)offset_coord.x
|
||||||
&& (int)Math.Clamp(offset_coord.y, 0, Size.y) == (int)offset_coord.y);
|
&& (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;
|
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)
|
public float GetHeightAtOffset(Vector2 offset_coord)
|
||||||
|
@ -108,7 +110,9 @@ public class TileWorld : Spatial
|
||||||
return 0;
|
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 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue