Moved steepness calculation
This commit is contained in:
parent
7bd2b7b255
commit
e51c74944d
@ -11,7 +11,7 @@ namespace TransportGame.Model
|
|||||||
[XmlRoot("map")]
|
[XmlRoot("map")]
|
||||||
public class Map
|
public class Map
|
||||||
{
|
{
|
||||||
private float[,] grid;
|
private float[,] heightmap;
|
||||||
private float[,] population;
|
private float[,] population;
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
@ -36,7 +36,7 @@ namespace TransportGame.Model
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return grid;
|
return heightmap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,11 +48,11 @@ namespace TransportGame.Model
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return grid.ToByteArray();
|
return heightmap.ToByteArray();
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
grid = value.GetFloatMatrix();
|
heightmap = value.GetFloatMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,13 +60,13 @@ namespace TransportGame.Model
|
|||||||
/// Gets width of heightmap
|
/// Gets width of heightmap
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[XmlIgnore]
|
[XmlIgnore]
|
||||||
public int Width { get { return (grid == null) ? 0 : grid.GetLength(0); } }
|
public int Width { get { return (heightmap == null) ? 0 : heightmap.GetLength(0); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets height of heightmap
|
/// Gets height of heightmap
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[XmlIgnore]
|
[XmlIgnore]
|
||||||
public int Height { get { return (grid == null) ? 0 : grid.GetLength(1); } }
|
public int Height { get { return (heightmap == null) ? 0 : heightmap.GetLength(1); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the population map
|
/// Gets the population map
|
||||||
@ -139,7 +139,7 @@ namespace TransportGame.Model
|
|||||||
/// <param name="height">Height</param>
|
/// <param name="height">Height</param>
|
||||||
public Map(int width, int height)
|
public Map(int width, int height)
|
||||||
{
|
{
|
||||||
grid = new float[width, height];
|
heightmap = new float[width, height];
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -152,7 +152,7 @@ namespace TransportGame.Model
|
|||||||
/// <returns>Value</returns>
|
/// <returns>Value</returns>
|
||||||
public float GetHeight(int x, int y)
|
public float GetHeight(int x, int y)
|
||||||
{
|
{
|
||||||
return grid[x, y] * Biome.Height;
|
return heightmap[x, y] * Biome.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -163,7 +163,7 @@ namespace TransportGame.Model
|
|||||||
/// <param name="value">Value</param>
|
/// <param name="value">Value</param>
|
||||||
public void SetHeight(int x, int y, float value)
|
public void SetHeight(int x, int y, float value)
|
||||||
{
|
{
|
||||||
grid[x, y] = value / Biome.Height;
|
heightmap[x, y] = value / Biome.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -187,5 +187,22 @@ namespace TransportGame.Model
|
|||||||
{
|
{
|
||||||
return x >= 0 && y >= 0 && x < Width && y < Height;
|
return x >= 0 && y >= 0 && x < Width && y < Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets steepness in specified point
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">X</param>
|
||||||
|
/// <param name="y">Y</param>
|
||||||
|
/// <returns>Steepness</returns>
|
||||||
|
public float GetSteepness(int x, int y)
|
||||||
|
{
|
||||||
|
if (x == 0) x++;
|
||||||
|
if (y == 0) y++;
|
||||||
|
|
||||||
|
float dx = GetHeight(x - 1, y) - GetHeight(x, y);
|
||||||
|
float dy = GetHeight(x, y - 1) - GetHeight(x, y);
|
||||||
|
|
||||||
|
return dx * dx + dy * dy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,12 +123,7 @@ public class TerrainGeneratorScript : MonoBehaviour
|
|||||||
float height = map.GetHeight(ix, iy);
|
float height = map.GetHeight(ix, iy);
|
||||||
|
|
||||||
// Get steepness
|
// Get steepness
|
||||||
int safex = (ix == 0) ? 1 : ix;
|
float steepness = map.GetSteepness(ix, iy);
|
||||||
int safey = (iy == 0) ? 1 : iy;
|
|
||||||
|
|
||||||
float dx = map.GetHeight(safex - 1, safey) - height;
|
|
||||||
float dy = map.GetHeight(safex, safey - 1) - height;
|
|
||||||
float steepness = dx * dx + dy * dy;
|
|
||||||
|
|
||||||
// Go through each texture layer
|
// Go through each texture layer
|
||||||
float[] weights = new float[terrainData.alphamapLayers];
|
float[] weights = new float[terrainData.alphamapLayers];
|
||||||
|
Loading…
Reference in New Issue
Block a user