29 lines
671 B
C#
29 lines
671 B
C#
|
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();
|
||
|
}
|
||
|
}
|