public long GetHeight(int mapIndex, Vector2d position) { if (mapIndex >= Maps.Length) { return(this.HeightBounds.x); } HeightMap map = Maps [mapIndex]; long normX = (position.x - this._bottomLeft.x).Div(Interval); long normY = (position.y - this._bottomLeft.y).Div(Interval); int gridX = FixedMath.ToInt(normX); int gridY = FixedMath.ToInt(normY); long fractionX = (normX - FixedMath.Create(gridX)); long fractionY = (normY - FixedMath.Create(gridY)); long baseHeight = map.GetHeight(gridX, gridY); int nextX = Mathf.Clamp(gridX + 1, 0, map.Map.Width); int nextY = Mathf.Clamp(gridY + 1, 0, map.Map.Height); //bilinear lerp long h1 = FixedMath.Lerp(baseHeight, map.GetHeight(nextX, gridY), fractionX); long h2 = FixedMath.Lerp(map.GetHeight(gridX, nextY), map.GetHeight(nextX, nextY), fractionX); return(FixedMath.Lerp(h1, h2, fractionY) + this.BonusHeight); }