mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
commit
d3503ea1d1
@ -149,14 +149,19 @@ namespace NewHorizons.Builder.General
|
|||||||
secondaryAO.SetKeplerCoordinatesFromTrueAnomaly(ecc, r2 / (1f - ecc), i, l, p, 180);
|
secondaryAO.SetKeplerCoordinatesFromTrueAnomaly(ecc, r2 / (1f - ecc), i, l, p, 180);
|
||||||
|
|
||||||
// Make sure positions are right
|
// Make sure positions are right
|
||||||
primary.transform.position = point.transform.position + OrbitalHelper.GetPosition(primaryAO);
|
var gravity = new OrbitalHelper.Gravity(exponent, totalMass);
|
||||||
secondary.transform.position = point.transform.position + OrbitalHelper.GetPosition(secondaryAO);
|
|
||||||
|
var primaryCat = OrbitalHelper.GetCartesian(gravity, primaryAO);
|
||||||
|
var secondaryCat = OrbitalHelper.GetCartesian(gravity, secondaryAO);
|
||||||
|
|
||||||
|
primary.transform.position = point.transform.position + primaryCat.Item1;
|
||||||
|
secondary.transform.position = point.transform.position + secondaryCat.Item1;
|
||||||
|
|
||||||
Logger.Log($"Primary AO: [{primaryAO}], Secondary AO: [{secondaryAO}]");
|
Logger.Log($"Primary AO: [{primaryAO}], Secondary AO: [{secondaryAO}]");
|
||||||
|
|
||||||
// Finally we update the speeds
|
// Finally we update the speeds
|
||||||
var v1 = OrbitalHelper.GetVelocity(new OrbitalHelper.Gravity(exponent, totalMass), primaryAO);
|
var v1 = primaryCat.Item2;
|
||||||
var v2 = OrbitalHelper.GetVelocity(new OrbitalHelper.Gravity(exponent, totalMass), secondaryAO);
|
var v2 = primaryCat.Item2;
|
||||||
|
|
||||||
var focalPointMotion = point.gameObject.GetComponent<InitialMotion>();
|
var focalPointMotion = point.gameObject.GetComponent<InitialMotion>();
|
||||||
var focalPointVelocity = focalPointMotion == null ? Vector3.zero : focalPointMotion.GetInitVelocity();
|
var focalPointVelocity = focalPointMotion == null ? Vector3.zero : focalPointMotion.GetInitVelocity();
|
||||||
|
|||||||
@ -1,134 +1,155 @@
|
|||||||
using NewHorizons.External;
|
using NewHorizons.External;
|
||||||
using NewHorizons.OrbitalPhysics;
|
using NewHorizons.OrbitalPhysics;
|
||||||
using NewHorizons.Utility;
|
using NewHorizons.Utility;
|
||||||
using OWML.Utils;
|
using OWML.Common;
|
||||||
using PacificEngine.OW_CommonResources.Game.Resource;
|
using OWML.Utils;
|
||||||
using PacificEngine.OW_CommonResources.Game.State;
|
using PacificEngine.OW_CommonResources.Game;
|
||||||
using PacificEngine.OW_CommonResources.Geometry.Orbits;
|
using PacificEngine.OW_CommonResources.Game.Resource;
|
||||||
using System;
|
using PacificEngine.OW_CommonResources.Game.State;
|
||||||
using System.Collections.Generic;
|
using PacificEngine.OW_CommonResources.Geometry.Orbits;
|
||||||
using System.Linq;
|
using System;
|
||||||
using System.Text;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using System.Text;
|
||||||
using Logger = NewHorizons.Utility.Logger;
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
namespace NewHorizons.Builder.General
|
using Logger = NewHorizons.Utility.Logger;
|
||||||
{
|
|
||||||
public static class HeavenlyBodyBuilder
|
namespace NewHorizons.Builder.General
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<string, HeavenlyBody> _bodyMap = new Dictionary<string, HeavenlyBody>();
|
public static class HeavenlyBodyBuilder
|
||||||
|
{
|
||||||
public static void Make(GameObject body, IPlanetConfig config, float SOI, GravityVolume bodyGravity, InitialMotion initialMotion)
|
private static readonly Dictionary<string, HeavenlyBody> _bodyMap = new Dictionary<string, HeavenlyBody>();
|
||||||
{
|
|
||||||
var size = new Position.Size(config.Base.SurfaceSize, SOI);
|
public static void Make(GameObject body, IPlanetConfig config, float SOI, GravityVolume bodyGravity, InitialMotion initialMotion)
|
||||||
|
{
|
||||||
var gravity = Gravity.of(0, 0);
|
var size = new Position.Size(config.Base.SurfaceSize, SOI);
|
||||||
if(bodyGravity != null)
|
var gravity = getGravity(bodyGravity);
|
||||||
{
|
var parent = GetBody(config.Orbit.PrimaryBody);
|
||||||
var G = GravityVolume.GRAVITATIONAL_CONSTANT;
|
var orbit = OrbitalHelper.KeplerCoordinatesFromOrbitModule(config.Orbit);
|
||||||
var exponent = bodyGravity.GetFalloffExponent();
|
if (parent == HeavenlyBody.None)
|
||||||
var mass = bodyGravity._surfaceAcceleration * Mathf.Pow(bodyGravity._upperSurfaceRadius, exponent) / G;
|
{
|
||||||
gravity = Gravity.of(bodyGravity == null ? 2f : exponent, bodyGravity == null ? 0 : mass);
|
Helper.helper.Console.WriteLine($"Could not find planet ({config.Name}) reference to its parent {config.Orbit.PrimaryBody}", MessageType.Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
var parent = GetBody(config.Orbit.PrimaryBody);
|
var hb = GetBody(config.Name);
|
||||||
var orbit = OrbitalHelper.KeplerCoordinatesFromOrbitModule(config.Orbit);
|
if (hb == null)
|
||||||
|
{
|
||||||
var hb = GetBody(config.Name);
|
hb = AddHeavenlyBody(config.Name);
|
||||||
if (hb == null)
|
}
|
||||||
{
|
|
||||||
hb = AddHeavenlyBody(config.Name);
|
Planet.Plantoid planetoid;
|
||||||
}
|
|
||||||
|
if (!config.Orbit.IsStatic)
|
||||||
Planet.Plantoid planetoid;
|
{
|
||||||
|
planetoid = new Planet.Plantoid(size, gravity, body.transform.rotation, initialMotion._initAngularSpeed, parent, orbit);
|
||||||
if (!config.Orbit.IsStatic)
|
}
|
||||||
{
|
else
|
||||||
planetoid = new Planet.Plantoid(size, gravity, body.transform.rotation, initialMotion._initAngularSpeed, parent, orbit);
|
{
|
||||||
}
|
planetoid = new Planet.Plantoid(size, gravity, body.transform.rotation, 0f, HeavenlyBody.None, body.transform.position, Vector3.zero);
|
||||||
else
|
}
|
||||||
{
|
|
||||||
planetoid = new Planet.Plantoid(size, gravity, body.transform.rotation, 0f, HeavenlyBody.None, body.transform.position, Vector3.zero);
|
var mapping = Planet.defaultMapping;
|
||||||
}
|
mapping[hb] = planetoid;
|
||||||
|
Planet.defaultMapping = mapping;
|
||||||
var mapping = Planet.defaultMapping;
|
|
||||||
mapping[hb] = planetoid;
|
// Fix for binary focal points
|
||||||
Planet.defaultMapping = mapping;
|
var focalPoint = Position.AstroLookup[parent].Invoke()?.gameObject.GetComponent<BinaryFocalPoint>();
|
||||||
|
if (focalPoint != null && mapping.ContainsKey(parent))
|
||||||
// Fix for binary focal points
|
{
|
||||||
var focalPoint = Position.AstroLookup[parent].Invoke()?.gameObject.GetComponent<BinaryFocalPoint>();
|
var primary = Position.getBody(GetBody(focalPoint.PrimaryName));
|
||||||
if (focalPoint != null && Planet.defaultMapping.ContainsKey(parent))
|
var secondary = Position.getBody(GetBody(focalPoint.SecondaryName));
|
||||||
{
|
|
||||||
var primary = Position.getBody(GetBody(focalPoint.PrimaryName));
|
if(primary != null && secondary != null)
|
||||||
var secondary = Position.getBody(GetBody(focalPoint.SecondaryName));
|
{
|
||||||
|
Logger.Log($"Fixing BinaryFocalPoint HeavenlyBody gravity value for {parent.name}");
|
||||||
if(primary != null && secondary != null)
|
var primaryGravity = getGravity(primary?.GetAttachedGravityVolume());
|
||||||
{
|
var secondaryGravity = getGravity(secondary?.GetAttachedGravityVolume());
|
||||||
Logger.Log($"Fixing BinaryFocalPoint HeavenlyBody gravity value for {parent.name}");
|
|
||||||
var exponent = ((primary?.GetAttachedGravityVolume()?.GetValue<float>("_falloffExponent") ?? 2f) + (secondary?.GetAttachedGravityVolume()?.GetValue<float>("_falloffExponent") ?? 2f)) / 2f;
|
var exponent = (primaryGravity.exponent + secondaryGravity.exponent) / 2f;
|
||||||
var mass = ((primary?.GetAttachedGravityVolume()?.GetValue<float>("_gravitationalMass") ?? ((primary?.GetMass() ?? 0f) * 1000f)) + (secondary?.GetAttachedGravityVolume()?.GetValue<float>("_gravitationalMass") ?? ((secondary?.GetMass() ?? 0f) * 1000f))) / 4f;
|
var mass = (primaryGravity.mass + secondaryGravity.mass) / 4f;
|
||||||
|
|
||||||
var currentValue = Planet.mapping[parent];
|
mapping[parent] = new Planet.Plantoid(mapping[parent].size, Gravity.of(exponent, mass), mapping[parent].state);
|
||||||
var newValue = new Planet.Plantoid(currentValue.size, Gravity.of(exponent, mass), currentValue.state);
|
Planet.defaultMapping = mapping;
|
||||||
Planet.defaultMapping[parent] = newValue;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public static void Remove(AstroObject obj)
|
||||||
private static HeavenlyBody AddHeavenlyBody(string name)
|
{
|
||||||
{
|
var astro = Position.find(obj);
|
||||||
var hb = new HeavenlyBody(name);
|
|
||||||
_bodyMap.Add(name, hb);
|
var mapping = Planet.defaultMapping;
|
||||||
|
mapping.Remove(astro);
|
||||||
var astroLookup = Position.AstroLookup;
|
Planet.defaultMapping = mapping;
|
||||||
var bodyLookup = Position.BodyLookup;
|
}
|
||||||
|
|
||||||
astroLookup.Add(hb, () => GetAstroObject(name));
|
private static Gravity getGravity(GravityVolume volume)
|
||||||
bodyLookup.Add(hb, () => GetOWRigidbody(name));
|
{
|
||||||
|
if (volume == null)
|
||||||
Position.AstroLookup = astroLookup;
|
{
|
||||||
Position.BodyLookup = bodyLookup;
|
return Gravity.of(2, 0);
|
||||||
|
}
|
||||||
return hb;
|
|
||||||
}
|
var exponent = volume._falloffType != GravityVolume.FalloffType.linear ? 2f : 1f;
|
||||||
|
var mass = (volume._surfaceAcceleration * Mathf.Pow(volume._upperSurfaceRadius, exponent)) / GravityVolume.GRAVITATIONAL_CONSTANT;
|
||||||
private static HeavenlyBody GetBody(string name)
|
|
||||||
{
|
return Gravity.of(exponent, mass);
|
||||||
if (_bodyMap.ContainsKey(name))
|
}
|
||||||
{
|
|
||||||
return _bodyMap[name];
|
private static HeavenlyBody AddHeavenlyBody(string name)
|
||||||
}
|
{
|
||||||
|
var hb = new HeavenlyBody(name);
|
||||||
var hb = Position.find(AstroObjectLocator.GetAstroObject(name));
|
_bodyMap.Add(name, hb);
|
||||||
if (hb != null)
|
|
||||||
{
|
var astroLookup = Position.AstroLookup;
|
||||||
_bodyMap.Add(name, hb);
|
var bodyLookup = Position.BodyLookup;
|
||||||
}
|
|
||||||
return hb;
|
astroLookup.Add(hb, () => GetAstroObject(name));
|
||||||
}
|
bodyLookup.Add(hb, () => GetOWRigidbody(name));
|
||||||
|
|
||||||
public static void OnDestroy()
|
Position.AstroLookup = astroLookup;
|
||||||
{
|
Position.BodyLookup = bodyLookup;
|
||||||
Planet.defaultMapping = Planet.standardMapping;
|
|
||||||
}
|
return hb;
|
||||||
|
}
|
||||||
private static AstroObject GetAstroObject(string name)
|
|
||||||
{
|
private static HeavenlyBody GetBody(string name)
|
||||||
var astroBody = AstroObjectLocator.GetAstroObject(name);
|
{
|
||||||
if (astroBody == null
|
if (_bodyMap.ContainsKey(name))
|
||||||
|| astroBody.gameObject == null)
|
{
|
||||||
{
|
return _bodyMap[name];
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
var hb = Position.find(AstroObjectLocator.GetAstroObject(name));
|
||||||
return astroBody;
|
if (hb != null)
|
||||||
}
|
{
|
||||||
|
_bodyMap.Add(name, hb);
|
||||||
private static OWRigidbody GetOWRigidbody(string name)
|
}
|
||||||
{
|
return hb;
|
||||||
var astroBody = GetAstroObject(name);
|
}
|
||||||
return astroBody?.GetOWRigidbody();
|
|
||||||
}
|
public static void Reset()
|
||||||
}
|
{
|
||||||
}
|
Planet.defaultMapping = Planet.standardMapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AstroObject GetAstroObject(string name)
|
||||||
|
{
|
||||||
|
var astroBody = AstroObjectLocator.GetAstroObject(name);
|
||||||
|
if (astroBody == null
|
||||||
|
|| astroBody.gameObject == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return astroBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OWRigidbody GetOWRigidbody(string name)
|
||||||
|
{
|
||||||
|
var astroBody = GetAstroObject(name);
|
||||||
|
return astroBody?.GetOWRigidbody();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -102,6 +102,8 @@ namespace NewHorizons.Builder.General
|
|||||||
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => RemoveProxy(ao.name.Replace("_Body", "")));
|
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => RemoveProxy(ao.name.Replace("_Body", "")));
|
||||||
|
|
||||||
ao.transform.root.gameObject.SetActive(false);
|
ao.transform.root.gameObject.SetActive(false);
|
||||||
|
|
||||||
|
HeavenlyBodyBuilder.Remove(ao);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RemoveDistantProxyClones()
|
public static void RemoveDistantProxyClones()
|
||||||
|
|||||||
@ -38,7 +38,7 @@ namespace NewHorizons.Builder.Orbital
|
|||||||
var gv = primaryBody.GetGravityVolume();
|
var gv = primaryBody.GetGravityVolume();
|
||||||
if(gv != null)
|
if(gv != null)
|
||||||
{
|
{
|
||||||
var velocity = OrbitalHelper.GetVelocity(new OrbitalHelper.Gravity(primaryBody.GetGravityVolume()), orbit);
|
var velocity = OrbitalHelper.GetCartesian(new OrbitalHelper.Gravity(primaryBody.GetGravityVolume()), orbit).Item2;
|
||||||
|
|
||||||
// For some stupid reason the InitialMotion awake method transforms the perfectly fine direction vector you give it so we preemptively do the inverse so it all cancels out
|
// For some stupid reason the InitialMotion awake method transforms the perfectly fine direction vector you give it so we preemptively do the inverse so it all cancels out
|
||||||
initialMotion._initLinearDirection = body.transform.InverseTransformDirection(velocity.normalized);
|
initialMotion._initLinearDirection = body.transform.InverseTransformDirection(velocity.normalized);
|
||||||
|
|||||||
@ -70,7 +70,7 @@ namespace NewHorizons
|
|||||||
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||||
{
|
{
|
||||||
Logger.Log($"Scene Loaded: {scene.name} {mode}");
|
Logger.Log($"Scene Loaded: {scene.name} {mode}");
|
||||||
HeavenlyBodyBuilder.OnDestroy();
|
HeavenlyBodyBuilder.Reset();
|
||||||
if (scene.name != "SolarSystem") { return; }
|
if (scene.name != "SolarSystem") { return; }
|
||||||
|
|
||||||
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>());
|
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>());
|
||||||
@ -290,7 +290,7 @@ namespace NewHorizons
|
|||||||
|
|
||||||
// Now that we're done move the planet into place
|
// Now that we're done move the planet into place
|
||||||
go.transform.parent = Locator.GetRootTransform();
|
go.transform.parent = Locator.GetRootTransform();
|
||||||
go.transform.position = OrbitalHelper.GetPosition(body.Config.Orbit) + primaryBody.transform.position;
|
go.transform.position = OrbitalHelper.GetCartesian(new OrbitalHelper.Gravity(1, 100), body.Config.Orbit).Item1 + primaryBody.transform.position;
|
||||||
|
|
||||||
if (go.transform.position.magnitude > FurthestOrbit)
|
if (go.transform.position.magnitude > FurthestOrbit)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,119 +1,90 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using NewHorizons.Utility;
|
using NewHorizons.Utility;
|
||||||
using Logger = NewHorizons.Utility.Logger;
|
using Logger = NewHorizons.Utility.Logger;
|
||||||
using NewHorizons.External;
|
using NewHorizons.External;
|
||||||
using CRGravity = PacificEngine.OW_CommonResources.Geometry.Orbits.Gravity;
|
using CRGravity = PacificEngine.OW_CommonResources.Geometry.Orbits.Gravity;
|
||||||
using KeplerCoordinates = PacificEngine.OW_CommonResources.Geometry.Orbits.KeplerCoordinates;
|
using KeplerCoordinates = PacificEngine.OW_CommonResources.Geometry.Orbits.KeplerCoordinates;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wrapper class for OW_CommonResources.Geometry.Orbits functions
|
* Wrapper class for OW_CommonResources.Geometry.Orbits functions
|
||||||
*/
|
*/
|
||||||
namespace NewHorizons.OrbitalPhysics
|
namespace NewHorizons.OrbitalPhysics
|
||||||
{
|
{
|
||||||
public static class OrbitalHelper
|
public static class OrbitalHelper
|
||||||
{
|
{
|
||||||
public enum FalloffType
|
public enum FalloffType
|
||||||
{
|
{
|
||||||
inverseSquared,
|
inverseSquared,
|
||||||
linear,
|
linear,
|
||||||
none
|
none
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3 GetPosition(OrbitModule orbit)
|
public static Tuple<Vector3, Vector3> GetCartesian(Gravity gravity, OrbitModule orbit)
|
||||||
{
|
{
|
||||||
Vector3 pos = Vector3.zero;
|
if (orbit.SemiMajorAxis == 0)
|
||||||
if(orbit.SemiMajorAxis != 0)
|
{
|
||||||
{
|
return Tuple.Create(Vector3.zero, Vector3.zero);
|
||||||
// The gravity doesnt have an affect on position so we put whatever
|
}
|
||||||
var crGravity = new CRGravity(GravityVolume.GRAVITATIONAL_CONSTANT, 1f, 100f);
|
|
||||||
var kepler = KeplerCoordinates.fromTrueAnomaly(orbit.Eccentricity, orbit.SemiMajorAxis, orbit.Inclination, orbit.ArgumentOfPeriapsis, orbit.LongitudeOfAscendingNode, orbit.TrueAnomaly);
|
var crGravity = new CRGravity(GravityVolume.GRAVITATIONAL_CONSTANT, gravity.Exponent, gravity.Mass);
|
||||||
pos = PacificEngine.OW_CommonResources.Geometry.Orbits.OrbitHelper.toCartesian(crGravity, 0f, kepler).Item1;
|
var kepler = KeplerCoordinates.fromTrueAnomaly(orbit.Eccentricity, orbit.SemiMajorAxis, orbit.Inclination, orbit.ArgumentOfPeriapsis, orbit.LongitudeOfAscendingNode, orbit.TrueAnomaly);
|
||||||
}
|
var cartesian = PacificEngine.OW_CommonResources.Geometry.Orbits.OrbitHelper.toCartesian(crGravity, 0f, kepler);
|
||||||
|
|
||||||
return pos;
|
if (cartesian == null)
|
||||||
}
|
{
|
||||||
|
cartesian = Tuple.Create(Vector3.zero, Vector3.zero);
|
||||||
public static Vector3 GetPosition(ParameterizedAstroObject ao)
|
}
|
||||||
{
|
|
||||||
Vector3 pos = Vector3.zero;
|
Logger.Log($"Position : {cartesian.Item1} Velocity : {cartesian.Item2}");
|
||||||
if(ao.SemiMajorAxis != 0)
|
return cartesian;
|
||||||
{
|
}
|
||||||
var crGravity = new CRGravity(GravityVolume.GRAVITATIONAL_CONSTANT, 1f, 100f);
|
|
||||||
var kepler = KeplerCoordinates.fromTrueAnomaly(ao.Eccentricity, ao.SemiMajorAxis, ao.Inclination, ao.ArgumentOfPeriapsis, ao.LongitudeOfAscendingNode, ao.TrueAnomaly);
|
public static Tuple<Vector3, Vector3> GetCartesian(Gravity gravity, ParameterizedAstroObject ao)
|
||||||
pos = PacificEngine.OW_CommonResources.Geometry.Orbits.OrbitHelper.toCartesian(crGravity, 0f, kepler).Item1;
|
{
|
||||||
}
|
if (ao.SemiMajorAxis == 0)
|
||||||
|
{
|
||||||
return pos;
|
return Tuple.Create(Vector3.zero, Vector3.zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3 GetPositionFromTrueAnomaly(float eccentricity, float semiMajorAxis, float inclination, float argumentOfPeriapsis, float longitudeOfAscendingNode, float trueAnomaly)
|
var crGravity = new CRGravity(GravityVolume.GRAVITATIONAL_CONSTANT, gravity.Exponent, gravity.Mass);
|
||||||
{
|
var kepler = KeplerCoordinates.fromTrueAnomaly(ao.Eccentricity, ao.SemiMajorAxis, ao.Inclination, ao.ArgumentOfPeriapsis, ao.LongitudeOfAscendingNode, ao.TrueAnomaly);
|
||||||
Vector3 pos = Vector3.zero;
|
var cartesian = PacificEngine.OW_CommonResources.Geometry.Orbits.OrbitHelper.toCartesian(crGravity, 0f, kepler);
|
||||||
if (semiMajorAxis != 0)
|
|
||||||
{
|
if (cartesian == null)
|
||||||
var crGravity = new CRGravity(GravityVolume.GRAVITATIONAL_CONSTANT, 1f, 100f);
|
{
|
||||||
var kepler = KeplerCoordinates.fromTrueAnomaly(eccentricity, semiMajorAxis, inclination, argumentOfPeriapsis, longitudeOfAscendingNode, trueAnomaly);
|
cartesian = Tuple.Create(Vector3.zero, Vector3.zero);
|
||||||
pos = PacificEngine.OW_CommonResources.Geometry.Orbits.OrbitHelper.toCartesian(crGravity, 0f, kepler).Item1;
|
}
|
||||||
}
|
|
||||||
|
Logger.Log($"Position : {cartesian.Item1} Velocity : {cartesian.Item2}");
|
||||||
return pos;
|
return cartesian;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3 GetPositionFromEccentricAnomaly(float eccentricity, float semiMajorAxis, float inclination, float argumentOfPeriapsis, float longitudeOfAscendingNode, float eccentricAnomaly)
|
public static KeplerCoordinates KeplerCoordinatesFromOrbitModule(OrbitModule orbit)
|
||||||
{
|
{
|
||||||
Vector3 pos = Vector3.zero;
|
return KeplerCoordinates.fromTrueAnomaly(orbit.Eccentricity, orbit.SemiMajorAxis, orbit.Inclination, orbit.ArgumentOfPeriapsis, orbit.LongitudeOfAscendingNode, orbit.TrueAnomaly);
|
||||||
if (semiMajorAxis != 0)
|
}
|
||||||
{
|
|
||||||
var crGravity = new CRGravity(GravityVolume.GRAVITATIONAL_CONSTANT, 1f, 100f);
|
public class Gravity
|
||||||
var kepler = KeplerCoordinates.fromEccentricAnomaly(eccentricity, semiMajorAxis, inclination, argumentOfPeriapsis, longitudeOfAscendingNode, eccentricAnomaly);
|
{
|
||||||
pos = PacificEngine.OW_CommonResources.Geometry.Orbits.OrbitHelper.toCartesian(crGravity, 0f, kepler).Item1;
|
public float Exponent { get; }
|
||||||
}
|
public float Mass { get; }
|
||||||
|
|
||||||
return pos;
|
public Gravity(float exponent, float mass)
|
||||||
}
|
{
|
||||||
|
Exponent = exponent;
|
||||||
public static Vector3 GetVelocity(Gravity gravity, OrbitModule orbit)
|
Mass = mass;
|
||||||
{
|
}
|
||||||
var crGravity = new CRGravity(GravityVolume.GRAVITATIONAL_CONSTANT, gravity.Exponent, gravity.Mass);
|
|
||||||
var kepler = KeplerCoordinates.fromTrueAnomaly(orbit.Eccentricity, orbit.SemiMajorAxis, orbit.Inclination, orbit.ArgumentOfPeriapsis, orbit.LongitudeOfAscendingNode, orbit.TrueAnomaly);
|
public Gravity(GravityVolume gv)
|
||||||
var vel = PacificEngine.OW_CommonResources.Geometry.Orbits.OrbitHelper.toCartesian(crGravity, 0f, kepler).Item2;
|
{
|
||||||
return vel;
|
Exponent = gv.GetFalloffExponent();
|
||||||
}
|
Mass = gv.GetStandardGravitationalParameter() / GravityVolume.GRAVITATIONAL_CONSTANT;
|
||||||
|
}
|
||||||
public static Vector3 GetVelocity(Gravity gravity, ParameterizedAstroObject ao)
|
}
|
||||||
{
|
}
|
||||||
var crGravity = new CRGravity(GravityVolume.GRAVITATIONAL_CONSTANT, gravity.Exponent, gravity.Mass);
|
}
|
||||||
var kepler = KeplerCoordinates.fromTrueAnomaly(ao.Eccentricity, ao.SemiMajorAxis, ao.Inclination, ao.ArgumentOfPeriapsis, ao.LongitudeOfAscendingNode, ao.TrueAnomaly);
|
|
||||||
var vel = PacificEngine.OW_CommonResources.Geometry.Orbits.OrbitHelper.toCartesian(crGravity, 0f, kepler).Item2;
|
|
||||||
return vel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static KeplerCoordinates KeplerCoordinatesFromOrbitModule(OrbitModule orbit)
|
|
||||||
{
|
|
||||||
return KeplerCoordinates.fromTrueAnomaly(orbit.Eccentricity, orbit.SemiMajorAxis, orbit.Inclination, orbit.ArgumentOfPeriapsis, orbit.LongitudeOfAscendingNode, orbit.TrueAnomaly);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Gravity
|
|
||||||
{
|
|
||||||
public float Exponent { get; }
|
|
||||||
public float Mass { get; }
|
|
||||||
|
|
||||||
public Gravity(float exponent, float mass)
|
|
||||||
{
|
|
||||||
Exponent = exponent;
|
|
||||||
Mass = mass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Gravity(GravityVolume gv)
|
|
||||||
{
|
|
||||||
Exponent = gv.GetFalloffExponent();
|
|
||||||
Mass = gv.GetStandardGravitationalParameter() / GravityVolume.GRAVITATIONAL_CONSTANT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,61 +0,0 @@
|
|||||||
using OWML.Utils;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UnityEngine;
|
|
||||||
using NewHorizons.Utility;
|
|
||||||
using Logger = NewHorizons.Utility.Logger;
|
|
||||||
|
|
||||||
namespace NewHorizons.OrbitalPhysics
|
|
||||||
{
|
|
||||||
public class ParameterizedOrbitLine : EllipticOrbitLine
|
|
||||||
{
|
|
||||||
public ParameterizedAstroObject astroObject;
|
|
||||||
|
|
||||||
public override void Start()
|
|
||||||
{
|
|
||||||
base.Start();
|
|
||||||
|
|
||||||
astroObject = _astroObject as ParameterizedAstroObject;
|
|
||||||
|
|
||||||
var periapsis = OrbitalHelper.GetPositionFromEccentricAnomaly(astroObject.Eccentricity, astroObject.SemiMajorAxis, astroObject.Inclination, astroObject.ArgumentOfPeriapsis, astroObject.LongitudeOfAscendingNode, 0f);
|
|
||||||
var semiMinorDecending = OrbitalHelper.GetPositionFromEccentricAnomaly(astroObject.Eccentricity, astroObject.SemiMajorAxis, astroObject.Inclination, astroObject.ArgumentOfPeriapsis, astroObject.LongitudeOfAscendingNode, 90f);
|
|
||||||
var a = astroObject.SemiMajorAxis;
|
|
||||||
var b = a * Mathf.Sqrt(1 - astroObject.Eccentricity * astroObject.Eccentricity);
|
|
||||||
|
|
||||||
_semiMajorAxis = periapsis.normalized * a;
|
|
||||||
_semiMinorAxis = semiMinorDecending.normalized * b;
|
|
||||||
_upAxisDir = Vector3.Cross(_semiMajorAxis, _semiMinorAxis).normalized;
|
|
||||||
_fociDistance = Mathf.Sqrt(a * a - b * b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Literally the stock EllipticOrbitLine but for now I don't want to use the patches from CommonResources
|
|
||||||
public override void Update()
|
|
||||||
{
|
|
||||||
AstroObject primaryAO = _astroObject?.GetPrimaryBody();
|
|
||||||
if (primaryAO == null)
|
|
||||||
{
|
|
||||||
base.enabled = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Vector3 vector = primaryAO.transform.position + this._semiMajorAxis.normalized * this._fociDistance;
|
|
||||||
float num = this.CalcProjectedAngleToCenter(vector, this._semiMajorAxis, this._semiMinorAxis, this._astroObject.transform.position);
|
|
||||||
for (int i = 0; i < this._numVerts; i++)
|
|
||||||
{
|
|
||||||
float f = (float)i / (float)(this._numVerts - 1) * 3.1415927f * 2f - (num + 3.1415927f);
|
|
||||||
this._verts[i] = this._semiMajorAxis * Mathf.Cos(f) + this._semiMinorAxis * Mathf.Sin(f);
|
|
||||||
}
|
|
||||||
this._lineRenderer.SetPositions(this._verts);
|
|
||||||
base.transform.position = vector;
|
|
||||||
base.transform.rotation = Quaternion.LookRotation(this._semiMinorAxis, this._upAxisDir);
|
|
||||||
float num2 = this.DistanceToEllipticalOrbitLine(vector, this._semiMajorAxis, this._semiMinorAxis, this._upAxisDir, Locator.GetActiveCamera().transform.position);
|
|
||||||
float widthMultiplier = Mathf.Min(num2 * (this._lineWidth / 1000f), this._maxLineWidth);
|
|
||||||
float num3 = this._fade ? (1f - Mathf.Clamp01((num2 - this._fadeStartDist) / (this._fadeEndDist - this._fadeStartDist))) : 1f;
|
|
||||||
this._lineRenderer.widthMultiplier = widthMultiplier;
|
|
||||||
this._lineRenderer.startColor = new Color(this._color.r, this._color.g, this._color.b, num3 * num3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -24,16 +24,16 @@ Planets are created using a JSON file format structure, and placed in the `plane
|
|||||||
<!-- /TOC -->
|
<!-- /TOC -->
|
||||||
|
|
||||||
## Roadmap
|
## Roadmap
|
||||||
|
- Stars (Done)
|
||||||
|
- Binary orbits (Done)
|
||||||
|
- Comets (Done)
|
||||||
- Procedurally terrain generation (started)
|
- Procedurally terrain generation (started)
|
||||||
- Asteroid belts (started, needs more customization)
|
- Asteroid belts (started, needs more customization)
|
||||||
- "Quantum" orbits
|
- "Quantum" orbits
|
||||||
- Better terrain and water LOD
|
- Better terrain and water LOD
|
||||||
- Support satellites (using custom models in the assets folder or in-game ones)
|
- Support satellites (using custom models in the assets folder or in-game ones)
|
||||||
- Surface scatter (rocks, trees, etc, using custom models or in-game ones)
|
- Surface scatter: rocks, trees, etc, using in-game models (done) or custom ones
|
||||||
- Stars
|
|
||||||
- Binary orbits
|
|
||||||
- Load planet meshes from asset bundle
|
- Load planet meshes from asset bundle
|
||||||
- Comets
|
|
||||||
- Edit existing planet orbits
|
- Edit existing planet orbits
|
||||||
- Black hole / white hole pairs
|
- Black hole / white hole pairs
|
||||||
- Separate solar system scenes accessible via wormhole
|
- Separate solar system scenes accessible via wormhole
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user