Version 0.9.21
--- a/Tools.cs
+++ b/Tools.cs
@@ -149,67 +149,17 @@
return string.Format("{0}° {1}", Math.Abs(v_lat).ToString(format), dir_lat);
}
- ///////////////////////////////////////////////////////////////////////////////
-
- //For MuMech_get_heading()
- public class MuMech_MovingAverage
- {
- private double[] store;
- private int storeSize;
- private int nextIndex = 0;
-
- public double value
- {
- get
- {
- double tmp = 0;
- foreach (double i in store)
- {
- tmp += i;
- }
- return tmp / storeSize;
- }
- set
- {
- store[nextIndex] = value;
- nextIndex = (nextIndex + 1) % storeSize;
- }
- }
-
- public MuMech_MovingAverage(int size = 10, double startingValue = 0)
- {
- storeSize = size;
- store = new double[size];
- force(startingValue);
- }
-
- public void force(double newValue)
- {
- for (int i = 0; i < storeSize; i++)
- {
- store[i] = newValue;
- }
- }
-
- public static implicit operator double(MuMech_MovingAverage v)
- {
- return v.value;
- }
-
- public override string ToString()
- {
- return value.ToString();
- }
-
- public string ToString(string format)
- {
- return value.ToString(format);
- }
- }
- //From http://svn.mumech.com/KSP/trunk/MuMechLib/VOID.vesselState.cs
- public static double MuMech_get_heading(Vessel vessel)
- {
- Vector3d CoM;
+ /*
+ * MuMechLib Methods
+ * The methods below are adapted from MuMechLib, © 2013-2014 r4m0n
+ * The following methods are a derivative work of the code from MuMechLib in the MechJeb project.
+ * Used under license.
+ * */
+
+ // Derived from MechJeb2/VesselState.cs
+ public static Quaternion getSurfaceRotation(this Vessel vessel)
+ {
+ Vector3 CoM;
try
{
@@ -217,25 +167,42 @@
}
catch
{
- return double.NaN;
- }
-
- Vector3d up = (CoM - vessel.mainBody.position).normalized;
- Vector3d north = Vector3d.Exclude(
- up,
- (vessel.mainBody.position +
- vessel.mainBody.transform.up * (float)vessel.mainBody.Radius
- ) - CoM).normalized;
-
- Quaternion rotationSurface = Quaternion.LookRotation(north, up);
- Quaternion rotationvesselSurface = Quaternion.Inverse(
- Quaternion.Euler(90, 0, 0) *
- Quaternion.Inverse(vessel.transform.rotation) *
- rotationSurface);
-
- return rotationvesselSurface.eulerAngles.y;
- }
- //From http://svn.mumech.com/KSP/trunk/MuMechLib/MuUtils.cs
+ return new Quaternion();
+ }
+
+ Vector3 bodyPosition = vessel.mainBody.position;
+ Vector3 bodyUp = vessel.mainBody.transform.up;
+
+ Vector3 surfaceUp = (CoM - vessel.mainBody.position).normalized;
+ Vector3 surfaceNorth = Vector3.Exclude(
+ surfaceUp,
+ (bodyPosition + bodyUp * (float)vessel.mainBody.Radius) - CoM
+ ).normalized;
+
+ Quaternion surfaceRotation = Quaternion.LookRotation(surfaceNorth, surfaceUp);
+
+ return Quaternion.Inverse(
+ Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(vessel.GetTransform().rotation) * surfaceRotation
+ );
+ }
+
+ // Derived from MechJeb2/VesselState.cs
+ public static double getSurfaceHeading(this Vessel vessel)
+ {
+ return vessel.getSurfaceRotation().eulerAngles.y;
+ }
+
+ // Derived from MechJeb2/VesselState.cs
+ public static double getSurfacePitch(this Vessel vessel)
+ {
+ Quaternion vesselSurfaceRotation = vessel.getSurfaceRotation();
+
+ return (vesselSurfaceRotation.eulerAngles.x > 180f) ?
+ (360f - vesselSurfaceRotation.eulerAngles.x) :
+ -vesselSurfaceRotation.eulerAngles.x;
+ }
+
+ // Derived from MechJeb2/MuUtils.cs
public static string MuMech_ToSI(
double d, int digits = 3, int MinMagnitude = 0, int MaxMagnitude = int.MaxValue
)
@@ -325,6 +292,10 @@
}
}
+ /*
+ * END MuMecLib METHODS
+ * */
+
public static string ConvertInterval(double seconds)
{
string format_1 = "{0:D1}y {1:D1}d {2:D2}h {3:D2}m {4:D2}.{5:D1}s";
--- a/VOID_Core.cs
+++ b/VOID_Core.cs
@@ -69,7 +69,7 @@
* Fields
* */
protected string VoidName = "VOID";
- protected string VoidVersion = "0.9.20";
+ protected string VoidVersion = "0.9.21";
protected bool _factoryReset = false;
@@ -958,10 +958,10 @@
this._skinName = this.defaultSkin;
- this.VOIDIconOnActivePath = "VOID/Textures/void_icon_light_glow";
- this.VOIDIconOnInactivePath = "VOID/Textures/void_icon_dark_glow";
- this.VOIDIconOffActivePath = "VOID/Textures/void_icon_light";
- this.VOIDIconOffInactivePath = "VOID/Textures/void_icon_dark";
+ this.VOIDIconOnInactivePath = "VOID/Textures/void_icon_light_glow";
+ this.VOIDIconOnActivePath = "VOID/Textures/void_icon_dark_glow";
+ this.VOIDIconOffInactivePath = "VOID/Textures/void_icon_light";
+ this.VOIDIconOffActivePath = "VOID/Textures/void_icon_dark";
this.UseToolbarManager = false;
--- a/VOID_HUD.cs
+++ b/VOID_HUD.cs
@@ -93,10 +93,7 @@
this.textColors.Add(Color.cyan);
this.textColors.Add(Color.magenta);
- VOID_Core.Instance.LabelStyles["hud"] = new GUIStyle();
- VOID_Core.Instance.LabelStyles["hud"].normal.textColor = this.textColors [this.ColorIndex];
-
- this.leftHUDdefaultPos = new Rect(Screen.width * .2083f, 0f, 300f, 90f);
+ this.leftHUDdefaultPos = new Rect(Screen.width * .375f - 300f, 0f, 300f, 90f);
this.leftHUDPos = new Rect(this.leftHUDdefaultPos);
this.rightHUDdefaultPos = new Rect(Screen.width * .625f, 0f, 300f, 90f);
@@ -113,9 +110,15 @@
leftHUD = new StringBuilder();
+ VOID_Core.Instance.LabelStyles["hud"].alignment = TextAnchor.UpperRight;
+
if (VOID_Core.Instance.powerAvailable)
{
- leftHUD.AppendFormat("Obt Alt: {0} Obt Vel: {1}",
+ leftHUD.AppendFormat("Primary: {0} Inc: {1}",
+ VOID_Data.primaryName.ValueUnitString(),
+ VOID_Data.orbitInclination.ValueUnitString("F3")
+ );
+ leftHUD.AppendFormat("\nObt Alt: {0} Obt Vel: {1}",
VOID_Data.orbitAltitude.ToSIString(),
VOID_Data.orbitVelocity.ToSIString()
);
@@ -127,16 +130,19 @@
VOID_Data.oribtPeriAlt.ToSIString(),
VOID_Data.timeToPeri.ValueUnitString()
);
- leftHUD.AppendFormat("\nInc: {0}", VOID_Data.orbitInclination.ValueUnitString("F3"));
- leftHUD.AppendFormat("\nPrimary: {0}", VOID_Data.primaryName.ValueUnitString());
-
- GUILayout.Label(leftHUD.ToString(), VOID_Core.Instance.LabelStyles["hud"], GUILayout.ExpandWidth(true));
+ leftHUD.AppendFormat("\nTot Δv: {0} Stg Δv: {1}",
+ VOID_Data.totalDeltaV.ToSIString(2),
+ VOID_Data.stageDeltaV.ToSIString(2)
+ );
}
else
{
+ VOID_Core.Instance.LabelStyles["hud"].normal.textColor = Color.red;
leftHUD.Append(string.Intern("-- POWER LOST --"));
}
+ GUILayout.Label(leftHUD.ToString(), VOID_Core.Instance.LabelStyles["hud"], GUILayout.ExpandWidth(true));
+
if (!this.positionsLocked)
{
GUI.DragWindow();
@@ -151,9 +157,15 @@
rightHUD = new StringBuilder();
+ VOID_Core.Instance.LabelStyles["hud"].alignment = TextAnchor.UpperLeft;
+
if (VOID_Core.Instance.powerAvailable)
{
- rightHUD.AppendFormat("Srf Alt: {0} Srf Vel: {1}",
+ rightHUD.AppendFormat("Biome: {0} Sit: {1}",
+ VOID_Data.currBiome.ValueUnitString(),
+ VOID_Data.expSituation.ValueUnitString()
+ );
+ rightHUD.AppendFormat("\nSrf Alt: {0} Srf Vel: {1}",
VOID_Data.trueAltitude.ToSIString(),
VOID_Data.surfVelocity.ToSIString()
);
@@ -165,14 +177,14 @@
VOID_Data.surfLatitude.ValueUnitString(),
VOID_Data.surfLongitude.ValueUnitString()
);
- rightHUD.AppendFormat("\nHdg: {0}", VOID_Data.vesselHeading.ValueUnitString());
- rightHUD.AppendFormat("\nBiome: {0} Sit: {1}",
- VOID_Data.currBiome.ValueUnitString(),
- VOID_Data.expSituation.ValueUnitString()
+ rightHUD.AppendFormat("\nHdg: {0} Pit: {1}",
+ VOID_Data.vesselHeading.ValueUnitString(),
+ VOID_Data.vesselPitch.ToSIString(2)
);
}
else
{
+ VOID_Core.Instance.LabelStyles["hud"].normal.textColor = Color.red;
rightHUD.Append(string.Intern("-- POWER LOST --"));
}
@@ -189,6 +201,11 @@
public override void DrawGUI()
{
+ if (!VOID_Core.Instance.LabelStyles.ContainsKey("hud"))
+ {
+ VOID_Core.Instance.LabelStyles["hud"] = new GUIStyle(GUI.skin.label);
+ }
+
VOID_Core.Instance.LabelStyles["hud"].normal.textColor = textColors [ColorIndex];
this.leftHUDPos = GUI.Window(
@@ -202,7 +219,7 @@
this.rightHUDPos = GUI.Window(
VOID_Core.Instance.windowID,
this.rightHUDPos,
- this.leftHUDWindow,
+ this.rightHUDWindow,
GUIContent.none,
GUIStyle.none
);
@@ -233,6 +250,68 @@
"Situation",
new Func<string> (() => VOID_Core.Instance.vessel.GetExperimentSituation().HumanString())
);
+
+ public static VOID_DoubleValue vesselPitch = new VOID_DoubleValue(
+ "Pitch",
+ () => core.vessel.getSurfacePitch(),
+ "°"
+ );
+
+ public static VOID_DoubleValue stageMassFlow = new VOID_DoubleValue(
+ "Stage Mass Flow",
+ delegate()
+ {
+ if (simManager.LastStage == null)
+ {
+ return double.NaN;
+ }
+
+ double stageIsp = simManager.LastStage.isp;
+ double stageThrust = simManager.LastStage.actualThrust;
+
+ return stageThrust / (stageIsp * KerbinGee);
+ },
+ "Mg/s"
+ );
+
+ public static VOID_DoubleValue burnTimeCompleteAtNode = new VOID_DoubleValue(
+ "Full burn time to complete at node",
+ delegate()
+ {
+ if (simManager.LastStage == null)
+ {
+ return double.NaN;
+ }
+
+ double nextManeuverDV = core.vessel.patchedConicSolver.maneuverNodes[0].DeltaV.magnitude;
+ double stageThrust = simManager.LastStage.actualThrust;
+
+ return burnTime(nextManeuverDV, totalMass, stageMassFlow, stageThrust);
+ },
+ "s"
+ );
+
+ public static VOID_DoubleValue burnTimeHalfDoneAtNode = new VOID_DoubleValue(
+ "Full burn time to be half done at node",
+ delegate()
+ {
+ if (simManager.LastStage == null)
+ {
+ return double.NaN;
+ }
+
+ double nextManeuverDV = core.vessel.patchedConicSolver.maneuverNodes[0].DeltaV.magnitude / 2d;
+ double stageThrust = simManager.LastStage.actualThrust;
+
+ return burnTime(nextManeuverDV, totalMass, stageMassFlow, stageThrust);
+ },
+ "s"
+ );
+
+ private static double burnTime(double deltaV, double initialMass, double massFlow, double thrust)
+ {
+ return initialMass / massFlow * (Math.Exp(deltaV * massFlow / thrust) - 1d);
+ }
}
}
--- a/VOID_SurfAtmo.cs
+++ b/VOID_SurfAtmo.cs
@@ -128,7 +128,7 @@
"Heading",
delegate()
{
- double heading = Tools.MuMech_get_heading(VOID_Core.Instance.vessel);
+ double heading = core.vessel.getSurfaceHeading();
string cardinal = Tools.get_heading_text(heading);
return string.Format(