extract IOrbit and IOrbitExtensions

This commit is contained in:
ktyl 2022-09-07 00:43:08 +01:00
parent bed71f2c4c
commit 5ad70b3f9c
2 changed files with 36 additions and 0 deletions

7
scripts/orbits/IOrbit.cs Normal file
View File

@ -0,0 +1,7 @@
using Vim.Math3d;
public interface IOrbit
{
DVector3 GetPosition(double t);
IEllipse Ellipse { get; set; }
}

View File

@ -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();
}
}