Initial orbiting craft
This commit is contained in:
64
src/Testing/DebugUI.cs
Normal file
64
src/Testing/DebugUI.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using Quadratic.Carto.Craft;
|
||||
using Quadratic.Carto.MathExt;
|
||||
|
||||
namespace Quadratic.Carto.Testing;
|
||||
|
||||
public partial class DebugUI : Control
|
||||
{
|
||||
[Export]
|
||||
Control minimapContainer = null!;
|
||||
|
||||
[Export]
|
||||
Vector2 minimapSize = new Vector2(360, 360);
|
||||
|
||||
[Export]
|
||||
float minimapSizeUnit = 6372;
|
||||
|
||||
[Export]
|
||||
float minimapUnitLength = 90;
|
||||
|
||||
[Export]
|
||||
Polygon2D planetOutline = null!;
|
||||
|
||||
[Export]
|
||||
Control vesselIndicator = null!;
|
||||
|
||||
[Export]
|
||||
Krakensbane krakensbane = null!;
|
||||
|
||||
[Export]
|
||||
Label displayLabel = null!;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
// draw the planet outline
|
||||
var polygon = new List<Vector2>();
|
||||
const int maxPoints = 360;
|
||||
var minimapCenter = minimapSize / 2;
|
||||
for (int i = 0; i < maxPoints; i++)
|
||||
{
|
||||
var angle = (float)i / maxPoints * Mathf.Pi * 2;
|
||||
var point = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * minimapUnitLength + minimapCenter;
|
||||
polygon.Add(point);
|
||||
}
|
||||
planetOutline.Polygon = polygon.ToArray();
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (krakensbane.FocusedVessel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var vesselPosition = krakensbane.GetPositionOf(krakensbane.FocusedVessel);
|
||||
var minimapCenter = minimapSize / 2;
|
||||
var minimapPosition3D = (vesselPosition / minimapSizeUnit).AsSingle().AsGodot() * minimapUnitLength;
|
||||
var minimapPosition2D = new Vector2(-minimapPosition3D.Y, minimapPosition3D.X) + minimapCenter;
|
||||
vesselIndicator.Position = minimapPosition2D;
|
||||
|
||||
displayLabel.Text = $"Vessel position:\n{vesselPosition.X},\n{vesselPosition.Y},\n{vesselPosition.Z}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user