mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Added ability to remove the sun
This commit is contained in:
parent
973c0008d9
commit
0283969be9
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ packages
|
||||
.vs
|
||||
bin
|
||||
obj
|
||||
Build
|
||||
@ -49,10 +49,15 @@ namespace NewHorizons.Builder.General
|
||||
if (config.Orbit.IsTidallyLocked)
|
||||
{
|
||||
var alignment = body.AddComponent<AlignWithTargetBody>();
|
||||
alignment.SetTargetBody(primaryBody.GetAttachedOWRigidbody());
|
||||
alignment.SetTargetBody(primaryBody?.GetAttachedOWRigidbody());
|
||||
alignment.SetValue("_usePhysicsToRotate", true);
|
||||
}
|
||||
|
||||
if(config.Base.CenterOfSolarSystem)
|
||||
{
|
||||
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => Locator.GetCenterOfTheUniverse()._staticReferenceFrame = owRigidBody, 2);
|
||||
}
|
||||
|
||||
return new Tuple<AstroObject, OWRigidbody>(astroObject, owRigidBody);
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ namespace NewHorizons.Builder.General
|
||||
forceDetector.SetValue("_inheritElement0", inherit);
|
||||
OWRB.RegisterAttachedForceDetector(forceDetector);
|
||||
|
||||
GravityVolume parentGravityVolume = primaryBody.GetAttachedOWRigidbody().GetAttachedGravityVolume();
|
||||
GravityVolume parentGravityVolume = primaryBody?.GetAttachedOWRigidbody()?.GetAttachedGravityVolume();
|
||||
if (parentGravityVolume != null)
|
||||
{
|
||||
forceDetector.SetValue("_detectableFields", new ForceVolume[] { parentGravityVolume });
|
||||
@ -33,7 +33,7 @@ namespace NewHorizons.Builder.General
|
||||
else if (astroObject != null)
|
||||
{
|
||||
// It's probably a focal point (or its just broken)
|
||||
var binaryFocalPoint = primaryBody.gameObject.GetComponent<BinaryFocalPoint>();
|
||||
var binaryFocalPoint = primaryBody?.gameObject?.GetComponent<BinaryFocalPoint>();
|
||||
if(binaryFocalPoint != null)
|
||||
{
|
||||
if(astroObject.GetCustomName().Equals(binaryFocalPoint.PrimaryName)) {
|
||||
|
||||
@ -17,21 +17,6 @@ namespace NewHorizons.Builder.Orbital
|
||||
{
|
||||
public static InitialMotion Make(GameObject body, AstroObject primaryBody, OWRigidbody OWRB, OrbitModule orbit)
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
ParameterizedInitialMotion initialMotion = body.AddComponent<ParameterizedInitialMotion>();
|
||||
initialMotion.SetPrimary(primaryBody);
|
||||
initialMotion.SetOrbitalParameters(
|
||||
orbit.Eccentricity,
|
||||
orbit.SemiMajorAxis,
|
||||
orbit.Inclination,
|
||||
orbit.LongitudeOfAscendingNode,
|
||||
orbit.ArgumentOfPeriapsis,
|
||||
orbit.TrueAnomaly);
|
||||
initialMotion.SetValue("_initAngularSpeed", orbit.SiderealPeriod == 0 ? 0.02f : 1.0f / orbit.SiderealPeriod);
|
||||
*/
|
||||
|
||||
InitialMotion initialMotion = body.AddComponent<InitialMotion>();
|
||||
return Update(initialMotion, body, primaryBody, OWRB, orbit);
|
||||
}
|
||||
@ -40,10 +25,10 @@ namespace NewHorizons.Builder.Orbital
|
||||
{
|
||||
if (!orbit.IsStatic)
|
||||
{
|
||||
initialMotion.SetPrimaryBody(primaryBody.GetAttachedOWRigidbody());
|
||||
initialMotion.SetPrimaryBody(primaryBody?.GetAttachedOWRigidbody());
|
||||
initialMotion.SetValue("_orbitAngle", orbit.Inclination);
|
||||
initialMotion.SetValue("_isGlobalAxis", false);
|
||||
if (orbit.Eccentricity != 0 && primaryBody.GetGravityVolume() != null)
|
||||
if (orbit.Eccentricity != 0 && primaryBody?.GetGravityVolume() != null)
|
||||
{
|
||||
// Calculate speed at apoapsis
|
||||
KeplerElements kepler = KeplerElements.FromOrbitModule(orbit);
|
||||
|
||||
1
NewHorizons/External/BaseModule.cs
vendored
1
NewHorizons/External/BaseModule.cs
vendored
@ -20,5 +20,6 @@ namespace NewHorizons.External
|
||||
public float LavaSize { get; set; }
|
||||
public bool HasCometTail { get; set; }
|
||||
public bool HasReferenceFrame { get; set; } = true;
|
||||
public bool CenterOfSolarSystem { get; set; } = false;
|
||||
}
|
||||
}
|
||||
|
||||
2
NewHorizons/External/StarModule.cs
vendored
2
NewHorizons/External/StarModule.cs
vendored
@ -12,5 +12,7 @@ namespace NewHorizons.External
|
||||
public float Size { get; set; }
|
||||
public MColor32 Tint { get; set; }
|
||||
public MColor32 SolarFlareTint { get; set; }
|
||||
public MColor32 LightTint { get; set; }
|
||||
public float SolarLuminosity { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,20 +202,29 @@ namespace NewHorizons
|
||||
|
||||
public static GameObject GenerateBody(NewHorizonsBody body, bool defaultPrimaryToSun = false)
|
||||
{
|
||||
AstroObject primaryBody = AstroObjectLocator.GetAstroObject(body.Config.Orbit.PrimaryBody);
|
||||
if (primaryBody == null)
|
||||
AstroObject primaryBody;
|
||||
if(body.Config.Orbit.PrimaryBody != null)
|
||||
{
|
||||
if(defaultPrimaryToSun)
|
||||
primaryBody = AstroObjectLocator.GetAstroObject(body.Config.Orbit.PrimaryBody);
|
||||
if (primaryBody == null)
|
||||
{
|
||||
Logger.Log($"Couldn't find {body.Config.Orbit.PrimaryBody}, defaulting to Sun");
|
||||
primaryBody = AstroObjectLocator.GetAstroObject("Sun");
|
||||
}
|
||||
else
|
||||
{
|
||||
NextPassBodies.Add(body);
|
||||
return null;
|
||||
if (defaultPrimaryToSun)
|
||||
{
|
||||
Logger.Log($"Couldn't find {body.Config.Orbit.PrimaryBody}, defaulting to Sun");
|
||||
primaryBody = AstroObjectLocator.GetAstroObject("Sun");
|
||||
}
|
||||
else
|
||||
{
|
||||
NextPassBodies.Add(body);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
primaryBody = null;
|
||||
}
|
||||
|
||||
|
||||
Logger.Log($"Begin generation sequence of [{body.Config.Name}]");
|
||||
|
||||
@ -272,7 +281,7 @@ namespace NewHorizons
|
||||
|
||||
// Now that we're done move the planet into place
|
||||
go.transform.parent = Locator.GetRootTransform();
|
||||
go.transform.position = positionVector + primaryBody.transform.position;
|
||||
go.transform.position = positionVector + (primaryBody == null ? Vector3.zero : primaryBody.transform.position);
|
||||
|
||||
if (go.transform.position.magnitude > FurthestOrbit)
|
||||
{
|
||||
|
||||
@ -1,112 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using NewHorizons.Utility;
|
||||
using Logger = NewHorizons.Utility.Logger;
|
||||
|
||||
namespace NewHorizons.OrbitalPhysics
|
||||
{
|
||||
public class ParameterizedInitialMotion : InitialMotion
|
||||
{
|
||||
/*
|
||||
private new void Awake()
|
||||
{
|
||||
_rotationAxis = base.transform.TransformDirection(_rotationAxis);
|
||||
_satelliteBody = this.GetRequiredComponent<OWRigidbody>();
|
||||
}
|
||||
|
||||
private new void Start()
|
||||
{
|
||||
_satelliteBody.UpdateCenterOfMass();
|
||||
_satelliteBody.AddVelocityChange(GetInitVelocity());
|
||||
_satelliteBody.AddAngularVelocityChange(GetInitAngularVelocity());
|
||||
}
|
||||
|
||||
public new Vector2 GetOrbitEllipseSemiAxes()
|
||||
{
|
||||
var x = _semiMajorAxis;
|
||||
var y = _semiMajorAxis * Mathf.Sqrt(1 - _eccentricity * _eccentricity);
|
||||
|
||||
return new Vector2(x, y);
|
||||
}
|
||||
|
||||
public new Vector3 GetInitAngularVelocity()
|
||||
{
|
||||
return _rotationAxis.normalized * _initAngularSpeed;
|
||||
}
|
||||
|
||||
public new OWRigidbody GetPrimaryBody()
|
||||
{
|
||||
return _primary.GetAttachedOWRigidbody();
|
||||
}
|
||||
|
||||
public new void SetPrimaryBody(OWRigidbody primaryBody)
|
||||
{
|
||||
_primary = primaryBody.gameObject.GetComponent<AstroObject>();
|
||||
}
|
||||
|
||||
public new Vector3 GetInitVelocity()
|
||||
{
|
||||
if(_initVelocityDirty)
|
||||
{
|
||||
var state = OrbitalHelper.CartesianStateVectorsFromTrueAnomaly(
|
||||
_primary.GetGravityVolume().GetStandardGravitationalParameter(),
|
||||
_eccentricity,
|
||||
_semiMajorAxis,
|
||||
_inclination,
|
||||
_longitudeOfAscendingNode,
|
||||
_argumentOfPeriapsis,
|
||||
_trueAnomaly,
|
||||
_primary.GetGravityVolume().GetFalloffType()
|
||||
);
|
||||
_initVelocity = state.Velocity;
|
||||
|
||||
if(_primary?.GetComponent<InitialMotion>() != null)
|
||||
{
|
||||
var primaryVel = _primary.GetComponent<InitialMotion>().GetInitVelocity();
|
||||
Logger.Log($"{primaryVel}");
|
||||
_initVelocity += primaryVel;
|
||||
}
|
||||
|
||||
_initVelocityDirty = false;
|
||||
}
|
||||
return _initVelocity;
|
||||
}
|
||||
|
||||
public void SetOrbitalParameters(float eccentricity, float semiMajorAxis, float inclination, float longitudeOfAscendingNode, float argumentOfPeriapsis, float trueAnomaly)
|
||||
{
|
||||
_eccentricity = eccentricity;
|
||||
_semiMajorAxis = semiMajorAxis;
|
||||
_inclination = inclination;
|
||||
_longitudeOfAscendingNode = longitudeOfAscendingNode;
|
||||
_argumentOfPeriapsis = argumentOfPeriapsis;
|
||||
_trueAnomaly = trueAnomaly;
|
||||
}
|
||||
|
||||
public void SetPrimary(AstroObject primary)
|
||||
{
|
||||
_primary = primary;
|
||||
}
|
||||
|
||||
private float _eccentricity;
|
||||
private float _semiMajorAxis;
|
||||
private float _inclination;
|
||||
private float _longitudeOfAscendingNode;
|
||||
private float _argumentOfPeriapsis;
|
||||
private float _trueAnomaly;
|
||||
|
||||
private AstroObject _primary;
|
||||
|
||||
private bool _initVelocityDirty = true;
|
||||
private Vector3 _initVelocity;
|
||||
private Vector3 _rotationAxis = Vector3.up;
|
||||
|
||||
private float _initAngularSpeed;
|
||||
|
||||
private OWRigidbody _satelliteBody;
|
||||
*/
|
||||
}
|
||||
}
|
||||
@ -1,128 +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 : OrbitLine
|
||||
{
|
||||
/*
|
||||
protected override void InitializeLineRenderer()
|
||||
{
|
||||
base.GetComponent<LineRenderer>().positionCount = this._numVerts;
|
||||
}
|
||||
|
||||
protected override void OnValidate()
|
||||
{
|
||||
if (_numVerts < 0 || _numVerts > 4096)
|
||||
{
|
||||
_numVerts = Mathf.Clamp(this._numVerts, 0, 4096);
|
||||
}
|
||||
if (base.GetComponent<LineRenderer>().positionCount != _numVerts)
|
||||
{
|
||||
InitializeLineRenderer();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
_verts = new Vector3[_numVerts];
|
||||
base.enabled = false;
|
||||
}
|
||||
|
||||
public void SetOrbitalParameters(float eccentricity, float semiMajorAxis, float inclination, float longitudeOfAscendingNode, float argumentOfPeriapsis, float trueAnomaly)
|
||||
{
|
||||
_eccentricity = eccentricity;
|
||||
_semiMajorAxis = semiMajorAxis;
|
||||
_inclination = inclination;
|
||||
_longitudeOfAscendingNode = longitudeOfAscendingNode;
|
||||
_argumentOfPeriapsis = argumentOfPeriapsis;
|
||||
_trueAnomaly = trueAnomaly;
|
||||
|
||||
_initialMotion = (_astroObject != null) ? _astroObject.GetComponent<InitialMotion>() : null;
|
||||
_primary = (_astroObject != null) ? _astroObject.GetPrimaryBody() : null;
|
||||
|
||||
_falloffType = _primary.GetGravityVolume().GetFalloffType();
|
||||
if (_initialMotion && _primary)
|
||||
{
|
||||
_vSemiMajorAxis = OrbitalHelper.CartesianStateVectorsFromEccentricAnomaly(0f, _eccentricity, _semiMajorAxis, _inclination, _longitudeOfAscendingNode, _argumentOfPeriapsis, 0, _falloffType).Position;
|
||||
_vSemiMinorAxis = OrbitalHelper.CartesianStateVectorsFromEccentricAnomaly(0f, _eccentricity, _semiMajorAxis, _inclination, _longitudeOfAscendingNode, _argumentOfPeriapsis, 90, _falloffType).Position;
|
||||
_upAxisDir = Vector3.Cross(_vSemiMajorAxis, _vSemiMinorAxis);
|
||||
|
||||
var semiMinorAxis = semiMajorAxis * Mathf.Sqrt(1 - (eccentricity * eccentricity));
|
||||
_fociDistance = Mathf.Sqrt((semiMajorAxis * semiMajorAxis) - (semiMinorAxis * semiMinorAxis));
|
||||
|
||||
base.enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogError($"Couldn't set values for KeplerOrbitLine. InitialMotion = {_initialMotion}, AstroObject = {_primary}");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
Vector3 vector = _primary.transform.position + _vSemiMajorAxis.normalized * _fociDistance;
|
||||
float nu = CalcProjectedAngleToCenter(vector, _vSemiMajorAxis, _vSemiMinorAxis, _astroObject.transform.position);
|
||||
|
||||
for (int i = 0; i < _numVerts; i++)
|
||||
{
|
||||
var angle = Mathf.Rad2Deg * _trueAnomaly + (Mathf.Rad2Deg * nu) - ((float)i / (float)(_numVerts - 1)) * 360f;
|
||||
_verts[i] = OrbitalHelper.CartesianStateVectorsFromTrueAnomaly(0f, _eccentricity, _semiMajorAxis, _inclination, _longitudeOfAscendingNode, _argumentOfPeriapsis, angle, _falloffType).Position;
|
||||
}
|
||||
_lineRenderer.SetPositions(_verts);
|
||||
|
||||
// From EllipticalOrbitLine
|
||||
base.transform.position = vector;
|
||||
base.transform.rotation = Quaternion.AngleAxis(0f, Vector3.up);
|
||||
//base.transform.rotation = Quaternion.AngleAxis(_trueAnomaly + _longitudeOfAscendingNode + _argumentOfPeriapsis, Vector3.up);
|
||||
|
||||
float num2 = DistanceToEllipticalOrbitLine(vector, _vSemiMajorAxis, _vSemiMinorAxis, _upAxisDir, Locator.GetActiveCamera().transform.position);
|
||||
float widthMultiplier = Mathf.Min(num2 * (_lineWidth / 1000f), _maxLineWidth);
|
||||
float num3 = _fade ? (1f - Mathf.Clamp01((num2 - _fadeStartDist) / (_fadeEndDist - _fadeStartDist))) : 1f;
|
||||
_lineRenderer.widthMultiplier = widthMultiplier;
|
||||
_lineRenderer.startColor = new Color(_color.r, _color.g, _color.b, num3 * num3);
|
||||
}
|
||||
|
||||
private float CalcProjectedAngleToCenter(Vector3 foci, Vector3 semiMajorAxis, Vector3 semiMinorAxis, Vector3 point)
|
||||
{
|
||||
Vector3 lhs = point - foci;
|
||||
Vector3 vector = new Vector3(Vector3.Dot(lhs, semiMajorAxis.normalized), 0f, Vector3.Dot(lhs, semiMinorAxis.normalized));
|
||||
vector.x *= semiMinorAxis.magnitude / semiMajorAxis.magnitude;
|
||||
return Mathf.Atan2(vector.z, vector.x);
|
||||
}
|
||||
|
||||
private float DistanceToEllipticalOrbitLine(Vector3 foci, Vector3 semiMajorAxis, Vector3 semiMinorAxis, Vector3 upAxis, Vector3 point)
|
||||
{
|
||||
float f = this.CalcProjectedAngleToCenter(foci, semiMajorAxis, semiMinorAxis, point);
|
||||
Vector3 b = foci + this._vSemiMajorAxis * Mathf.Cos(f) + this._vSemiMinorAxis * Mathf.Sin(f);
|
||||
return Vector3.Distance(point, b);
|
||||
}
|
||||
|
||||
private Vector3 _vSemiMajorAxis;
|
||||
private Vector3 _vSemiMinorAxis;
|
||||
private Vector3 _upAxisDir;
|
||||
private float _fociDistance;
|
||||
|
||||
private float _eccentricity;
|
||||
private float _semiMajorAxis;
|
||||
private float _inclination;
|
||||
private float _longitudeOfAscendingNode;
|
||||
private float _argumentOfPeriapsis;
|
||||
private float _trueAnomaly;
|
||||
|
||||
private Vector3[] _verts;
|
||||
private InitialMotion _initialMotion;
|
||||
private AstroObject _primary;
|
||||
private OrbitalHelper.FalloffType _falloffType;
|
||||
*/
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user