Skip to content

Commit

Permalink
Added more NBody - needs state vector breakdown, Added to #67, Fixed #69
Browse files Browse the repository at this point in the history
  • Loading branch information
Whitecat106 committed Jun 23, 2016
1 parent 570ffb5 commit 5ac6d1c
Show file tree
Hide file tree
Showing 6 changed files with 758 additions and 181 deletions.
57 changes: 54 additions & 3 deletions Source/DecayManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,12 @@ public void SetGUIToggledFalse(Part part)

public void UpdateActiveVesselInformation(Vessel vessel)
{
if (vessel == FlightGlobals.ActiveVessel)
if (HighLogic.LoadedScene != GameScenes.EDITOR) // 1.6.0 Fixes VAB Rightclick errors
{
VesselData.UpdateActiveVesselData(vessel);
if (vessel == FlightGlobals.ActiveVessel)
{
VesselData.UpdateActiveVesselData(vessel);
}
}
}

Expand Down Expand Up @@ -636,15 +639,48 @@ public static bool CheckReferenceBody(Vessel vessel) // 1.6.0 Body Checks

}

public static bool CheckNBodyAltitude(Vessel vessel)
{
bool BeyondSafeArea = false;

if (Math.Abs(vessel.orbitDriver.orbit.altitude) > (2.0 * vessel.orbitDriver.orbit.referenceBody.Radius))
{
BeyondSafeArea = true;
}

return BeyondSafeArea;
}


public static void RealisticDecaySimulator(Vessel vessel) // 1.4.0 Cleanup
{
Orbit orbit = vessel.orbitDriver.orbit;
CelestialBody body = orbit.referenceBody;

if (CheckReferenceBody(vessel))
if (Settings.ReadNB() && CheckNBodyAltitude(vessel))
{
if (vessel.situation == Vessel.Situations.ORBITING)
{
/*
print("Pos: " + vessel.orbitDriver.orbit.pos);
print("PosAtUT: " + vessel.orbitDriver.orbit.getPositionAtUT(HighLogic.CurrentGame.UniversalTime));
print("PosAlternate: " + vessel.orbitDriver.orbit.getRelativePositionAtUT(HighLogic.CurrentGame.UniversalTime));
print("DifferenceBetween Pos & PosAlt: " + (vessel.orbitDriver.orbit.pos - vessel.orbitDriver.orbit.getRelativePositionAtUT(HighLogic.CurrentGame.UniversalTime)));
print("Vel: " + vessel.orbitDriver.orbit.vel.magnitude);
print("VelAt: " + vessel.orbitDriver.orbit.getOrbitalSpeedAt(HighLogic.CurrentGame.UniversalTime));
print("VelAtAlt: " + vessel.orbitDriver.orbit.getOrbitalSpeedAtRelativePos(vessel.orbitDriver.orbit.getRelativePositionAtUT(HighLogic.CurrentGame.UniversalTime)));
print("Energy: " + vessel.orbitDriver.orbit.orbitalEnergy);
print("Energy Calculated: " + (((Math.Pow(vessel.orbit.vel.magnitude, 2.0)) / 2.0) - (vessel.orbitDriver.orbit.referenceBody.gravParameter / (vessel.orbitDriver.orbit.altitude + vessel.orbit.referenceBody.Radius))));
*/

NBodyManager.ManageVessel(vessel); // 1.6.0 N-Body master reference
}
}

if (CheckReferenceBody(vessel))
{
RealisticGravitationalPertubationDecay(vessel); // 1.5.0
RealisticRadiationDragDecay(vessel); // 1.5.0 Happens everywhere now
RealisticYarkovskyEffectDecay(vessel); // 1.5.0 // Partial, full for 1.6.0
Expand Down Expand Up @@ -886,6 +922,7 @@ public static void RealisticYarkovskyEffectDecay(Vessel vessel) // 1.5.0
VesselData.UpdateVesselSMA(vessel, VesselData.FetchSMA(vessel) - (-1.0 * YarkovskyEffect.FetchDeltaSMA(vessel)));
}


#endregion

#region Old Stock
Expand Down Expand Up @@ -1043,7 +1080,9 @@ public static void ActiveDecayRealistic(Vessel vessel) // 1.4.0 Use R
if ((p.physicalSignificance == Part.PhysicalSignificance.FULL) &&
(p.Rigidbody != null))
{
// NBody Active
// p.Rigidbody.AddForce(Vector3d.back * (decayForce)); // 1.5.0

}
}

Expand All @@ -1060,6 +1099,8 @@ public static void ActiveDecayRealistic(Vessel vessel) // 1.4.0 Use R
{
if (vessel.vesselType != VesselType.EVA)
{
NBodyManager.ManageVessel(vessel); // 1.6.0 NBody

VesselData.UpdateVesselSMA(vessel, (VesselData.FetchSMA(vessel) - DecayValue));
CatchUpOrbit(vessel);
}
Expand Down Expand Up @@ -1329,6 +1370,16 @@ public static double DecayRateYarkovskyEffect(Vessel vessel)
return DecayRate;
}

public static double DecayRateNBodyPerturbation(Vessel vessel)
{
double decayRate = 0;
//decayRate = NBodyManager.CalculateSMA(vessel, vessel.orbitDriver.orbit.getOrbitalSpeedAtRelativePos(vessel.orbitDriver.orbit.getRelativePositionAtUT(HighLogic.CurrentGame.UniversalTime)), HighLogic.CurrentGame.UniversalTime, 1.0);

// Work this out.

return decayRate;
}

public static double DecayRateTotal(Vessel vessel)
{
double Total = DecayRateAtmosphericDrag(vessel) + DecayRateGravitationalPertubation(vessel) + DecayRateRadiationPressure(vessel) + DecayRateYarkovskyEffect(vessel);
Expand Down
35 changes: 35 additions & 0 deletions Source/NBodyConicsManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using KSP.IO;

namespace WhitecatIndustries
{
public static class NBodyConicsManager
{
public static void DrawPredictedVesselPath(Vessel vessel)
{

}

public static void DrawPredictedBodyPath(CelestialBody body)
{


}

public static void DrawHillSphere(CelestialBody body)
{


}

public static void DrawSphereOfInfluence(CelestialBody body)
{


}
}
}
Loading

0 comments on commit 5ac6d1c

Please sign in to comment.