diff --git a/scripts/orbits/IOrbit.cs b/scripts/orbits/IOrbit.cs new file mode 100644 index 0000000..08bd18e --- /dev/null +++ b/scripts/orbits/IOrbit.cs @@ -0,0 +1,7 @@ +using Vim.Math3d; + +public interface IOrbit +{ + DVector3 GetPosition(double t); + IEllipse Ellipse { get; set; } +} \ No newline at end of file diff --git a/scripts/orbits/IOrbitExtensions.cs b/scripts/orbits/IOrbitExtensions.cs new file mode 100644 index 0000000..23e2bd9 --- /dev/null +++ b/scripts/orbits/IOrbitExtensions.cs @@ -0,0 +1,29 @@ +using Godot; + +public static class IOrbitExtensions +{ + public static void Draw(this IOrbit orbit, ImmediateGeometry geo) + { + geo.Clear(); + geo.Begin(Mesh.PrimitiveType.LineLoop); + geo.SetColor(new Color(1, 0, 0)); + + int steps = 100; + var ellipse = orbit.Ellipse; + + for (int i = 0; i < steps; i++) + { + float t = i / (float)steps; + float a = t * Mathf.Tau; + + var v2 = ellipse.Foci[0] + ellipse.GetPosition(a); + + geo.AddVertex(new Godot.Vector3 + { + x = (float)v2.X, + z = (float)v2.Y + }); + } + geo.End(); + } +} \ No newline at end of file