using XFEEDToolBox.Core.Navigation;
namespace XFEEDToolBox.Core.Rendering;
/// <summary>Removes the native resource's changing reference rotation from presentation only.</summary>
public sealed class LocalSystemViewLock
{
private long system;
private ulong anchor;
private Basis? original;
public LocalSystemOrientation Orientation{get;private set;}=LocalSystemOrientation.Identity;
public bool Locked=>original is not null;
public bool Observe(CurrentSystemSnapshot snapshot)
{
if(system!=snapshot.SystemAddress){system=snapshot.SystemAddress;anchor=0;original=null;Orientation=LocalSystemOrientation.Identity;}
var orbit=snapshot.Orbits.Where(value=>value.Renderable)
.Where(value=>anchor==0||value.ChildWorldAddress==anchor)
.OrderByDescending(value=>value.SemiMajorAxisMetres).ThenBy(value=>value.ChildWorldAddress).FirstOrDefault();
if(orbit is null)return original is null;
var basis=new Basis(orbit.PeriapsisDirection!.Value,Vector3d.Cross(orbit.TransverseDirection!.Value,orbit.PeriapsisDirection.Value),orbit.TransverseDirection.Value);
if(original is null){anchor=orbit.ChildWorldAddress;original=basis;}
Orientation=new(original.Value.X,original.Value.Y,original.Value.Z,basis.X,basis.Y,basis.Z);
return true;
}
private readonly record struct Basis(Vector3d X,Vector3d Y,Vector3d Z);
}
public readonly record struct LocalSystemOrientation(Vector3d FixedX,Vector3d FixedY,Vector3d FixedZ,Vector3d CurrentX,Vector3d CurrentY,Vector3d CurrentZ)
{
public static LocalSystemOrientation Identity=>new(new(1,0,0),new(0,1,0),new(0,0,1),new(1,0,0),new(0,1,0),new(0,0,1));
public Vector3d Rotate(Vector3d value)=>FixedX*Vector3d.Dot(value,CurrentX)+FixedY*Vector3d.Dot(value,CurrentY)+FixedZ*Vector3d.Dot(value,CurrentZ);
}
using XFEEDToolBox.Core.Navigation;
namespace XFEEDToolBox.Core.Rendering;
/// <summary>Removes the native resource's changing reference rotation from presentation only.</summary>
public sealed class LocalSystemViewLock
{
private long system;
private ulong anchor;
private Basis? original;
public LocalSystemOrientation Orientation{get;private set;}=LocalSystemOrientation.Identity;
public bool Locked=>original is not null;
public bool Observe(CurrentSystemSnapshot snapshot)
{
if(system!=snapshot.SystemAddress){system=snapshot.SystemAddress;anchor=0;original=null;Orientation=LocalSystemOrientation.Identity;}
var orbit=snapshot.Orbits.Where(value=>value.Renderable)
.Where(value=>anchor==0||value.ChildWorldAddress==anchor)
.OrderByDescending(value=>value.SemiMajorAxisMetres).ThenBy(value=>value.ChildWorldAddress).FirstOrDefault();
if(orbit is null)return original is null;
var basis=new Basis(orbit.PeriapsisDirection!.Value,Vector3d.Cross(orbit.TransverseDirection!.Value,orbit.PeriapsisDirection.Value),orbit.TransverseDirection.Value);
if(original is null){anchor=orbit.ChildWorldAddress;original=basis;}
Orientation=new(original.Value.X,original.Value.Y,original.Value.Z,basis.X,basis.Y,basis.Z);
return true;
}
private readonly record struct Basis(Vector3d X,Vector3d Y,Vector3d Z);
}
public readonly record struct LocalSystemOrientation(Vector3d FixedX,Vector3d FixedY,Vector3d FixedZ,Vector3d CurrentX,Vector3d CurrentY,Vector3d CurrentZ)
{
public static LocalSystemOrientation Identity=>new(new(1,0,0),new(0,1,0),new(0,0,1),new(1,0,0),new(0,1,0),new(0,0,1));
public Vector3d Rotate(Vector3d value)=>FixedX*Vector3d.Dot(value,CurrentX)+FixedY*Vector3d.Dot(value,CurrentY)+FixedZ*Vector3d.Dot(value,CurrentZ);
}