Skip to content

Commit

Permalink
Merge pull request #303 from Kopernicus/Sigma88
Browse files Browse the repository at this point in the history
Orbital Period
StollD authored Aug 2, 2018
2 parents 58d72c2 + abd00d3 commit 756dd23
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Kopernicus/Configuration/OrbitLoader.cs
Original file line number Diff line number Diff line change
@@ -273,6 +273,14 @@ public void FinalizeOrbit()
FinalizeOrbit(Value);
}

// OrbitalPeriod
[ParserTarget("period")]
public NumericParser<Double> period
{
get { return Value.orbit.period; }
set { OrbitalPeriod(Value, value); }
}

// Parser apply event
void IParserEventSubscriber.Apply(ConfigNode node)
{
@@ -405,6 +413,34 @@ public static void FinalizeOrbit(CelestialBody body)
UnityEngine.Debug.Log("CBUpdate for " + body.name + " failed: " + e.Message);
}
}

// Set Orbital Period
public static void OrbitalPeriod(CelestialBody body, Double period)
{
if (body.orbitDriver != null && body.referenceBody != null)
{
body.orbit.period = period;
body.orbit.meanMotion =
2 * Math.PI / body.orbit.period; // in theory this should work but I haven't tested it

if (body.orbit.eccentricity <= 1.0)
{
body.orbit.meanAnomaly = body.orbit.meanAnomalyAtEpoch;
body.orbit.orbitPercent = body.orbit.meanAnomalyAtEpoch / (Math.PI * 2);
body.orbit.ObTAtEpoch = body.orbit.orbitPercent * body.orbit.period;
}
else
{
// ignores this body's own mass for this one...
body.orbit.meanAnomaly = body.orbit.meanAnomalyAtEpoch;
body.orbit.ObT =
Math.Pow(
Math.Pow(Math.Abs(body.orbit.semiMajorAxis), 3.0) /
body.orbit.referenceBody.gravParameter, 0.5) * body.orbit.meanAnomaly;
body.orbit.ObTAtEpoch = body.orbit.ObT;
}
}
}
}
}
}

0 comments on commit 756dd23

Please sign in to comment.