Aetheria/Assets/Plugins/Celestial Body/Scripts/Normalizer.cs
Reinier Vens 53a91351b7 Procedural Planets
Integrated Sebastian Lague's Planet Generator
Created Tour function in SectorRenderer which makes the camera follow each terrestrial planet in turn
2020-12-05 23:43:02 +00:00

21 lines
No EOL
644 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class Normalizer {
public static void Normalize (System.Func<int, float> getValue, System.Action<int, float> setValue, int length) {
float min = float.PositiveInfinity;
float max = float.NegativeInfinity;
for (int i = 0; i < length; i++) {
float value = getValue (i);
min = System.Math.Min (min, value);
max = System.Math.Max (max, value);
}
for (int i = 0; i < length; i++) {
setValue (i, Mathf.InverseLerp (min, max, getValue (i)));
}
}
}