XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
namespace XFEEDToolBox.Core.Galaxy;

[Flags]
public enum GalaxyMouseButtons { None=0, Left=1, Right=2 }
public enum GalaxyMouseGesture { None, Orbit, Crane, Translate }
public readonly record struct GalaxyMouseMotion(double Yaw,double Pitch,double Right,double Forward,double Vertical);

/// <summary>Axes from the original galaxymapcontrols chord graph. Sensitivity is a tool calibration.</summary>
public static class GalaxyMouseControls
{
    public static GalaxyMouseGesture Gesture(GalaxyMouseButtons buttons)=>(buttons&(GalaxyMouseButtons.Left|GalaxyMouseButtons.Right)) switch
    {
        GalaxyMouseButtons.Left=>GalaxyMouseGesture.Orbit,
        GalaxyMouseButtons.Right=>GalaxyMouseGesture.Crane,
        GalaxyMouseButtons.Left|GalaxyMouseButtons.Right=>GalaxyMouseGesture.Translate,
        _=>GalaxyMouseGesture.None
    };

    public static GalaxyMouseMotion Motion(GalaxyMouseButtons buttons,double dx,double dy,double worldPerPixel,double angularPerPixel=.006,bool reverseCrane=false)
    {
        if(!double.IsFinite(dx)||!double.IsFinite(dy)||!double.IsFinite(worldPerPixel)||!double.IsFinite(angularPerPixel)||worldPerPixel<=0||angularPerPixel<0)
            throw new ArgumentException("星图鼠标输入无效。");
        // The graph proves raw MouseYAxis+ -> Galactic Y+. Its physical sign
        // relative to screen dy remains a live calibration; retain reversal.
        return Gesture(buttons) switch
        {
            GalaxyMouseGesture.Orbit=>new(dx*angularPerPixel,dy*angularPerPixel,0,0,0),
            GalaxyMouseGesture.Crane=>new(dx*angularPerPixel,0,0,0,dy*worldPerPixel*(reverseCrane?-1:1)),
            GalaxyMouseGesture.Translate=>new(0,0,-dx*worldPerPixel,dy*worldPerPixel,0),
            _=>default
        };
    }
}