extract IOrbit and IOrbitExtensions
This commit is contained in:
parent
bed71f2c4c
commit
5ad70b3f9c
|
@ -0,0 +1,7 @@
|
|||
using Vim.Math3d;
|
||||
|
||||
public interface IOrbit
|
||||
{
|
||||
DVector3 GetPosition(double t);
|
||||
IEllipse Ellipse { get; set; }
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue