-
Notifications
You must be signed in to change notification settings - Fork 32
/
TerrainData.cs
39 lines (33 loc) · 1.16 KB
/
TerrainData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using Kethane.GeodesicGrid;
using System;
using System.Collections.Generic;
namespace Kethane
{
public class TerrainData
{
private static readonly Dictionary<string, TerrainData> bodies = new Dictionary<string, TerrainData>();
public static void Clear()
{
bodies.Clear();
}
public static TerrainData ForBody(CelestialBody body)
{
if (body == null) { throw new ArgumentException("Body may not be null"); }
if (!bodies.ContainsKey(body.name))
{
bodies[body.name] = new TerrainData(body);
}
return bodies[body.name];
}
private readonly Cell.Map<float> heightRatios;
private TerrainData(CelestialBody body)
{
if (body.pqsController == null) { throw new ArgumentException("Body doesn't have a PQS controller"); }
heightRatios = new Cell.Map<float>(MapOverlay.GridLevel, c => (float)(body.pqsController.GetSurfaceHeight(c.Position) / body.pqsController.radius));
}
public float GetHeightRatio(Cell cell)
{
return heightRatios[cell];
}
}
}