using XFEEDToolBox.Core.Models; namespace XFEEDToolBox.Core.Galaxy; /// Angles are radians; focus and orbit distance are light years. public readonly record struct GalaxyCameraPose(Coordinates Focus, double Yaw, double Pitch, double Distance); /// /// Explicit application convergence tolerances. The original stop thresholds /// reside in runtime globals and have not been recovered from frozen resources. /// Zero adds no application tolerance; unchanged arithmetic still settles exactly. /// public readonly record struct GalaxyCameraStopThresholds(double Focus, double Angle, double Distance); /// /// Ordinary orbit phase of the original GalaxyMapCamera. These factors apply /// once per update, without multiplying by elapsed time. Cinematic recenter /// transitions have a separate easing path and are not represented here. /// public static class GalaxyOriginalCameraControls { public const string SourceResource = "86ec03fba621526059fc6812faca6f10adcb63cb"; public const string SourceSha256 = "29a90189d0bb238c88d09dcc0f15ff751ea29aa208b1a90894ef3b47f8942e5f"; public const string SourceBinding = "galaxymap/root1490/component9/GalaxyMapCamera/EC6A0092/pool423:14672"; public const double FocusFactor = (double).3f; public const double PitchFactor = (double).2f; public const double YawFactor = (double).2f; public const double DistanceFactor = (double).2f; public const double MinimumDistance = 6; public const double MaximumDistance = 25000; public const double DefaultDistance = 17.75; // 3B40630 multiplies degree metadata by this original float constant. public const float DegreesToRadians = .01745329238474369f; public const double MinimumPitch = (double)(-80f * DegreesToRadians); public const double MaximumPitch = (double)(80f * DegreesToRadians); public const double DefaultPitch = (double)(45f * DegreesToRadians); public const double DefaultYaw = (double)(30f * DegreesToRadians); /// /// Clamp only the input target and settle its floor height when craning is /// inactive. The independently smoothed actual pose is never rounded here. /// public static GalaxyCameraPose PrepareTarget(GalaxyCameraPose target, bool cameraCraning, double craneInput) { Validate(target); return target with { Focus = GalaxyFloorSelector.SettleHeight(target.Focus, cameraCraning, craneInput), Pitch = Math.Clamp(target.Pitch, MinimumPitch, MaximumPitch), Distance = Math.Clamp(target.Distance, MinimumDistance, MaximumDistance) }; } /// /// Advance four independent channels using original 3A2B800: focus/pitch/yaw /// lerp and distance lerp in log2 space. Retains the application's double /// coordinates; this is an algorithm port, not SIMD float bit emulation. /// Yaw is intentionally not wrapped or replaced by a shortest-angle path. /// public static GalaxyCameraPose Smooth(GalaxyCameraPose actual, GalaxyCameraPose target, GalaxyCameraStopThresholds stop = default) { Validate(actual); Validate(target); if (!double.IsFinite(stop.Focus) || !double.IsFinite(stop.Angle) || !double.IsFinite(stop.Distance) || stop.Focus < 0 || stop.Angle < 0 || stop.Distance < 0) throw new ArgumentException("星图相机收敛阈值无效。", nameof(stop)); var x = actual.Focus.X + (target.Focus.X - actual.Focus.X) * FocusFactor; var y = actual.Focus.Y + (target.Focus.Y - actual.Focus.Y) * FocusFactor; var z = actual.Focus.Z + (target.Focus.Z - actual.Focus.Z) * FocusFactor; var focus = new Coordinates(x, y, z); if (focus == actual.Focus || Length(target.Focus.X - x, target.Focus.Y - y, target.Focus.Z - z) < stop.Focus) focus = target.Focus; var distance = actual.Distance * Math.Pow(2, (Math.Log2(target.Distance) - Math.Log2(actual.Distance)) * DistanceFactor); if (distance == actual.Distance || Math.Abs(target.Distance - distance) < stop.Distance) distance = target.Distance; var next = new GalaxyCameraPose(focus, Linear(actual.Yaw, target.Yaw, YawFactor, stop.Angle), Linear(actual.Pitch, target.Pitch, PitchFactor, stop.Angle), distance); Validate(next); return next; } static double Linear(double actual, double target, double factor, double threshold) { var next = actual + (target - actual) * factor; return next == actual || Math.Abs(target - next) < threshold ? target : next; } static double Length(double x, double y, double z) => Math.Sqrt(x * x + y * y + z * z); static void Validate(GalaxyCameraPose pose) { if (pose.Focus is not { IsValid: true } || !double.IsFinite(pose.Yaw) || !double.IsFinite(pose.Pitch) || !double.IsFinite(pose.Distance) || pose.Distance <= 0) throw new ArgumentException("星图相机姿态无效。"); } }