/* MAP: build: map to Texture2D */ public Texture2D getPartialMap() { SCANdata data = SCANcontroller.controller.getData(body); Color[] pix; if (map == null) { map = new Texture2D(mapwidth, mapheight, TextureFormat.ARGB32, false); pix = map.GetPixels(); for (int i = 0; i < pix.Length; ++i) { pix [i] = Color.clear; } map.SetPixels(pix); } else if (mapstep >= map.height) { return(map); } if (redline == null || redline.Length != map.width) { redline = new Color[map.width]; for (int i = 0; i < redline.Length; ++i) { redline [i] = Color.red; } } if (mapstep < map.height - 1) { map.SetPixels(0, mapstep + 1, map.width, 1, redline); } if (mapstep <= 0) { mapstep = 0; mapline = new double[map.width]; } pix = map.GetPixels(0, mapstep, map.width, 1); for (int i = 0; i < map.width; i++) { int scheme = 0; double lat = (mapstep * 1.0f / mapscale) - 90f + lat_offset; double lon = (i * 1.0f / mapscale) - 180f + lon_offset; double la = lat, lo = lon; lat = unprojectLatitude(lo, la); lon = unprojectLongitude(lo, la); pix [i] = Color.grey; if (double.IsNaN(lat) || double.IsNaN(lon) || lat < -90 || lat > 90 || lon < -180 || lon > 180) { pix [i] = Color.clear; continue; } if (mapmode == 0) { if (!data.isCovered(lon, lat, SCANdata.SCANtype.Altimetry)) { continue; } if (body.pqsController == null) { pix [i] = Color.Lerp(Color.black, Color.white, UnityEngine.Random.value); //big_heightmap[i, mapstep, SCANcontroller.controller.projection] = 0; continue; } float val = 0f; if (mapType == 0) { val = big_heightmap[i, mapstep, SCANcontroller.controller.projection]; } if (val == 0) { if (data.isCovered(lon, lat, SCANdata.SCANtype.AltimetryHiRes)) { // high resolution gets a coloured pixel for the actual position val = (float)data.getElevation(lon, lat); pix[i] = heightToColor(val, scheme); heightMapArray(val, mapstep, i, mapType); } else { // basic altimetry gets forced greyscale with lower resolution val = (float)data.getElevation(((int)(lon * 5)) / 5, ((int)(lat * 5)) / 5); pix[i] = heightToColor(val, 1); heightMapArray(val, mapstep, i, mapType); } } else if (val != 0) { if (data.isCovered(lon, lat, SCANdata.SCANtype.AltimetryHiRes)) { pix[i] = heightToColor(val, scheme); } else { pix[i] = heightToColor(val, 1); } } /* draw height lines - works, but mostly useless... * int step = (int)(val / 1000); * int step_h = step, step_v = step; * if(i > 0) step_h = (int)(bigline[i - 1] / 1000); * if(bigstep > 0) step_v = (int)(bigline[i] / 1000); * if(step != step_h || step != step_v) { * pix[i] = Color.white; * } */ mapline [i] = val; } else if (mapmode == 1) { if (!data.isCovered(lon, lat, SCANdata.SCANtype.Altimetry)) { continue; } if (body.pqsController == null) { pix [i] = Color.Lerp(Color.black, Color.white, UnityEngine.Random.value); continue; } float val = 0f; if (mapType == 0) { val = big_heightmap[i, mapstep, SCANcontroller.controller.projection]; } if (val == 0) { if (data.isCovered(lon, lat, SCANdata.SCANtype.AltimetryHiRes)) { val = (float)data.getElevation(lon, lat); heightMapArray(val, mapstep, i, mapType); } else { val = (float)data.getElevation(((int)(lon * 5)) / 5, ((int)(lat * 5)) / 5); heightMapArray(val, mapstep, i, mapType); } } if (mapstep == 0) { pix [i] = Color.grey; } else { // This doesn't actually calculate the slope per se, but it's faster // than asking for yet more elevation data. Please don't use this // code to operate nuclear power plants or rockets. double v1 = mapline [i]; if (i > 0) { v1 = Math.Max(v1, mapline [i - 1]); } if (i < mapline.Length - 1) { v1 = Math.Max(v1, mapline [i + 1]); } float v = Mathf.Clamp((float)Math.Abs(val - v1) / 1000f, 0, 2f); if (SCANcontroller.controller.colours == 1) { pix [i] = Color.Lerp(Color.black, Color.white, v / 2f); } else { if (v < 1) { pix [i] = Color.Lerp(XKCDColors.PukeGreen, XKCDColors.Lemon, v); } else { pix [i] = Color.Lerp(XKCDColors.Lemon, XKCDColors.OrangeRed, v - 1); } } } mapline [i] = val; } else if (mapmode == 2) { if (!data.isCovered(lon, lat, SCANdata.SCANtype.Biome)) { continue; } if (body.BiomeMap == null || body.BiomeMap.Map == null) { pix [i] = Color.Lerp(Color.black, Color.white, UnityEngine.Random.value); continue; } /* // this just basically stretches the actual biome map to fit... it looks horrible * float u = ((lon + 360 + 180 + 90)) % 360; * float v = ((lat + 180 + 90)) % 180; * if(u < 0 || v < 0 || u >= 360 || v >= 180) continue; * u /= 360f; v /= 180f; * pix[i] = body.BiomeMap.Map.GetPixelBilinear(u, v); */ double bio = data.getBiomeIndexFraction(lon, lat); Color biome = Color.grey; if (SCANcontroller.controller.colours == 1) { if ((i > 0 && mapline [i - 1] != bio) || (mapstep > 0 && mapline [i] != bio)) { biome = Color.white; } else { biome = Color.Lerp(Color.black, Color.white, (float)bio); } } else { Color elevation = Color.gray; if (data.isCovered(lon, lat, SCANdata.SCANtype.Altimetry)) { float val = 0f; if (mapType == 0) { val = big_heightmap[i, mapstep, SCANcontroller.controller.projection]; } if (val == 0) { if (data.isCovered(lon, lat, SCANdata.SCANtype.AltimetryHiRes)) { val = (float)data.getElevation(lon, lat); heightMapArray(val, mapstep, i, mapType); } else { val = (float)data.getElevation(((int)(lon * 5)) / 5, ((int)(lat * 5)) / 5); heightMapArray(val, mapstep, i, mapType); } } elevation = Color.Lerp(Color.black, Color.white, Mathf.Clamp(val + 1500f, 0, 9000) / 9000f); } Color bio1 = XKCDColors.CamoGreen; Color bio2 = XKCDColors.Marigold; if ((i > 0 && mapline [i - 1] != bio) || (mapstep > 0 && mapline [i] != bio)) { //biome = Color.Lerp(XKCDColors.Puce, elevation, 0.5f); biome = Color.white; } else { biome = Color.Lerp(Color.Lerp(bio1, bio2, (float)bio), elevation, 0.5f); } } pix [i] = biome; mapline [i] = bio; } } map.SetPixels(0, mapstep, map.width, 1, pix); mapstep++; if (mapstep % 10 == 0 || mapstep >= map.height) { map.Apply(); } return(map); }