public Vector3d GetPointOnGlideslope(double glideslope, double distanceOnCenterline) { Vector3d runwayStart = GetVectorToTouchdown(); Vector3d runwayEnd = End(); Vector3d runwayDir = (runwayEnd - runwayStart).normalized; Vector3d glideslopeDir = QuaternionD.AngleAxis(glideslope, Vector3d.up) * runwayDir; Vector3d pointOnGlideslope = runwayStart - (distanceOnCenterline * glideslopeDir); double latAtDistance, lonAtDistance, altAtDistance; body.GetLatLonAlt(pointOnGlideslope, out latAtDistance, out lonAtDistance, out altAtDistance); double latAtTouchdown, lonAtTouchdown, altAtTouchdown; body.GetLatLonAlt(GetVectorToTouchdown(), out latAtTouchdown, out lonAtTouchdown, out altAtTouchdown); if (altAtDistance < altAtTouchdown) { // TODO: can we optimize this? glideslopeDir = QuaternionD.AngleAxis(-glideslope, Vector3d.up) * runwayDir; pointOnGlideslope = runwayStart - (distanceOnCenterline * glideslopeDir); } return(pointOnGlideslope); }
public Vector3d GetSurfaceNormalVector() { CelestialBody body = ParentBody ? ParentBody : ParentVessel?.mainBody; if (body == null) { return(Vector3d.zero); } body.GetLatLonAlt(position, out double lat, out double lon, out double _); return(body.GetSurfaceNVector(lat, lon)); }
public Vector3d GetPointOnGlideslope(double glideslope, double distanceOnCenterline) { Vector3d runwayStart = Start(); Vector3d runwayEnd = End(); Vector3d runwayDir = (runwayEnd - runwayStart).normalized; Vector3d pointOnGlideslope = runwayStart - (distanceOnCenterline * runwayDir); double altitude = start.altitude + Math.Tan(glideslope * Mathf.Deg2Rad) * distanceOnCenterline; body.GetLatLonAlt(pointOnGlideslope, out double latAtDistance, out double lonAtDistance, out double altAtDistance); return(body.GetWorldSurfacePosition(latAtDistance, lonAtDistance, altitude)); }
/// <summary> /// Coroutine for adding scripts to the Lua context. Paced to load one /// string per frame. /// /// It also looks for existing global RasterPropMonitor COLOR_ definitions. /// </summary> /// <returns>null when done</returns> private IEnumerator LoadAvionicsSystemAssets() { userScripts.Clear(); ConfigNode[] userScriptNodes = GameDatabase.Instance.GetConfigNodes("MAS_LUA"); if (userScriptNodes.Length > 0) { for (int nodeIdx = 0; nodeIdx < userScriptNodes.Length; ++nodeIdx) { if (userScriptNodes[nodeIdx].HasValue("name")) { ConfigNode node = userScriptNodes[nodeIdx]; string[] scripts = node.GetValues("script"); Utility.LogMessage(this, "Parsing MAS_LUA node \"{0}\" ({1} script references)", node.GetValue("name"), scripts.Length); for (int scriptIdx = 0; scriptIdx < scripts.Length; ++scriptIdx) { try { userScripts.Add(string.Join(Environment.NewLine, File.ReadAllLines(KSPUtil.ApplicationRootPath + "GameData/" + scripts[scriptIdx], Encoding.UTF8))); } catch (Exception e) { Utility.LogError(this, "Exception caught trying to load script \"{0}\": {1}", scripts[scriptIdx], e.ToString()); } } yield return(new WaitForEndOfFrame()); } } } namedColors.Clear(); ConfigNode[] rpmColorNodes = GameDatabase.Instance.GetConfigNodes("RPM_GLOBALCOLORSETUP"); for (int colorNodeIdx = 0; colorNodeIdx < rpmColorNodes.Length; ++colorNodeIdx) { ConfigNode[] colorDef = rpmColorNodes[colorNodeIdx].GetNodes("COLORDEFINITION"); for (int defIdx = 0; defIdx < colorDef.Length; ++defIdx) { if (colorDef[defIdx].HasValue("name") && colorDef[defIdx].HasValue("color")) { string name = "COLOR_" + (colorDef[defIdx].GetValue("name").Trim()); Color32 color = ConfigNode.ParseColor32(colorDef[defIdx].GetValue("color").Trim()); if (namedColors.ContainsKey(name)) { namedColors[name] = color; } else { namedColors.Add(name, color); } //Utility.LogMessage(this, "{0} = {1}", name, color); } } yield return(new WaitForEndOfFrame()); } // Add XKCD colors Type t = typeof(XKCDColors); PropertyInfo[] properties = t.GetProperties(); int numProperties = properties.Length; for (int i = 0; i < numProperties; ++i) { try { // This is probably overkill in terms of checks. if (properties[i].PropertyType == typeof(Color) && properties[i].CanRead) { MethodInfo[] accessor = properties[i].GetAccessors(); for (int j = 0; j < accessor.Length; ++j) { if (accessor[j].ReturnType == typeof(Color)) { object o = accessor[j].Invoke(null, null); Color color = (Color)o; StringBuilder sb = StringBuilderCache.Acquire(); sb.Append("COLOR_XKCD_").Append(properties[i].Name.ToUpperInvariant()); string name = sb.ToStringAndRelease(); if (namedColors.ContainsKey(name)) { namedColors[name] = color; } else { namedColors.Add(name, color); } } } } } catch { } } yield return(new WaitForEndOfFrame()); var dsn = UnityEngine.Object.FindObjectsOfType <CommNet.CommNetHome>(); if (dsn != null) { CelestialBody kerbin = Planetarium.fetch.Home; List <FinePrint.Waypoint> relays = new List <FinePrint.Waypoint>(); for (int i = 0; i < dsn.Length; ++i) { // TODO: Support non-Kerbin stations? // Unfortunately, the lat/lon/alt/body fields are all protected, so I have // to do this, instead: Vector3d position = dsn[i].nodeTransform.position; double latitude, longitude, altitude; kerbin.GetLatLonAlt(position, out latitude, out longitude, out altitude); FinePrint.Waypoint dsnWp = new FinePrint.Waypoint(); dsnWp.latitude = latitude; dsnWp.longitude = longitude; dsnWp.celestialName = kerbin.name; dsnWp.altitude = altitude; dsnWp.name = dsn[i].nodeName; dsnWp.index = 256; // ? dsnWp.navigationId = Guid.NewGuid(); dsnWp.id = "vessel"; // seems to be icon name. May be WPM-specific. relays.Add(dsnWp); } deepSpaceNetwork = relays.ToArray(); Array.Sort(deepSpaceNetwork, waypointNameComparer); } else { deepSpaceNetwork = new FinePrint.Waypoint[0]; } }
private void FixedUpdate() { if (Settings.fetch.NewGui) { return; } float t = Time.realtimeSinceStartup; if (t < lastStringRenderTime + stringRenderInterval) { return; } lastStringRenderTime = t; Trajectory traj = Trajectory.fetch; Trajectory.Patch lastPatch = traj.Patches.LastOrDefault(); CelestialBody lastPatchBody = lastPatch?.StartingState.ReferenceBody; CelestialBody targetBody = Trajectory.Target.Body; guistring_gForce = (traj.MaxAccel / 9.81).ToString("0.00"); if (lastPatch != null && lastPatch.ImpactPosition.HasValue) { Vector3 up = lastPatch.ImpactPosition.Value.normalized; Vector3 vel = lastPatch.ImpactVelocity.Value - lastPatchBody.getRFrmVel(lastPatch.ImpactPosition.Value + lastPatchBody.position); float vVelMag = Vector3.Dot(vel, up); Vector3 vVel = up * vVelMag; float hVelMag = (vel - vVel).magnitude; guistring_impactVelocity = String.Format("Impact: V = {0,6:F0}m/s, H = {1,6:F0}m/s", -vVelMag, hVelMag); } else { guistring_impactVelocity = ""; } if (Settings.fetch.DisplayTargetGUI) { if (lastPatchBody != null && targetBody != null && lastPatch.ImpactPosition.HasValue && lastPatchBody == targetBody && Trajectory.Target.WorldPosition.HasValue) { // Get Latitude and Longitude from impact position double impactLat; double impatLon; double impactAlt; // Get Latitude and Longitude from impact position impactPos = lastPatch.ImpactPosition.Value + lastPatchBody.position; lastPatchBody.GetLatLonAlt(impactPos, out impactLat, out impatLon, out impactAlt); // Get Latitude and Longitude for target position double targetLat; double targetLon; double targetAlt; targetPos = Trajectory.Target.WorldPosition.Value + targetBody.position; targetBody.GetLatLonAlt(targetPos, out targetLat, out targetLon, out targetAlt); float targetDistance = (float)(Util.DistanceFromLatitudeAndLongitude(targetBody.Radius + impactAlt, impactLat, impatLon, targetLat, targetLon) / 1e3); float targetDistanceNorth = (float)(Util.DistanceFromLatitudeAndLongitude(targetBody.Radius + impactAlt, impactLat, targetLon, targetLat, targetLon) / 1e3) * ((targetLat - impactLat) < 0 ? -1.0f : +1.0f); float targetDistanceEast = (float)(Util.DistanceFromLatitudeAndLongitude(targetBody.Radius + impactAlt, targetLat, impatLon, targetLat, targetLon) / 1e3) * ((targetLon - impatLon) < 0 ? -1.0f : +1.0f); // format distance to target string guistring_targetDistance = String.Format("{0,6:F1}km | {1}: {2,6:F1}km | {3}: {4,6:F1}km", targetDistance, targetDistanceNorth > 0.0f ? 'N' : 'S', Math.Abs(targetDistanceNorth), targetDistanceEast > 0.0f ? 'E' : 'W', Math.Abs(targetDistanceEast)); } else { guistring_targetDistance = ""; } } if (FlightGlobals.ActiveVessel != null) { var body = FlightGlobals.ActiveVessel.mainBody; guistring_Latitude = body.GetLatitude(FlightGlobals.ActiveVessel.GetWorldPos3D()).ToString("000.000000"); guistring_Longitude = body.GetLongitude(FlightGlobals.ActiveVessel.GetWorldPos3D()).ToString("000.000000"); } }