//Display info on the nearest anomaly *Need to separate the BTDT display* private void anomalyInfo(int id) { if ((sensors & SCANtype.AnomalyDetail) != SCANtype.Nothing) { SCANanomaly nearest = null; double nearest_dist = -1; foreach (SCANanomaly a in data.Anomalies) { if (!a.Known) { continue; } double d = (a.Mod.transform.position - v.transform.position).magnitude; if (d < nearest_dist || nearest_dist < 0) { if (d < 50000) { nearest = a; nearest_dist = d; } } } if (nearest != null) { string txt = "Anomaly"; if (nearest.Detail) { txt = nearest.Name; } txt += ": " + SCANuiUtil.distanceString(nearest_dist, 5000); GUILayout.Label(txt, SCANskins.SCAN_insColorLabel); if (anomalyView == null) { anomalyView = new SCANremoteView(); } if (anomalyView != null) { if (nearest.Mod != null) { if (anomalyView.lookat != nearest.Mod.gameObject) { anomalyView.setup(320, 240, nearest.Mod.gameObject); } Texture t = anomalyView.getTexture(); if (t != null) { GUILayout.Label(anomalyView.getTexture()); anomalyView.drawOverlay(GUILayoutUtility.GetLastRect(), SCANskins.SCAN_anomalyOverlay, nearest.Detail); } } } } } }
//Display the current vessel altitude private void altInfo(int id) { if ((sensors & SCANtype.Altimetry) != SCANtype.Nothing) { double h = v.altitude; double pqs = 0; if (v.mainBody.pqsController != null) { pqs = v.PQSAltitude(); if (pqs > 0 || !v.mainBody.ocean) { h -= pqs; } } if (h < 0) { h = v.altitude; } if (v.situation == Vessel.Situations.LANDED || v.situation == Vessel.Situations.SPLASHED || v.situation == Vessel.Situations.PRELAUNCH) { GUILayout.Label(string.Format("Terrain: {0:N1}m", pqs), SCANskins.SCAN_insColorLabel); } else { GUILayout.Label(string.Format("Altitude: {0}", SCANuiUtil.distanceString(h, 100000)), SCANskins.SCAN_insColorLabel); } fillS(-10); //Calculate slope less frequently; the rapidly changing value makes it difficult to read otherwise if (v.mainBody.pqsController != null) { float deltaTime = 1f; if (Time.deltaTime != 0) { deltaTime = TimeWarp.deltaTime / Time.deltaTime; } if (deltaTime > 5) { deltaTime = 5; } if (((Time.time * deltaTime) - lastUpdate) > updateInterval) { lastUpdate = Time.time; /* Slope is calculated using a nine point grid centered 5m around the vessel location * The rise between the vessel location's elevation and each point on the grid is calculated, converted to slope in degrees, and averaged; * Note: Averageing is not the most accurate method */ double latOffset = degreeOffset * Math.Cos(Mathf.Deg2Rad * vlat); double[] e = new double[9]; double[] s = new double[8]; e[0] = pqs; e[1] = SCANUtil.getElevation(v.mainBody, vlon + latOffset, vlat); e[2] = SCANUtil.getElevation(v.mainBody, vlon - latOffset, vlat); e[3] = SCANUtil.getElevation(v.mainBody, vlon, vlat + degreeOffset); e[4] = SCANUtil.getElevation(v.mainBody, vlon, vlat - degreeOffset); e[5] = SCANUtil.getElevation(v.mainBody, vlon + latOffset, vlat + degreeOffset); e[6] = SCANUtil.getElevation(v.mainBody, vlon + latOffset, vlat - degreeOffset); e[7] = SCANUtil.getElevation(v.mainBody, vlon - latOffset, vlat + degreeOffset); e[8] = SCANUtil.getElevation(v.mainBody, vlon - latOffset, vlat - degreeOffset); /* Calculate rise for each point on the grid * The distance is 5m for adjacent points and 7.071m for the points on the corners * Rise is converted to slope; i.e. a 5m elevation change over a 5m distance is a rise of 1 * Converted to slope using the inverse tangent this gives a slope of 45° * */ for (int i = 1; i <= 4; i++) { s[i - 1] = Math.Atan((Math.Abs(e[i] - e[0])) / 5) * Mathf.Rad2Deg; } for (int i = 5; i <= 8; i++) { s[i - 1] = Math.Atan((Math.Abs(e[i] - e[0])) / 7.071) * Mathf.Rad2Deg; } slopeAVG = s.Sum() / 8; } GUILayout.Label(string.Format("Slope: {0:F2}°", slopeAVG), SCANskins.SCAN_insColorLabel); fillS(-10); } } }