mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Fixed true anomaly
This commit is contained in:
parent
6cb125f84c
commit
d4d0ea32a9
@ -16,8 +16,6 @@ namespace NewHorizons.Components.Orbital
|
||||
public float Eccentricity { get; private set; }
|
||||
public float ArgumentOfPeriapsis { get; private set; }
|
||||
public float TrueAnomaly { get; private set; }
|
||||
public float MeanAnomaly { get; private set; }
|
||||
public float EccentricAnomaly { get; private set; }
|
||||
public float Period { get; private set; }
|
||||
|
||||
public Vector3 InitialPosition { get; private set; }
|
||||
@ -42,15 +40,10 @@ namespace NewHorizons.Components.Orbital
|
||||
var power = primaryGravity.Power;
|
||||
var period = (float) (GravityVolume.GRAVITATIONAL_CONSTANT * (primaryMass + secondaryMass) / (4 * Math.PI * Math.PI * Math.Pow(semiMajorAxis, power)));
|
||||
|
||||
orbitalParameters.Period = period;
|
||||
|
||||
// All in radians
|
||||
var f = Mathf.Deg2Rad * trueAnomaly;
|
||||
var eccentricAnomaly = Mathf.Atan2(Mathf.Sqrt(1 - (eccentricity * eccentricity)) * Mathf.Sin(f), eccentricity + Mathf.Cos(f));
|
||||
var meanAnomaly = eccentricAnomaly - eccentricity * Mathf.Sin(eccentricAnomaly);
|
||||
|
||||
orbitalParameters.Period = period;
|
||||
orbitalParameters.MeanAnomaly = meanAnomaly * Mathf.Rad2Deg;
|
||||
orbitalParameters.EccentricAnomaly = eccentricAnomaly * Mathf.Rad2Deg;
|
||||
|
||||
var p = semiMajorAxis * (1 - (eccentricity * eccentricity)); // Semi-latus rectum
|
||||
var r = p / (1 + eccentricity * Mathf.Cos(f));
|
||||
|
||||
@ -84,11 +77,9 @@ namespace NewHorizons.Components.Orbital
|
||||
v = Mathf.Sqrt(G * primaryMass * ((2f / r) - (1f / semiMajorAxis)));
|
||||
}
|
||||
|
||||
var semiMinorAxis = semiMajorAxis * Mathf.Sqrt(1 - (eccentricity * eccentricity));
|
||||
var focusDistance = Mathf.Sqrt((semiMajorAxis * semiMajorAxis) - (semiMinorAxis * semiMinorAxis));
|
||||
|
||||
var x = semiMajorAxis * Mathf.Cos(eccentricAnomaly) - focusDistance;
|
||||
var y = semiMinorAxis * Mathf.Sin(eccentricAnomaly);
|
||||
// Origin is the focus
|
||||
var x = r * Mathf.Cos(f);
|
||||
var y = r * Mathf.Sin(f);
|
||||
|
||||
var n_p = new Vector2(x, y).normalized;
|
||||
|
||||
|
||||
@ -386,6 +386,7 @@ namespace NewHorizons.Handlers
|
||||
return go;
|
||||
}
|
||||
|
||||
//private static int j = 0;
|
||||
private static void UpdatePosition(GameObject go, NewHorizonsBody body, AstroObject primaryBody, AstroObject secondaryBody)
|
||||
{
|
||||
go.transform.parent = Locator.GetRootTransform();
|
||||
@ -396,6 +397,24 @@ namespace NewHorizons.Handlers
|
||||
var secondaryGravity = new Gravity(secondaryBody.GetGravityVolume());
|
||||
|
||||
var relativePosition = body.Config.Orbit.GetOrbitalParameters(primaryGravity, secondaryGravity).InitialPosition;
|
||||
|
||||
/* Debugging true anomaly
|
||||
if(Main.Instance.CurrentStarSystem != "SolarSystem")
|
||||
{
|
||||
var colors = new Color[] { Color.red, Color.blue, Color.yellow, Color.green, Color.grey, Color.white };
|
||||
var orbit = body.Config.Orbit;
|
||||
// This is gonna be wacky
|
||||
for (int i = 0; i < 360; i += 20)
|
||||
{
|
||||
var color = colors[j % (colors.Count() - 1)];
|
||||
orbit.TrueAnomaly = i;
|
||||
var shape = AddDebugShape.AddSphere(primaryBody.gameObject, 100, color);
|
||||
shape.transform.position = orbit.GetOrbitalParameters(primaryGravity, secondaryGravity).InitialPosition + primaryBody.transform.position;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
*/
|
||||
|
||||
go.transform.position = relativePosition + primaryBody.transform.position;
|
||||
}
|
||||
else
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user