FormatNumber() public static method

public static FormatNumber ( double number, int decimals = -1 ) : string
number double
decimals int
return string
Esempio n. 1
0
        private void DrawVesselDetails(Vessel targetVessel)
        {
            if (targetVessel.mainBody != fe.vessel.mainBody)
            {
                targetObject        = null;
                typeOfTarget        = TargetType.None;
                typeOfVessel        = VesselType.Unknown;
                fe.settings.Changed = true;
            }

            if (FlightGlobals.fetch.VesselTarget == null)
            {
                FlightGlobals.fetch.SetVesselTarget(targetVessel);
            }
            Orbit activeOrbit = fe.vessel.orbit;
            Orbit targetOrbit = targetVessel.orbit;

            Vector3d activePosition       = activeOrbit.getRelativePositionAtUT(Planetarium.GetUniversalTime());
            Vector3d targetPosition       = targetVessel.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime());
            Vector3d activeVelocity       = Vector3d.zero;
            Vector3d targetVelocity       = Vector3d.zero;
            Vector3d relVelocity          = FlightGlobals.ship_tgtVelocity;
            double   phaseAngle           = CalcPhaseAngle(activePosition, targetPosition);
            double   interceptAngle       = CalcInterceptAngle(activeOrbit.radius, targetOrbit.radius);
            double   distance             = Vector3d.Distance(targetPosition, activePosition);
            double   interceptDistance    = CalcInterceptDistance(activeOrbit.radius, targetOrbit.radius, interceptAngle);
            double   relInclination       = CalcRelativeInclination(activeOrbit, targetVessel.orbit);
            double   ascendingNode        = CalcAngleToAscendingNode(activePosition, activeOrbit, targetOrbit);
            double   descendingNode       = CalcAngleToDescendingNode(activePosition, activeOrbit, targetOrbit);
            double   timeToAN             = CalcTimeToNode(activeOrbit, ascendingNode);
            double   timeToDN             = CalcTimeToNode(activeOrbit, descendingNode);
            double   altitude             = targetOrbit.altitude;
            double   velocity             = targetVessel.obt_velocity.magnitude;
            double   relVelocityMagnitude = FlightGlobals.ship_tgtVelocity.magnitude;

            if (interceptAngle < 0)
            {
                phaseAngle    -= 360;
                interceptAngle = (phaseAngle - interceptAngle) + 360;
            }
            else
            {
                interceptAngle = phaseAngle - interceptAngle;
            }

            if (interceptAngle < 0)
            {
                interceptAngle += 360;
            }

            GUILayout.Label(targetVessel.vesselName, fe.headingStyle);

            GUILayout.BeginHorizontal(fe.areaStyle);
            GUILayout.BeginVertical();
            fe.settings.Set("*SPACER_RENDEZVOUS_VESSEL", "");
            fe.settings.Set("*headingStyle_RENDEZVOUS_VESSEL", "RENDEZVOUS DISPLAY - VESSEL");
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Phase Angle", true))
            {
                GUILayout.Label("Phase Angle", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Intercept Angle", true))
            {
                GUILayout.Label("Intercept Angle", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Intercept Distance", true))
            {
                GUILayout.Label("Intercept Distance", fe.headingStyle);
            }

            if (fe.settings.Get <bool>("Rendezvous: Vessel - Rel. Inclination", true))
            {
                GUILayout.Label("Rel. Inclination", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Rel. Latitude", false))
            {
                GUILayout.Label("Rel. Latitude", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Ascending Node", true))
            {
                GUILayout.Label("Ascending Node", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Descending Node", true))
            {
                GUILayout.Label("Descending Node", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Time to Ascending Node", true))
            {
                GUILayout.Label("Time to AN", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Time to Ascending Node", true))
            {
                GUILayout.Label("Time to DN", fe.headingStyle);
            }

            if (fe.settings.Get <bool>("Rendezvous: Vessel - Current Altitude", true))
            {
                GUILayout.Label("Current Altitude", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Apoapsis Height", true))
            {
                GUILayout.Label("Apoapsis Height", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Periapsis Height", true))
            {
                GUILayout.Label("Periapsis Height", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Orbital Period", true))
            {
                GUILayout.Label("Orbital Preiod", fe.headingStyle);
            }

            if (fe.settings.Get <bool>("Rendezvous: Vessel - Distance", true))
            {
                GUILayout.Label("Distance", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Velocity", true))
            {
                GUILayout.Label("Velocity", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Rel. Velocity", true))
            {
                GUILayout.Label("Rel. Velocity", fe.headingStyle);
            }
            if (relVelocity != Vector3d.zero)
            {
                if (fe.settings.Get <bool>("Rendezvous: Vessel - Rel. Velocity (Vertical)", true))
                {
                    GUILayout.Label(" > Vertical", fe.headingStyle);
                }
                if (fe.settings.Get <bool>("Rendezvous: Vessel - Rel. Velocity (Horizontal)", true))
                {
                    GUILayout.Label(" > Horizontal", fe.headingStyle);
                }
                if (fe.settings.Get <bool>("Rendezvous: Vessel - Rel. Velocity (Forward)", true))
                {
                    GUILayout.Label(" > Forward", fe.headingStyle);
                }
            }
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Phase Angle"))
            {
                GUILayout.Label(Tools.FormatNumber(phaseAngle, "°", 6), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Intercept Angle"))
            {
                GUILayout.Label(Tools.FormatNumber(interceptAngle, "°", 6), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Intercept Distance"))
            {
                GUILayout.Label(Tools.FormatSI(distance - interceptDistance, Tools.SIUnitType.Distance), fe.dataStyle);
            }

            if (fe.settings.Get <bool>("Rendezvous: Vessel - Rel. Inclination"))
            {
                GUILayout.Label(Tools.FormatNumber(relInclination, "°", 6), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Rel. Latitude"))
            {
                GUILayout.Label(Tools.FormatNumber(fe.vessel.latitude - targetVessel.latitude, "°", 6), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Ascending Node", true))
            {
                GUILayout.Label(Tools.FormatNumber(ascendingNode, "°", 6), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Descending Node", true))
            {
                GUILayout.Label(Tools.FormatNumber(descendingNode, "°", 6), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Time to Ascending Node", true))
            {
                GUILayout.Label(Tools.FormatTime(timeToAN), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Time to Ascending Node", true))
            {
                GUILayout.Label(Tools.FormatTime(timeToDN), fe.dataStyle);
            }

            if (fe.settings.Get <bool>("Rendezvous: Vessel - Current Altitude"))
            {
                GUILayout.Label(Tools.FormatSI(altitude, Tools.SIUnitType.Distance), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Apoapsis Height"))
            {
                GUILayout.Label(Tools.FormatSI(targetOrbit.ApA, Tools.SIUnitType.Distance), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Periapsis Height"))
            {
                GUILayout.Label(Tools.FormatSI(targetOrbit.PeA, Tools.SIUnitType.Distance), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Orbital Period"))
            {
                GUILayout.Label(Tools.FormatTime(targetOrbit.period), fe.dataStyle);
            }

            if (fe.settings.Get <bool>("Rendezvous: Vessel - Distance"))
            {
                GUILayout.Label(Tools.FormatSI(distance, Tools.SIUnitType.Distance), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Velocity"))
            {
                GUILayout.Label(Tools.FormatSI(velocity, Tools.SIUnitType.Speed), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Vessel - Rel. Velocity"))
            {
                GUILayout.Label(Tools.FormatSI(relVelocityMagnitude, Tools.SIUnitType.Speed), fe.dataStyle);
            }
            if (relVelocity != Vector3d.zero)
            {
                if (fe.settings.Get <bool>("Rendezvous: Vessel - Rel. Velocity (Vertical)"))
                {
                    GUILayout.Label(Tools.FormatSI(relVelocity.x, Tools.SIUnitType.Speed), fe.dataStyle);
                }
                if (fe.settings.Get <bool>("Rendezvous: Vessel - Rel. Velocity (Horizontal)"))
                {
                    GUILayout.Label(Tools.FormatSI(relVelocity.y, Tools.SIUnitType.Speed), fe.dataStyle);
                }
                if (fe.settings.Get <bool>("Rendezvous: Vessel - Rel. Velocity (Forward)"))
                {
                    GUILayout.Label(Tools.FormatSI(relVelocity.z, Tools.SIUnitType.Speed), fe.dataStyle);
                }
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        }
Esempio n. 2
0
        private void DrawBodyDetails(CelestialBody targetBody)
        {
            if (fe.vessel.mainBody == targetBody)
            {
                targetObject        = null;
                fe.settings.Changed = true;
                return;
            }

            if (FlightGlobals.fetch.VesselTarget == null)
            {
                FlightGlobals.fetch.SetVesselTarget(targetBody);
            }

            Orbit activeOrbit;
            Orbit targetOrbit = targetBody.orbit;

            Vector3d activePosition = Vector3d.zero;
            Vector3d targetPosition = targetOrbit.getRelativePositionAtUT(Planetarium.GetUniversalTime());
            double   altitude       = altitude = targetOrbit.altitude;
            double   phaseAngle     = 0.0d;
            double   interceptAngle = 0.0d;

            if (fe.vessel.mainBody == Planetarium.fetch.Sun || fe.vessel.mainBody == targetBody.referenceBody)
            {
                activeOrbit    = fe.vessel.orbit;
                activePosition = activeOrbit.getRelativePositionAtUT(Planetarium.GetUniversalTime());
                interceptAngle = CalcInterceptAngle(activeOrbit.radius, targetOrbit.radius);
            }
            else
            {
                activeOrbit    = fe.vessel.mainBody.orbit;
                activePosition = activeOrbit.getRelativePositionAtUT(Planetarium.GetUniversalTime());
                interceptAngle = CalcInterceptAngle(activeOrbit.radius, targetOrbit.radius);
            }

            double distance = Vector3d.Distance(targetPosition, activePosition);

            double angleToPrograde   = 0d;
            double angleToRetrograde = 0d;
            double ejectionAngle     = 0d;

            if (fe.vessel.mainBody != targetBody.referenceBody && fe.vessel.mainBody != Planetarium.fetch.Sun)
            {
                angleToPrograde   = AngleToPrograde(fe.vessel);
                angleToRetrograde = AngleToRetrograde(fe.vessel);
                ejectionAngle     = CalcEjectionAngle(fe.vessel, targetBody);
            }

            double relInclination = CalcRelativeInclination(activeOrbit, targetOrbit);
            double ascendingNode  = CalcAngleToAscendingNode(activePosition, activeOrbit, targetOrbit);
            double descendingNode = CalcAngleToDescendingNode(activePosition, activeOrbit, targetOrbit);
            double timeToAN       = CalcTimeToNode(activeOrbit, ascendingNode);
            double timeToDN       = CalcTimeToNode(activeOrbit, descendingNode);

            if (interceptAngle < 0)
            {
                phaseAngle     = CalcPhaseAngle(activePosition, targetPosition) - 360;
                interceptAngle = (phaseAngle - interceptAngle) + 360;
            }
            else
            {
                phaseAngle     = CalcPhaseAngle(activePosition, targetPosition);
                interceptAngle = phaseAngle - interceptAngle;
            }

            if (interceptAngle < 0)
            {
                interceptAngle += 360;
            }

            GUILayout.Label(targetBody.name, fe.headingStyle);

            GUILayout.BeginHorizontal(fe.areaStyle);
            GUILayout.BeginVertical();
            fe.settings.Set("*SPACER_RENDEZVOUS_CELESTIAL", "");
            fe.settings.Set("*headingStyle_RENDEZVOUS_CELESTIAL", "RENDEZVOUS DISPLAY - CELESTIAL BODY");
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Current Phase Angle", true))
            {
                GUILayout.Label("Current Phase Angle", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Intercept Angle", true))
            {
                GUILayout.Label("Intercept Angle", fe.headingStyle);
            }

            if (fe.vessel.mainBody != targetBody.referenceBody && fe.vessel.mainBody != Planetarium.fetch.Sun)
            {
                if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Ejection Angle", true))
                {
                    GUILayout.Label("Ejection Angle", fe.headingStyle);
                }
                if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Angle to Prograde/Retrograde", true))
                {
                    if (phaseAngle > 0)
                    {
                        GUILayout.Label("Angle to Prograde", fe.headingStyle);
                    }
                    else
                    {
                        GUILayout.Label("Angle to Retrograde", fe.headingStyle);
                    }
                }
            }

            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Relative Inclination", true))
            {
                GUILayout.Label("Relative Inclination", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Ascending Node", true))
            {
                GUILayout.Label("Ascending Node", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Descending Node", true))
            {
                GUILayout.Label("Descending Node", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Time to Ascending Node", true))
            {
                GUILayout.Label("Time to AN", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Time to Ascending Node", true))
            {
                GUILayout.Label("Time to DN", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Altitude", true))
            {
                GUILayout.Label("Altitude", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Distance", true))
            {
                GUILayout.Label("Distance", fe.headingStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Orbital Period", true))
            {
                GUILayout.Label("Orbital Period", fe.headingStyle);
            }
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Current Phase Angle"))
            {
                GUILayout.Label(Tools.FormatNumber(phaseAngle, "°", 6), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Intercept Angle"))
            {
                GUILayout.Label(Tools.FormatNumber(interceptAngle, "°", 6), fe.dataStyle);
            }

            if (fe.vessel.mainBody != targetBody.referenceBody && fe.vessel.mainBody != Planetarium.fetch.Sun)
            {
                if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Ejection Angle"))
                {
                    GUILayout.Label(Tools.FormatNumber(ejectionAngle, "°", 6), fe.dataStyle);
                }

                if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Angle to Prograde/Retrograde", true))
                {
                    if (phaseAngle > 0)
                    {
                        GUILayout.Label(Tools.FormatNumber(angleToPrograde, "°", 6), fe.dataStyle);
                    }
                    else
                    {
                        GUILayout.Label(Tools.FormatNumber(angleToRetrograde, "°", 6), fe.dataStyle);
                    }
                }
            }

            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Relative Inclination"))
            {
                GUILayout.Label(Tools.FormatNumber(relInclination, "°", 6), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Ascending Node", true))
            {
                GUILayout.Label(Tools.FormatNumber(ascendingNode, "°", 6), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Descending Node", true))
            {
                GUILayout.Label(Tools.FormatNumber(descendingNode, "°", 6), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Time to Ascending Node", true))
            {
                GUILayout.Label(Tools.FormatTime(timeToAN), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Time to Ascending Node", true))
            {
                GUILayout.Label(Tools.FormatTime(timeToDN), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Altitude"))
            {
                GUILayout.Label(Tools.FormatSI(altitude, Tools.SIUnitType.Distance), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Distance"))
            {
                GUILayout.Label(Tools.FormatSI(distance, Tools.SIUnitType.Distance), fe.dataStyle);
            }
            if (fe.settings.Get <bool>("Rendezvous: Celestial Body - Orbital Period"))
            {
                GUILayout.Label(Tools.FormatTime(targetBody.orbit.period), fe.dataStyle);
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        }
Esempio n. 3
0
        // Impact Code by: mic_e
        private void DrawSurface()
        {
            bool   impacthappening = false;
            double impacttime      = 0;
            double impactlong      = 0;
            double impactlat       = 0;
            double impactalt       = 0;

            if (FlightGlobals.ActiveVessel.mainBody.pqsController != null)
            {
                //do impact site calculations
                impacthappening = true;
                impacttime      = 0;
                impactlong      = 0;
                impactlat       = 0;
                impactalt       = 0;
                double e = this.vessel.orbit.eccentricity;
                //get current position direction vector
                Vector3d currentpos = radiusdirection(this.vessel.orbit.trueAnomaly);
                //calculate longitude in inertial reference frame from that
                double currentirflong = 180 * Math.Atan2(currentpos.x, currentpos.y) / Math.PI;

                //experimentally determined; even for very flat trajectories, the errors go into the sub-millimeter area after 5 iterations or so
                const int impactiterations = 6;

                //do a few iterations of impact site calculations
                for (int i = 0; i < impactiterations; i++)
                {
                    if (this.vessel.orbit.PeA >= impactalt)
                    {
                        //periapsis must be lower than impact alt
                        impacthappening = false;
                    }
                    if ((this.vessel.orbit.eccentricity < 1) && (this.vessel.orbit.ApA <= impactalt))
                    {
                        //apoapsis must be higher than impact alt
                        impacthappening = false;
                    }
                    if ((this.vessel.orbit.eccentricity >= 1) && (this.vessel.orbit.timeToPe <= 0))
                    {
                        //if currently escaping, we still need to be before periapsis
                        impacthappening = false;
                    }
                    if (!impacthappening)
                    {
                        impacttime = 0;
                        impactlong = 0;
                        impactlat  = 0;
                        impactalt  = 0;
                        break;
                    }

                    double impacttheta = 0;
                    if (e > 0)
                    {
                        //in this step, we are using the calculated impact altitude of the last step, to refine the impact site position
                        impacttheta = -180 * Math.Acos((this.vessel.orbit.PeR * (1 + e) / (this.vessel.mainBody.Radius + impactalt) - 1) / e) / Math.PI;
                    }

                    //calculate time to impact
                    impacttime = this.vessel.orbit.timeToPe - timetoperiapsis(impacttheta);
                    //calculate position vector of impact site
                    Vector3d impactpos = radiusdirection(impacttheta);
                    //calculate longitude of impact site in inertial reference frame
                    double impactirflong = 180 * Math.Atan2(impactpos.x, impactpos.y) / Math.PI;
                    double deltairflong  = impactirflong - currentirflong;
                    //get body rotation until impact
                    double bodyrot = 360 * impacttime / this.vessel.mainBody.rotationPeriod;
                    //get current longitude in body coordinates
                    double currentlong = this.vessel.longitude;
                    //finally, calculate the impact longitude in body coordinates
                    impactlong = normangle(currentlong - deltairflong - bodyrot);
                    //calculate impact latitude from impact position
                    impactlat = 180 * Math.Asin(impactpos.z / impactpos.magnitude) / Math.PI;
                    //calculate the actual altitude of the impact site
                    //altitude for long/lat code stolen from some ISA MapSat forum post; who knows why this works, but it seems to.
                    Vector3d rad = QuaternionD.AngleAxis(impactlong, Vector3d.down) * QuaternionD.AngleAxis(impactlat, Vector3d.forward) * Vector3d.right;
                    impactalt = this.vessel.mainBody.pqsController.GetSurfaceHeight(rad) - this.vessel.mainBody.pqsController.radius;
                    if ((impactalt < 0) && (this.vessel.mainBody.ocean == true))
                    {
                        impactalt = 0;
                    }
                }
            }

            if (this.vessel.geeForce > maxGForce)
            {
                maxGForce = this.vessel.geeForce;
            }

            if (!hasCheckedForFAR)
            {
                hasCheckedForFAR = true;

                foreach (AssemblyLoader.LoadedAssembly assembly in AssemblyLoader.loadedAssemblies)
                {
                    if (assembly.assembly.ToString().Split(',')[0] == "FerramAerospaceResearch")
                    {
                        hasInstalledFAR = true;
                        print("[KerbalEngineer]: FAR detected!  Turning off atmospheric details!");
                    }
                }
            }

            GUILayout.Label("SURFACE DISPLAY", headingStyle);
            GUILayout.BeginHorizontal(areaStyle);
            GUILayout.BeginVertical();
            settings.Set("*SPACER_SURFACE", "");
            settings.Set("*headingStyle_SURFACE", "SURFACE DISPLAY");
            if (settings.Get <bool>("Surface: Altitude (Sea Level)", true))
            {
                GUILayout.Label("Altitude (Sea Level)", headingStyle);
            }
            if (settings.Get <bool>("Surface: Altitude (Terrain)", true))
            {
                GUILayout.Label("Altitude (Terrain)", headingStyle);
            }
            if (settings.Get <bool>("Surface: Vertical Speed", true))
            {
                GUILayout.Label("Vertical Speed", headingStyle);
            }
            if (settings.Get <bool>("Surface: Horizontal Speed", true))
            {
                GUILayout.Label("Horizontal Speed", headingStyle);
            }
            if (settings.Get <bool>("Surface: Longitude", true))
            {
                GUILayout.Label("Longitude", headingStyle);
            }
            if (settings.Get <bool>("Surface: Latitude", true))
            {
                GUILayout.Label("Latitude", headingStyle);
            }

            if (impacthappening)
            {
                if (settings.Get <bool>("Surface: Impact Time", true))
                {
                    GUILayout.Label("Impact Time", headingStyle);
                }
                if (settings.Get <bool>("Surface: Impact Longitude", true))
                {
                    GUILayout.Label("Impact Longitude", headingStyle);
                }
                if (settings.Get <bool>("Surface: Impact Latitude", true))
                {
                    GUILayout.Label("Impact Latitude", headingStyle);
                }
                if (settings.Get <bool>("Surface: Impact Altitude", true))
                {
                    GUILayout.Label("Impact Altitude", headingStyle);
                }
            }

            if (settings.Get <bool>("Surface: G-Force", true))
            {
                GUILayout.Label("G-Force", headingStyle);
            }

            if (!hasInstalledFAR)
            {
                if (settings.Get <bool>("Surface: Terminal Velocity", true))
                {
                    GUILayout.Label("Terminal Velocity", headingStyle);
                }
                if (settings.Get <bool>("Surface: Atmospheric Efficiency", true))
                {
                    GUILayout.Label("Atmospheric Efficiency", headingStyle);
                }
                if (settings.Get <bool>("Surface: Atmospheric Drag", true))
                {
                    GUILayout.Label("Atmospheric Drag", headingStyle);
                }
                if (settings.Get <bool>("Surface: Atmospheric Pressure", true))
                {
                    GUILayout.Label("Atmospheric Pressure", headingStyle);
                }
                if (settings.Get <bool>("Surface: Atmospheric Density", true))
                {
                    GUILayout.Label("Atmospheric Density", headingStyle);
                }
            }
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            if (settings.Get <bool>("Surface: Altitude (Sea Level)"))
            {
                GUILayout.Label(Tools.FormatSI(this.vessel.mainBody.GetAltitude(this.vessel.CoM), Tools.SIUnitType.Distance), dataStyle);
            }
            if (settings.Get <bool>("Surface: Altitude (Terrain)"))
            {
                GUILayout.Label(Tools.FormatSI(this.vessel.mainBody.GetAltitude(this.vessel.CoM) - this.vessel.terrainAltitude, Tools.SIUnitType.Distance), dataStyle);
            }
            if (settings.Get <bool>("Surface: Vertical Speed"))
            {
                GUILayout.Label(Tools.FormatSI(this.vessel.verticalSpeed, Tools.SIUnitType.Speed), dataStyle);
            }
            if (settings.Get <bool>("Surface: Horizontal Speed"))
            {
                GUILayout.Label(Tools.FormatSI(this.vessel.horizontalSrfSpeed, Tools.SIUnitType.Speed), dataStyle);
            }
            if (settings.Get <bool>("Surface: Longitude"))
            {
                GUILayout.Label(Tools.FormatNumber(this.vessel.longitude, "°", 6), dataStyle);
            }
            if (settings.Get <bool>("Surface: Latitude"))
            {
                GUILayout.Label(Tools.FormatNumber(this.vessel.latitude, "°", 6), dataStyle);
            }

            if (impacthappening)
            {
                if (settings.Get <bool>("Surface: Impact Time", true))
                {
                    GUILayout.Label(Tools.FormatTime(impacttime), dataStyle);
                }
                if (settings.Get <bool>("Surface: Impact Longitude", true))
                {
                    GUILayout.Label(Tools.FormatNumber(impactlong, "°", 6), dataStyle);
                }
                if (settings.Get <bool>("Surface: Impact Latitude", true))
                {
                    GUILayout.Label(Tools.FormatNumber(impactlat, "°", 6), dataStyle);
                }
                if (settings.Get <bool>("Surface: Impact Altitude", true))
                {
                    GUILayout.Label(Tools.FormatSI(impactalt, Tools.SIUnitType.Distance), dataStyle);
                }
            }

            if (settings.Get <bool>("Surface: G-Force"))
            {
                GUILayout.Label(Tools.FormatNumber(this.vessel.geeForce, 3) + " / " + Tools.FormatNumber(maxGForce, "g", 3), dataStyle);
            }

            if (!hasInstalledFAR)
            {
                double totalMass = 0d;
                double massDrag  = 0d;
                foreach (Part part in this.vessel.parts)
                {
                    if (part.physicalSignificance != Part.PhysicalSignificance.NONE)
                    {
                        double partMass = part.mass + part.GetResourceMass();
                        totalMass += partMass;
                        massDrag  += partMass * part.maximum_drag;
                    }
                }

                double gravity    = FlightGlobals.getGeeForceAtPosition(this.vessel.CoM).magnitude;
                double atmosphere = this.vessel.atmDensity;

                double terminalVelocity = 0d;
                if (atmosphere > 0)
                {
                    terminalVelocity = Math.Sqrt((2 * totalMass * gravity) / (atmosphere * massDrag * FlightGlobals.DragMultiplier));
                }

                double atmosphericEfficiency = 0d;
                if (terminalVelocity > 0)
                {
                    atmosphericEfficiency = FlightGlobals.ship_srfSpeed / terminalVelocity;
                }

                double dragForce = 0.5 * atmosphere * Math.Pow(FlightGlobals.ship_srfSpeed, 2) * massDrag * FlightGlobals.DragMultiplier;

                if (settings.Get <bool>("Surface: Terminal Velocity"))
                {
                    GUILayout.Label(Tools.FormatSI(terminalVelocity, Tools.SIUnitType.Speed), dataStyle);
                }
                if (settings.Get <bool>("Surface: Atmospheric Efficiency"))
                {
                    GUILayout.Label(Tools.FormatNumber(atmosphericEfficiency * 100, "%", 2), dataStyle);
                }
                if (settings.Get <bool>("Surface: Atmospheric Drag"))
                {
                    GUILayout.Label(Tools.FormatSI(dragForce, Tools.SIUnitType.Force), dataStyle);
                }
                if (settings.Get <bool>("Surface: Atmospheric Pressure"))
                {
                    GUILayout.Label(Tools.FormatSI(this.part.dynamicPressureAtm * 100, Tools.SIUnitType.Pressure), dataStyle);
                }
                if (settings.Get <bool>("Surface: Atmospheric Density"))
                {
                    GUILayout.Label(Tools.FormatSI(this.vessel.atmDensity, Tools.SIUnitType.Density), dataStyle);
                }
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        }
Esempio n. 4
0
        private void DrawVessel()
        {
            if ((TimeWarp.WarpMode == TimeWarp.Modes.LOW) || (TimeWarp.CurrentRate <= TimeWarp.MaxPhysicsRate))
            {
                SimManager.Instance.RequestSimulation();
            }

            int stage = stages.Length - 1;

            GUILayout.Label("VESSEL DISPLAY", headingStyle);
            GUILayout.BeginHorizontal(areaStyle);
            GUILayout.BeginVertical();
            settings.Set("*SPACER_VESSEL", "");
            settings.Set("*headingStyle_VESSEL", "VESSEL DISPLAY");

            int stageCount       = stages.Length;
            int stageCountUseful = 0;

            if (settings.Get <bool>("Vessel: Show All DeltaV Stages", true))
            {
                for (int i = stageCount - 1; i >= 0; i--)
                {
                    stageDeltaV = stages[i].deltaV;
                    if (stageDeltaV > 0)
                    {
                        if (settings.Get <bool>("Vessel: DeltaV (Stage)", true))
                        {
                            GUILayout.Label("DeltaV (S" + i + ")", headingStyle);
                        }
                        stageCountUseful++;
                    }
                }

                if (stageCount != numberOfStages || stageCountUseful != numberOfStagesUseful)
                {
                    numberOfStages       = stageCount;
                    numberOfStagesUseful = stageCountUseful;
                    settings.Changed     = true;
                }
            }
            else
            {
                if (settings.Get <bool>("Vessel: DeltaV (Stage)", true))
                {
                    GUILayout.Label("DeltaV (Stage)", headingStyle);
                }
            }
            if (settings.Get <bool>("Vessel: DeltaV (Total)", true))
            {
                GUILayout.Label("DeltaV (Total)", headingStyle);
            }
            if (settings.Get <bool>("Vessel: Specific Impulse", true))
            {
                GUILayout.Label("Specific Impulse", headingStyle);
            }
            if (settings.Get <bool>("Vessel: Mass", true))
            {
                GUILayout.Label("Mass", headingStyle);
            }
            if (settings.Get <bool>("Vessel: Thrust (Maximum)", true))
            {
                GUILayout.Label("Thrust (Maximum)", headingStyle);
            }
            if (settings.Get <bool>("Vessel: Thrust (Throttle)", true))
            {
                GUILayout.Label("Thrust (Throttle)", headingStyle);
            }
            if (settings.Get <bool>("Vessel: Thrust to Weight (Throttle)", true))
            {
                GUILayout.Label("TWR (Throttle)", headingStyle);
            }
            if (settings.Get <bool>("Vessel: Thrust to Weight (Current)", true))
            {
                GUILayout.Label("TWR (Current)", headingStyle);
            }
            if (settings.Get <bool>("Vessel: Thrust to Weight (Surface)", true))
            {
                GUILayout.Label("TWR (Surface)", headingStyle);
            }
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            if (settings.Get <bool>("Vessel: Show All DeltaV Stages"))
            {
                for (int i = stageCount - 1; i >= 0; i--)
                {
                    stageDeltaV = stages[i].deltaV;
                    if (stageDeltaV > 0)
                    {
                        if (settings.Get <bool>("Vessel: DeltaV (Stage)"))
                        {
                            GUILayout.Label(Tools.FormatNumber(stages[i].deltaV, "m/s", 0) + " (" + Tools.FormatTime(stages[i].time) + ")", dataStyle);
                        }
                    }
                }
            }
            else
            {
                if (settings.Get <bool>("Vessel: DeltaV (Stage)"))
                {
                    GUILayout.Label(Tools.FormatNumber(stages[Staging.lastStage].deltaV, "m/s", 0) + " (" + Tools.FormatTime(stages[Staging.lastStage].time) + ")", dataStyle);
                }
            }
            if (settings.Get <bool>("Vessel: DeltaV (Total)"))
            {
                GUILayout.Label(Tools.FormatNumber(stages[Staging.lastStage].totalDeltaV, "m/s", 0) + " (" + Tools.FormatTime(stages[Staging.lastStage].totalTime) + ")", dataStyle);
            }
            if (settings.Get <bool>("Vessel: Specific Impulse"))
            {
                GUILayout.Label(Tools.FormatNumber(stages[Staging.lastStage].isp, "s", 3), dataStyle);
            }
            if (settings.Get <bool>("Vessel: Mass"))
            {
                GUILayout.Label(EngineerTools.WeightFormatter(stages[Staging.lastStage].mass, stages[Staging.lastStage].totalMass), dataStyle);
            }
            if (settings.Get <bool>("Vessel: Thrust (Maximum)"))
            {
                GUILayout.Label(Tools.FormatSI(stages[Staging.lastStage].thrust, Tools.SIUnitType.Force), dataStyle);
            }
            if (settings.Get <bool>("Vessel: Thrust (Throttle)"))
            {
                GUILayout.Label(Tools.FormatSI(stages[Staging.lastStage].actualThrust, Tools.SIUnitType.Force), dataStyle);
            }
            if (settings.Get <bool>("Vessel: Thrust to Weight (Throttle)"))
            {
                GUILayout.Label(Tools.FormatNumber(stages[Staging.lastStage].actualThrustToWeight, 3), dataStyle);
            }
            if (settings.Get <bool>("Vessel: Thrust to Weight (Current)"))
            {
                GUILayout.Label(Tools.FormatNumber(stages[Staging.lastStage].thrustToWeight, 3), dataStyle);
            }
            if (settings.Get <bool>("Vessel: Thrust to Weight (Surface)", true))
            {
                GUILayout.Label(Tools.FormatNumber(stages[Staging.lastStage].thrust / (stages[Staging.lastStage].totalMass * (this.vessel.mainBody.gravParameter / Math.Pow(this.vessel.mainBody.Radius, 2))), 3), dataStyle);
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        }
Esempio n. 5
0
        private void DrawOrbital()
        {
            GUILayout.Label("ORBITAL DISPLAY", headingStyle);
            GUILayout.BeginHorizontal(areaStyle);
            GUILayout.BeginVertical();
            settings.Set("*SPACER_ORBITAL", "");
            settings.Set("*headingStyle_ORBITAL", "ORBITAL DISPLAY");
            if (settings.Get <bool>("Orbital: Show Grouped Ap/Pe Readouts", false))
            {
                if (settings.Get <bool>("Orbital: Apoapsis Height", true))
                {
                    GUILayout.Label("Apoapsis Height", headingStyle);
                }
                if (settings.Get <bool>("Orbital: Time to Apoapsis", true))
                {
                    GUILayout.Label("Time to Apoapsis", headingStyle);
                }
                if (settings.Get <bool>("Orbital: Periapsis Height", true))
                {
                    GUILayout.Label("Periapsis Height", headingStyle);
                }
                if (settings.Get <bool>("Orbital: Time to Periapsis", true))
                {
                    GUILayout.Label("Time to Periapsis", headingStyle);
                }
            }
            else
            {
                if (settings.Get <bool>("Orbital: Apoapsis Height", true))
                {
                    GUILayout.Label("Apoapsis Height", headingStyle);
                }
                if (settings.Get <bool>("Orbital: Periapsis Height", true))
                {
                    GUILayout.Label("Periapsis Height", headingStyle);
                }
                if (settings.Get <bool>("Orbital: Time to Apoapsis", true))
                {
                    GUILayout.Label("Time to Apoapsis", headingStyle);
                }
                if (settings.Get <bool>("Orbital: Time to Periapsis", true))
                {
                    GUILayout.Label("Time to Periapsis", headingStyle);
                }
            }
            if (settings.Get <bool>("Orbital: Inclination", true))
            {
                GUILayout.Label("Inclination", headingStyle);
            }
            if (settings.Get <bool>("Orbital: Eccentricity", true))
            {
                GUILayout.Label("Eccentricity", headingStyle);
            }
            if (settings.Get <bool>("Orbital: Period", true))
            {
                GUILayout.Label("Orbital Period", headingStyle);
            }
            if (settings.Get <bool>("Orbital: Longitude of AN", true))
            {
                GUILayout.Label("Longitude of AN", headingStyle);
            }
            if (settings.Get <bool>("Orbital: Longitude of Pe", true))
            {
                GUILayout.Label("Longitude of Pe", headingStyle);
            }
            if (settings.Get <bool>("Orbital: Semi-major Axis", true))
            {
                GUILayout.Label("Semi-major Axis", headingStyle);
            }
            if (settings.Get <bool>("Orbital: Semi-minor Axis", true))
            {
                GUILayout.Label("Semi-minor Axis", headingStyle);
            }
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            if (settings.Get <bool>("Orbital: Show Grouped Ap/Pe Readouts"))
            {
                if (settings.Get <bool>("Orbital: Apoapsis Height"))
                {
                    GUILayout.Label(Tools.FormatSI(this.vessel.orbit.ApA, Tools.SIUnitType.Distance), dataStyle);
                }
                if (settings.Get <bool>("Orbital: Time to Apoapsis"))
                {
                    GUILayout.Label(Tools.FormatTime(this.vessel.orbit.timeToAp), dataStyle);
                }
                if (settings.Get <bool>("Orbital: Periapsis Height"))
                {
                    GUILayout.Label(Tools.FormatSI(this.vessel.orbit.PeA, Tools.SIUnitType.Distance), dataStyle);
                }
                if (settings.Get <bool>("Orbital: Time to Periapsis"))
                {
                    GUILayout.Label(Tools.FormatTime(this.vessel.orbit.timeToPe), dataStyle);
                }
            }
            else
            {
                if (settings.Get <bool>("Orbital: Apoapsis Height"))
                {
                    GUILayout.Label(Tools.FormatSI(this.vessel.orbit.ApA, Tools.SIUnitType.Distance), dataStyle);
                }
                if (settings.Get <bool>("Orbital: Periapsis Height"))
                {
                    GUILayout.Label(Tools.FormatSI(this.vessel.orbit.PeA, Tools.SIUnitType.Distance), dataStyle);
                }
                if (settings.Get <bool>("Orbital: Time to Apoapsis"))
                {
                    GUILayout.Label(Tools.FormatTime(this.vessel.orbit.timeToAp), dataStyle);
                }
                if (settings.Get <bool>("Orbital: Time to Periapsis"))
                {
                    GUILayout.Label(Tools.FormatTime(this.vessel.orbit.timeToPe), dataStyle);
                }
            }
            if (settings.Get <bool>("Orbital: Inclination"))
            {
                GUILayout.Label(Tools.FormatNumber(this.vessel.orbit.inclination, "°", 6), dataStyle);
            }
            if (settings.Get <bool>("Orbital: Eccentricity"))
            {
                GUILayout.Label(Tools.FormatNumber(this.vessel.orbit.eccentricity, "°", 6), dataStyle);
            }
            if (settings.Get <bool>("Orbital: Period"))
            {
                GUILayout.Label(Tools.FormatTime(this.vessel.orbit.period), dataStyle);
            }
            if (settings.Get <bool>("Orbital: Longitude of AN"))
            {
                GUILayout.Label(Tools.FormatNumber(this.vessel.orbit.LAN, "°", 6), dataStyle);
            }
            if (settings.Get <bool>("Orbital: Longitude of Pe"))
            {
                GUILayout.Label(Tools.FormatNumber(this.vessel.orbit.LAN + this.vessel.orbit.argumentOfPeriapsis, "°", 6), dataStyle);
            }
            if (settings.Get <bool>("Orbital: Semi-major Axis"))
            {
                GUILayout.Label(Tools.FormatSI(this.vessel.orbit.semiMajorAxis, Tools.SIUnitType.Distance), dataStyle);
            }
            if (settings.Get <bool>("Orbital: Semi-minor Axis"))
            {
                GUILayout.Label(Tools.FormatSI(this.vessel.orbit.semiMinorAxis, Tools.SIUnitType.Distance), dataStyle);
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        }