Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/orbits and trajectories #32

Merged
merged 73 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
e705a51
started work on trajectories and planetary motion
Katniss218 Jul 20, 2024
ef573d0
Some more WIP work on reference frames
Katniss218 Jul 21, 2024
6c8e376
more work on reference frames and physics objects (backup, WIP)
Katniss218 Jul 25, 2024
e2d396e
x
Katniss218 Jul 30, 2024
71d7203
x
Katniss218 Aug 2, 2024
42b53b4
game compiles and appears to work now with merged physicsobject and r…
Katniss218 Aug 3, 2024
9f00dc6
xx
Katniss218 Aug 6, 2024
84bde4d
Fixed vessels' position not serializing correctly
Katniss218 Aug 13, 2024
76f9010
scene reference frame can now be moving
Katniss218 Aug 14, 2024
467e23a
preparations to split the active object manager into 3 parts
Katniss218 Aug 15, 2024
8babb2b
Split the scene reference frame from the active object (vessel), and …
Katniss218 Aug 16, 2024
644cde8
Fixed the atmosphere not following the planet correctly. Slight clean…
Katniss218 Aug 16, 2024
90c3e45
Final preparations to actual work on trajectories (finally)
Katniss218 Aug 16, 2024
77cfb20
x
Katniss218 Aug 19, 2024
0159c03
figured out why exactly the non-fixed phys transforms bug out when so…
Katniss218 Aug 20, 2024
928bfef
Made the OnSceneReferenceFrameSwitch method idempotent (allows object…
Katniss218 Aug 21, 2024
67e2fe5
realization about planets - they should never be simulated in scene s…
Katniss218 Aug 21, 2024
eb3fce3
Updated UnityPlus to include newest QuaternionDbl and Vector3Dbl chan…
Katniss218 Aug 22, 2024
a275624
Fixed some major synchronization problems between absolute and scene …
Katniss218 Aug 24, 2024
411040c
more small misc preparatory work
Katniss218 Aug 24, 2024
ffd3796
very minor changes because I don't feel mentally okay for anything more
Katniss218 Aug 25, 2024
82d5057
vessels and celestialbodies now recache the physics transform and ref…
Katniss218 Aug 27, 2024
c786489
(forced to not compile) modifications to the reference frame transfor…
Katniss218 Aug 29, 2024
84b5a02
Fixed most of the issues relating to validity of the cached reference…
Katniss218 Aug 30, 2024
223de72
trying to debug a nasty bug with the free reference frame transform c…
Katniss218 Aug 31, 2024
4462b92
x
Katniss218 Sep 1, 2024
51d5a27
fixed gravity applier being added to a vessel outside the gameplay scene
Katniss218 Sep 1, 2024
a799881
x
Katniss218 Sep 5, 2024
4d346b9
early fix for the as it turns out launch site position being wrong af…
Katniss218 Sep 7, 2024
25187cd
slightly cleaner fix to the pinned reference transform position cache…
Katniss218 Sep 7, 2024
6ec1ea5
more fixes to the reference frame transforms
Katniss218 Sep 8, 2024
8904dd1
cleanup / figuring out a more permanent and proper fix
Katniss218 Sep 8, 2024
803c9f8
fixed the scene reference frame switch bug where the cached values an…
Katniss218 Sep 9, 2024
302ea44
updated unityplus to clean up the player loop interface
Katniss218 Sep 10, 2024
398d704
x
Katniss218 Sep 11, 2024
5ef8c9e
y
Katniss218 Sep 11, 2024
5e3cbe7
Updated player loop utils from unityplus, added a skeleton of the tra…
Katniss218 Sep 12, 2024
ed44419
more work on trajectories and integration with the referenceframetran…
Katniss218 Sep 12, 2024
b95fe0f
removed the trajectory variants of the reference frame transforms, as…
Katniss218 Sep 13, 2024
1c556be
more work on trajectory simulation, added several events to reference…
Katniss218 Sep 14, 2024
bce24b5
More work on specific trajectory implementations
Katniss218 Sep 14, 2024
bd5d07a
more work on trajectory code, kepler orbits, and misc related stuff
Katniss218 Sep 15, 2024
6da52e1
hooked up the trajectories into vessels/celestial bodies. need to fix…
Katniss218 Sep 19, 2024
72ace5f
New approach to the trajectories, which seems like it'll work, but th…
Katniss218 Sep 20, 2024
e978c2d
Figured out that weird stuff is happening inside the simulator, relat…
Katniss218 Sep 20, 2024
113c2ea
Keplerian orbits (bounded) round trip correctly (I think correctly, b…
Katniss218 Sep 29, 2024
fd0da15
x
Katniss218 Sep 30, 2024
67a146d
x
Katniss218 Oct 2, 2024
969c7d7
Found a bug in reference frame code somewhere (related to caching)
Katniss218 Oct 4, 2024
b3ad0e1
Play mode tests work now (Don't use yield return null, it's broken). …
Katniss218 Oct 11, 2024
64ca607
Fixed a lot of the problems with scene reference frame and switching …
Katniss218 Oct 13, 2024
ddceec7
Cleanup
Katniss218 Oct 13, 2024
fa9710d
Cleanup, fixed last commit that stopped the reference frame from foll…
Katniss218 Oct 13, 2024
b0ea188
x
Katniss218 Oct 13, 2024
af2ae60
Fixed kinematic reference transforms returning incorrect position/rot…
Katniss218 Oct 19, 2024
553a75f
x
Katniss218 Oct 19, 2024
b942926
x2
Katniss218 Oct 19, 2024
05674d2
More tinkering with keplerian orbits. The state vector to keplerian s…
Katniss218 Oct 31, 2024
4458898
Fixed keplerian orbits not being calculated correctly when computing …
Katniss218 Nov 2, 2024
ef53a07
Fixed planet pos/vel not being reset if something's colliding with it…
Katniss218 Nov 3, 2024
88410f4
x
Katniss218 Nov 5, 2024
8d275e8
Fixed circular orbits of 0 inclination not round tripping with enough…
Katniss218 Nov 8, 2024
bb7564d
precision testing continues, analyzing why the PQS doesn't cubdivide …
Katniss218 Nov 8, 2024
4e4611b
Fixed retrograde, circular, equatorial keplerian orbits, fixed the re…
Katniss218 Nov 8, 2024
48ad604
tests with a lot of celestial bodies created during gameplay
Katniss218 Nov 8, 2024
4c5f276
More accurate way to position vessels relative to launch site spawner…
Katniss218 Nov 9, 2024
559011e
Added the hybrid reference frame transform, able to simulate itself b…
Katniss218 Nov 14, 2024
2648c6e
Fixed a bug when switching from to absolute frame simulation in the h…
Katniss218 Nov 14, 2024
cac955a
Removed the now unused Shift method in reference frames, implemented …
Katniss218 Nov 15, 2024
f0954fc
Moved the body-centered reference frame getters from celestial body t…
Katniss218 Nov 15, 2024
ea143e2
Vessels disable their parts from updating when too far away from scen…
Katniss218 Nov 17, 2024
ba7d93e
Clarified the API of active vessel/object
Katniss218 Nov 17, 2024
777085b
Fixed an invisible bug with kinematic/hybrid transform in absolute mo…
Katniss218 Nov 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
#
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
[Bb]uilds/
[Bb]in/
[Ll]ogs/
[Uu]ser[Ss]ettings/
Assets/AssetStoreTools*
Executable/
Assets/StreamingAssets/*.meta
Logs/

ProfilerExports/

# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
[Mm]emoryCaptures/
/[Mm]emoryCaptures/

# Recordings can get excessive in size
[Rr]ecordings/
**/[Uu]ser[Ss]ettings/
/[Rr]ecordings/

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
Expand All @@ -34,19 +48,40 @@ ExportedObj/
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D Generated File On Crash Reports
# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.aab
*.unitypackage
*.app

# Crashlytics generated file
crashlytics-build.properties

# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*

# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*

# ======================================
# ======================================
#
#
# HSP-specific entries:
#

# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*
HumanSpaceProgram/log.txt
[Bb]in/
18 changes: 1 addition & 17 deletions HumanSpaceProgram/Assembly-CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,7 @@
<Analyzer Include="C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Visual Studio Tools for Unity\Analyzers\Microsoft.Unity.Analyzers.dll" />
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\HSP.Vanilla.UI.Components\UITextReadout_Velocity.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\UIControlSetupWindow.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\ControlSetupControlGroupUI.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\UITextReadout_Altitude.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\UIPartWindow.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\ControlSetupControlUI.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\ControlSetupWindowComponentUI.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\UISequenceElement.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\UIPartWindowComponent.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\UISequenceAction.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\UISequencerPanel.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\SequencerPanelFactory.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\ControlSetupControlConnectionUI.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\UINavball.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\NavballRenderTextureManager.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\UITextReadout_Acceleration.cs" />
<Compile Include="Assets\HSP.Vanilla.UI.Components\UIIResourceContainer.cs" />
<Compile Include="Assets\ReferenceFrameTransformUtils.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Assets\_TextMesh Pro\Shaders\TMPro.cginc" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ Shader "Hidden/Atmosphere"
float2 toSun = raySphere(inScatterPoint, dirToSun, _Center, _MaxRadius);
float lengthToSun = toSun.y;

/// terminator blocking the rays, version 1 (crude, sharp)

//float2 hitSurface = raySphere(inScatterPoint, dirToSun, _Center, _MinRadius);
//lengthToSun = min(hitSurface.x + hitSurface.y, lengthToSun);
//if (hitSurface.x != maxFloat) // this can be done to black out the side behind the sun.
Expand All @@ -129,7 +131,9 @@ Shader "Hidden/Atmosphere"
float sunRayOpticalDepth = opticalDepth(inScatterPoint, dirToSun, lengthToSun); // average density of the ray from the point to the edge in the direction towards the sun.
viewRayOpticalDepth = opticalDepth(inScatterPoint, -rayDir, stepSize * i); // * i to get the entire ray up to the current point.

//if (i != _InScatteringPointCount - 1) // terminator and blacking out the back side, different way to do it.
/// terminator blocking the rays, version 2 (softer)

//if (i != _InScatteringPointCount - 1)
//{
// float2 hitSurface = raySphere(inScatterPoint, dirToSun, _Center, _MinRadius);
// if (hitSurface.x != maxFloat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,19 @@ public Shader AtmosphereShader
CommandBuffer _cmdAtmospheres;
CommandBuffer _cmdComposition;

Vector3 _center = Vector3.zero;
public static CelestialBody Body;

[SerializeField]
new public Light light { get; set; }

public float Height { get; set; } = 140_000;

[SerializeField]
RenderTexture _rt;

public Func<RenderTexture> ColorRenderTextureGetter { get; set; }
public Func<RenderTexture> DepthRenderTextureGetter { get; set; }

void OnReferenceFrameSwitch( SceneReferenceFrameManager.ReferenceFrameSwitchData data )
{
Vector3Dbl oldAirfPos = data.OldFrame.TransformPosition( _center );
_center = (Vector3)data.NewFrame.InverseTransformPosition( oldAirfPos );
}

void Awake()
{
_camera = this.GetComponent<Camera>();
Expand All @@ -55,8 +52,6 @@ void Awake()
{
name = "HSP - Atmospheres - Composition"
};

SceneReferenceFrameManager.OnAfterReferenceFrameSwitch += OnReferenceFrameSwitch;
}

void OnEnable()
Expand All @@ -70,8 +65,6 @@ void OnEnable()

void OnDestroy()
{
SceneReferenceFrameManager.OnAfterReferenceFrameSwitch -= OnReferenceFrameSwitch;

if( _rt != null )
RenderTexture.ReleaseTemporary( _rt );

Expand All @@ -88,20 +81,22 @@ void OnPreRender()
{
if( instance._atmosphereMaterial == null )
return;
if( Body == null )
return;

this._rt = RenderTexture.GetTemporary( Screen.width, Screen.height, 0, RenderTextureFormat.ARGB32 );

// The `_Texture` property name gets overriden by something else... Unity... >:{
_atmosphereMaterial.SetTexture( Shader.PropertyToID( "_texgsfs" ), ColorRenderTextureGetter.Invoke() );
_atmosphereMaterial.SetTexture( Shader.PropertyToID( "_DepthBuffer" ), DepthRenderTextureGetter.Invoke(), RenderTextureSubElement.Depth );

_atmosphereMaterial.SetVector( Shader.PropertyToID( "_Center" ), _center );
_atmosphereMaterial.SetVector( Shader.PropertyToID( "_Center" ), Body.ReferenceFrameTransform.Position );
_atmosphereMaterial.SetVector( Shader.PropertyToID( "_SunDirection" ), -light.transform.forward );
_atmosphereMaterial.SetVector( Shader.PropertyToID( "_ScatteringWavelengths" ), new Vector3( 675, 530, 400 ) );
_atmosphereMaterial.SetFloat( Shader.PropertyToID( "_ScatteringStrength" ), 128 );
_atmosphereMaterial.SetFloat( Shader.PropertyToID( "_TerminatorFalloff" ), 32 );
_atmosphereMaterial.SetFloat( Shader.PropertyToID( "_MinRadius" ), 6371000f );
_atmosphereMaterial.SetFloat( Shader.PropertyToID( "_MaxRadius" ), 6500000f );
_atmosphereMaterial.SetFloat( Shader.PropertyToID( "_MinRadius" ), (float)Body.Radius );
_atmosphereMaterial.SetFloat( Shader.PropertyToID( "_MaxRadius" ), (float)(Body.Radius + Height) );
_atmosphereMaterial.SetFloat( Shader.PropertyToID( "_InScatteringPointCount" ), 16 );
_atmosphereMaterial.SetFloat( Shader.PropertyToID( "_OpticalDepthPointCount" ), 8 );
_atmosphereMaterial.SetFloat( Shader.PropertyToID( "_DensityFalloffPower" ), 13.7f );
Expand Down
67 changes: 43 additions & 24 deletions HumanSpaceProgram/Assets/HSP.CelestialBodies/CelestialBody.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using HSP.ReferenceFrames;
using HSP.Time;
using System;
using UnityEngine;
using UnityPlus.Serialization;

namespace HSP.CelestialBodies
{
[RequireComponent( typeof( ReferenceFrameTransform ) )]
public class CelestialBody : MonoBehaviour
public static class HSPEvent_AFTER_CELESTIAL_BODY_CREATED
{
/// <summary>
/// Gets the current global position of the celestial body.
/// </summary>
public Vector3Dbl AIRFPosition { get => this._rootTransform.AIRFPosition; set => this._rootTransform.AIRFPosition = value; }
/// <summary>
/// Gets the current global rotation of the celestial body.
/// </summary>
public QuaternionDbl AIRFRotation { get => this._rootTransform.AIRFRotation; set => this._rootTransform.AIRFRotation = value; }
public const string ID = HSPEvent.NAMESPACE_HSP + ".celestial_body_created.after";
}

public static class HSPEvent_AFTER_CELESTIAL_BODY_DESTROYED
{
public const string ID = HSPEvent.NAMESPACE_HSP + ".celestial_body_destroyed.after";
}

public class CelestialBody : MonoBehaviour
{
public string _id;
/// <summary>
/// Gets the id of the celestial body.
Expand All @@ -26,7 +27,8 @@ public string ID
get => _id;
set
{
if( value == null ) throw new ArgumentNullException( "value", "Can't assign a null ID." );
if( value == null )
throw new ArgumentNullException( "value", "Can't assign a null ID." );

if( _id != null )
CelestialBodyManager.Unregister( _id );
Expand All @@ -39,26 +41,52 @@ public string ID
/// Gets or sets the display name of the celestial body.
/// </summary>
public string DisplayName { get; set; }

/// <summary>
/// Gets the mass of the celestial body.
/// </summary>
public double Mass { get; internal set; }
public double Mass { get; internal set; } // TODO - add setters that fire events.

/// <summary>
/// Gets the radius of the celestial body.
/// </summary>
public double Radius { get; internal set; }

ReferenceFrameTransform _rootTransform;
IPhysicsTransform _physicsTransform;
public IPhysicsTransform PhysicsTransform
{
get
{
if( _physicsTransform.IsUnityNull() )
_physicsTransform = this.GetComponent<IPhysicsTransform>();
return _physicsTransform;
}
}

void Awake()
IReferenceFrameTransform _referenceFrameTransform;
public IReferenceFrameTransform ReferenceFrameTransform
{
_rootTransform = this.GetComponent<ReferenceFrameTransform>();
get
{
if( _referenceFrameTransform.IsUnityNull() )
_referenceFrameTransform = this.GetComponent<IReferenceFrameTransform>();
return _referenceFrameTransform;
}
}

void Start()
{
if( this.ID == null )
Debug.LogError( $"Celestial body '{this.gameObject.name}' has not been assigned an ID." );
//this.gameObject.SetLayer( (int)Layer.CELESTIAL_BODY, true );

HSPEvent.EventManager.TryInvoke( HSPEvent_AFTER_CELESTIAL_BODY_CREATED.ID, this );
//this.gameObject.SetLayer( (int)Layer.CELESTIAL_BODY, true );
}

private void OnDestroy()
{
HSPEvent.EventManager.TryInvoke( HSPEvent_AFTER_CELESTIAL_BODY_DESTROYED.ID, this );
}

void OnDisable()
Expand All @@ -76,15 +104,6 @@ void OnDisable()
}
}

/// <summary>
/// Constructs the reference frame centered on this body, with axes aligned with the AIRF frame.
/// </summary>
public IReferenceFrame CenteredReferenceFrame => new CenteredReferenceFrame( this.AIRFPosition );

/// <summary>
/// Constructs the reference frame centered on this body, with axes aligned with the body (i.e. local body space).
/// </summary>
public IReferenceFrame OrientedReferenceFrame => new OrientedReferenceFrame( this.AIRFPosition, this.AIRFRotation );

[MapsInheritingFrom( typeof( CelestialBody ) )]
public static SerializationMapping CelestialBodyMapping()
Expand Down
Loading