public static Contract.ContractPrestige getTelescopePrestige(TSTSpaceTelescope.TargetableObject body) { double distance = 0f; if (body.type == typeof(TSTGalaxy)) { Vector3d bodyPos = body.position; CelestialBody HmePlanet = Planetarium.fetch.Home; Vector3d hmeplntPos = HmePlanet.getPositionAtUT(0); distance = Math.Sqrt(Math.Pow(bodyPos.x - hmeplntPos.x, 2) + Math.Pow(bodyPos.y - hmeplntPos.y, 2) + Math.Pow(bodyPos.z - hmeplntPos.z, 2)); } else { distance = Utilities.DistanceFromHomeWorld(body.name); } if (distance < 13000000000) { return(Contract.ContractPrestige.Trivial); } if (distance < 20000000000) { return(Contract.ContractPrestige.Significant); } return(Contract.ContractPrestige.Exceptional); }
/// <summary> /// Select a specific CelestialBody /// </summary> /// <param name="body">The CelestialBody to select</param> protected void SelectBody(CelestialBody body) { selectedBody = body; planetName = selectedBody.name; if (selectedBody == sunBody) { } else { sunRefOrbitHeight = FlightGlobals.getAltitudeAtPos(selectedBody.getPositionAtUT(0d), sunBody) / 1000000d; } bodyRefOrbitHeight = (selectedBody.atmosphereDepth + 10000d) / 1000d; if (Settings.DebugUIMode) { Utils.Log(String.Format("[UI Solar Manager] Selected {0}", selectedBody.name)); } }
/// <summary> /// Constructor /// </summary> /// <param name="uiHost">The parent UI</param> /// <param name="view">The parent ElectricalView panel</param> public UISolarPanelManager(DynamicBatteryStorageUI uiHost, UIElectricalView view) : base(uiHost) { electricalView = view; sunBody = FlightGlobals.Bodies[0]; homeBody = FlightGlobals.GetHomeBody(); selectedBodyIndex = homeBody.flightGlobalsIndex; SelectBody(homeBody); refSunOrbitAlt = FlightGlobals.getAltitudeAtPos(homeBody.getPositionAtUT(0d), sunBody) / 1000000d; if (Settings.DebugUIMode) { Utils.Log(String.Format("[UI Solar Manager] Set home body to {0} (alt {1}), sun body to {2}", homeBody.name, FormatUtils.ToSI(refSunOrbitAlt, "F2"), sunBody.name)); } if (Settings.DebugUIMode) { Utils.Log(String.Format("[UI Solar Manager] Created")); } }
/// <summary> /// Return the Vector3d of the actual position of the body, converted to Scaled Space /// </summary> /// <param name="body"></param> /// <param name="time"></param> /// <returns></returns> static Vector3d GetPositionAtUT(CelestialBody body, double time) { return(Vector3.Scale(ScaledSpace.LocalToScaledSpace(body.getPositionAtUT(time)), new Vector3d(ScaledSpace.ScaleFactor, ScaledSpace.ScaleFactor, ScaledSpace.ScaleFactor))); }
public double mindistance(CelestialBody target, double time, double dt, Orbit vesselorbit) { double[] dist_at_int = new double[11]; for (int i = 0; i <= 10; i++) { double step = time + i * dt; dist_at_int[i] = (target.getPositionAtUT(step) - vesselorbit.getPositionAtUT(step)).magnitude ; } double mindist = dist_at_int.Min(); double maxdist = dist_at_int.Max(); int minindex = Array.IndexOf(dist_at_int, mindist); if (drawApproachToBody == target) closestApproachTime = time + minindex * dt; if ((maxdist - mindist) / maxdist >= 0.00001) mindist = mindistance(target, time + ((minindex - 1) * dt), dt / 5, vesselorbit); return mindist; }