diff --git a/scenes/Main.tscn b/scenes/Main.tscn index 990a849..a269a98 100644 --- a/scenes/Main.tscn +++ b/scenes/Main.tscn @@ -1,19 +1,15 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=3 format=2] -[ext_resource path="res://scenes/Train.tscn" type="PackedScene" id=1] -[ext_resource path="res://scenes/Railway.tscn" type="PackedScene" id=2] [ext_resource path="res://scenes/OrbitCamera.tscn" type="PackedScene" id=3] +[ext_resource path="res://scenes/OrbitSystem.tscn" type="PackedScene" id=4] [node name="Main" type="Node2D"] [node name="DirectionalLight" type="DirectionalLight" parent="."] transform = Transform( 0.515898, 0.606099, -0.605386, -0.393123, 0.795389, 0.461314, 0.76112, -2.26831e-08, 0.648611, 0, 0, 0 ) +visible = false -[node name="OrbitCamera" parent="." instance=ExtResource( 3 )] +[node name="Camera" parent="." instance=ExtResource( 3 )] _speed = 0.5 -[node name="Railway" parent="." instance=ExtResource( 2 )] - -[node name="Train" parent="." instance=ExtResource( 1 )] -_speed = 5.0 -_railwayPath = NodePath("../Railway") +[node name="Orbit System" parent="." instance=ExtResource( 4 )] diff --git a/scripts/orbits/Orbit.cs b/scripts/orbits/Orbit.cs new file mode 100644 index 0000000..0aca13e --- /dev/null +++ b/scripts/orbits/Orbit.cs @@ -0,0 +1,12 @@ +using Godot; +using System; + +public class Orbit +{ + public Orbit(PointMass a, PointMass b) + { + + } + + // ellipse +} diff --git a/scripts/orbits/OrbitSystem.cs b/scripts/orbits/OrbitSystem.cs index 358ad53..12e2531 100644 --- a/scripts/orbits/OrbitSystem.cs +++ b/scripts/orbits/OrbitSystem.cs @@ -26,7 +26,9 @@ public class OrbitSystem : Node, IMassive, ILocation public float Mass { get; } = 1; - private ImmediateGeometry _orbit; + private Orbit _orbit; + + private ImmediateGeometry _orbitGeometry; public override void _Ready() { @@ -39,35 +41,40 @@ public class OrbitSystem : Node, IMassive, ILocation DrawOrbit(); } + private void InitOrbit() + { + + } + private void DrawOrbit() { int steps = 100; - _orbit.Clear(); - _orbit.Begin(Mesh.PrimitiveType.LineLoop); - _orbit.SetColor(new Color(1, 0, 0)); + _orbitGeometry.Clear(); + _orbitGeometry.Begin(Mesh.PrimitiveType.LineLoop); + _orbitGeometry.SetColor(new Color(1, 0, 0)); for (int i = 0; i < steps; i++) { float t = i / (float)steps; float a = t * Mathf.Tau; - _orbit.AddVertex(new Vector3 + _orbitGeometry.AddVertex(new Vector3 { x = Mathf.Sin(a), z = Mathf.Cos(a) }); } - _orbit.End(); + _orbitGeometry.End(); } private void InitGeometry() { - _orbit = new ImmediateGeometry(); + _orbitGeometry = new ImmediateGeometry(); var m = new SpatialMaterial(); m.VertexColorUseAsAlbedo = true; m.FlagsUnshaded = true; - _orbit.MaterialOverride = m; - AddChild(_orbit); + _orbitGeometry.MaterialOverride = m; + AddChild(_orbitGeometry); } private void InitPointMasses() diff --git a/scripts/orbits/Planet.cs b/scripts/orbits/Planet.cs index c93a33a..877455f 100644 --- a/scripts/orbits/Planet.cs +++ b/scripts/orbits/Planet.cs @@ -1,7 +1,7 @@ using Godot; using System; -public class Planet : Node +public class Planet : Node, IMassive { [Export] public float Mass { get; set; } diff --git a/scripts/orbits/PointMass.cs b/scripts/orbits/PointMass.cs index bb277c1..bbeaa14 100644 --- a/scripts/orbits/PointMass.cs +++ b/scripts/orbits/PointMass.cs @@ -1,6 +1,6 @@ using Godot; -struct PointMass : IMassive, ILocation +public struct PointMass : IMassive, ILocation { public float Mass => _massive == null ? _mass : _massive.Mass; public Vector3 Position => _spatial.Translation; diff --git a/scripts/orbits/math/Double2.cs b/scripts/orbits/math/Double2.cs new file mode 100644 index 0000000..942f746 --- /dev/null +++ b/scripts/orbits/math/Double2.cs @@ -0,0 +1,8 @@ +using Godot; +using System; + +public struct Double2 +{ + public double x; + public double y; +} \ No newline at end of file diff --git a/scripts/orbits/math/Ellipse.cs b/scripts/orbits/math/Ellipse.cs new file mode 100644 index 0000000..64751e7 --- /dev/null +++ b/scripts/orbits/math/Ellipse.cs @@ -0,0 +1,34 @@ +using Godot; +using System; + +public struct Ellipse +{ + public double a { get => SemiMajorAxis; set => SemiMajorAxis = value; } + public double SemiMajorAxis { get; set; } + + public double e { get => Eccentricity; set => Eccentricity = value; } + public double Eccentricity { get; set; } + + public double b => SemiMajorAxis; + public double SemiMinorAxis => Math.Sqrt(Apisides.max * Apisides.min); + + private Apisides Apisides => new Apisides(a, e); + + public Ellipse(double a = 1, double e = 0) + { + SemiMajorAxis = a; + Eccentricity = e; + } +} + +public struct Apisides +{ + public readonly double min; + public readonly double max; + + public Apisides(double a, double e) + { + min = a * (1 - e); + max = a * (1 + e); + } +} \ No newline at end of file