Add layered system viewer and local coordinates
This commit is contained in:
@@ -111,9 +111,9 @@ public sealed class ScenarioLoader
|
||||
Id = $"node-{++nodeIdCounter}",
|
||||
SystemId = system.Definition.Id,
|
||||
Position = new Vector3(
|
||||
system.Position.X + (MathF.Cos(node.Angle) * node.RadiusOffset),
|
||||
system.Position.Y + balance.YPlane,
|
||||
system.Position.Z + (MathF.Sin(node.Angle) * node.RadiusOffset)),
|
||||
MathF.Cos(node.Angle) * node.RadiusOffset,
|
||||
balance.YPlane,
|
||||
MathF.Sin(node.Angle) * node.RadiusOffset),
|
||||
SourceKind = node.SourceKind,
|
||||
ItemId = node.ItemId,
|
||||
OreRemaining = node.OreAmount,
|
||||
@@ -149,7 +149,7 @@ public sealed class ScenarioLoader
|
||||
|
||||
var patrolRoutes = scenario.PatrolRoutes.ToDictionary(
|
||||
(route) => route.SystemId,
|
||||
(route) => route.Points.Select(ToVector).ToList(),
|
||||
(route) => route.Points.Select((point) => NormalizeScenarioPoint(systemsById[route.SystemId], point)).ToList(),
|
||||
StringComparer.Ordinal);
|
||||
|
||||
var shipsRuntime = new List<ShipRuntime>();
|
||||
@@ -164,7 +164,7 @@ public sealed class ScenarioLoader
|
||||
for (var index = 0; index < formation.Count; index += 1)
|
||||
{
|
||||
var offset = new Vector3((index % 3) * 18f, balance.YPlane, (index / 3) * 18f);
|
||||
var position = Add(ToVector(formation.Center), offset);
|
||||
var position = Add(NormalizeScenarioPoint(systemsById[formation.SystemId], formation.Center), offset);
|
||||
shipsRuntime.Add(new ShipRuntime
|
||||
{
|
||||
Id = $"ship-{++shipIdCounter}",
|
||||
@@ -832,7 +832,7 @@ public sealed class ScenarioLoader
|
||||
{
|
||||
if (plan.Position is { Length: 3 })
|
||||
{
|
||||
return ToVector(plan.Position);
|
||||
return NormalizeScenarioPoint(system, plan.Position);
|
||||
}
|
||||
|
||||
if (plan.PlanetIndex is int planetIndex && planetIndex >= 0 && planetIndex < system.Definition.Planets.Count)
|
||||
@@ -840,15 +840,28 @@ public sealed class ScenarioLoader
|
||||
var planet = system.Definition.Planets[planetIndex];
|
||||
var side = plan.LagrangeSide ?? 1;
|
||||
return new Vector3(
|
||||
system.Position.X + planet.OrbitRadius + (side * 72f),
|
||||
system.Position.Y + balance.YPlane,
|
||||
system.Position.Z + ((planetIndex + 1) * 42f * side));
|
||||
planet.OrbitRadius + (side * 72f),
|
||||
balance.YPlane,
|
||||
(planetIndex + 1) * 42f * side);
|
||||
}
|
||||
|
||||
return new Vector3(system.Position.X + 180f, system.Position.Y + balance.YPlane, system.Position.Z);
|
||||
return new Vector3(180f, balance.YPlane, 0f);
|
||||
}
|
||||
|
||||
private static Vector3 ToVector(float[] values) => new(values[0], values[1], values[2]);
|
||||
|
||||
private static Vector3 NormalizeScenarioPoint(SystemRuntime system, float[] values)
|
||||
{
|
||||
var raw = ToVector(values);
|
||||
var relativeToSystem = new Vector3(
|
||||
raw.X - system.Position.X,
|
||||
raw.Y - system.Position.Y,
|
||||
raw.Z - system.Position.Z);
|
||||
|
||||
return relativeToSystem.LengthSquared() < raw.LengthSquared()
|
||||
? relativeToSystem
|
||||
: raw;
|
||||
}
|
||||
|
||||
private static Vector3 Add(Vector3 left, Vector3 right) => new(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user