feat:修复部分问题
This commit is contained in:
1 parent
153ea88f4f
commit
5760fb77b0
38 files changed
+2273
-200
No files matched your search
@@ -152,7 +152,34 @@ public class CelestialView : Control
|
||||
}
|
||||
|
||||
public string DeclinationLabel => DeclinationText(SubsolarLatitude);
|
||||
public string CurrentDate => DateForAngle(_orbitDeg);
|
||||
|
||||
/// <summary>定格在二分二至时,日期直接取模型数据里的教材日期,避免近似公式差一两天。</summary>
|
||||
public string CurrentDate
|
||||
{
|
||||
get
|
||||
{
|
||||
if (View == SceneView.Revolution)
|
||||
{
|
||||
var season = NearestSeason(2.5);
|
||||
if (season?.Date != null) return FormatSeasonDate(season.Date);
|
||||
}
|
||||
return DateForAngle(_orbitDeg);
|
||||
}
|
||||
}
|
||||
|
||||
private string FormatSeasonDate(string monthDay)
|
||||
{
|
||||
var parts = monthDay.Split('/');
|
||||
if (parts.Length == 2 && int.TryParse(parts[0], out var m) && int.TryParse(parts[1], out var d)
|
||||
&& m is >= 1 and <= 12 && d is >= 1 and <= 31)
|
||||
{
|
||||
var date = new DateTime(2025, m, d);
|
||||
var chinese = Texts.Language.StartsWith("zh", StringComparison.OrdinalIgnoreCase);
|
||||
return date.ToString(chinese ? "M月d日" : "MMM d", CultureInfo.InvariantCulture);
|
||||
}
|
||||
return monthDay;
|
||||
}
|
||||
|
||||
public event Action? AnglesChanged;
|
||||
/// <summary>缩放目标变化(滚轮、按钮、捏合)。</summary>
|
||||
public event Action<double>? ZoomChanged;
|
||||
@@ -256,8 +283,9 @@ public class CelestialView : Control
|
||||
if (!_dragging) return;
|
||||
|
||||
var dx = p.X - _dragLast.X;
|
||||
var dy = p.Y - _dragLast.Y;
|
||||
_dragLast = p;
|
||||
DragBy(dx, p.Y - _dragLast.Y + (p.Y - _dragLast.Y));
|
||||
DragBy(dx, dy);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
@@ -330,9 +358,13 @@ public class CelestialView : Control
|
||||
if (!_pinching) { BeginPinch(); return; }
|
||||
var pts = _pointers.Values.Take(2).ToArray();
|
||||
var d = Math.Max(8.0, Distance(pts[0], pts[1]));
|
||||
SetZoom(_pinchStartZoom * d / _pinchStartDistance, immediate: true);
|
||||
SetZoom(PinchZoom(_pinchStartZoom, _pinchStartDistance, d), immediate: true);
|
||||
}
|
||||
|
||||
/// <summary>捏合比例换算:两指间距放大多少倍,缩放就放大多少倍(限幅 0.6–6)。</summary>
|
||||
public static double PinchZoom(double startZoom, double startDistance, double currentDistance)
|
||||
=> Math.Clamp(startZoom * Math.Max(8.0, currentDistance) / Math.Max(8.0, startDistance), 0.6, 6.0);
|
||||
|
||||
private static double Distance(Point a, Point b)
|
||||
{
|
||||
var dx = a.X - b.X;
|
||||
@@ -654,11 +686,34 @@ public class CelestialView : Control
|
||||
t => LatLonToUnit(lat, t * 360.0), 144);
|
||||
if (label == null) return;
|
||||
|
||||
var world = Vector3.Transform(LatLonToUnit(lat, 64), planet);
|
||||
var c = Vector3.Transform(world, cam);
|
||||
if (c.Z <= 0.05f) return;
|
||||
var p = new Point(center.X + c.X * radius, center.Y - c.Y * radius);
|
||||
DrawText(ctx, label, p.X + 5, p.Y - 13, 10.5, labelBrush, FontWeight.SemiBold);
|
||||
// 找该纬线上「最靠右且可见」的点作为标签锚点:
|
||||
// 地球自转时标签始终留在可见半球右侧,不会忽隐忽现
|
||||
Vector3 best = default;
|
||||
var bestScore = double.NegativeInfinity;
|
||||
for (var lon = -180; lon < 180; lon += 6)
|
||||
{
|
||||
var world = Vector3.Transform(LatLonToUnit(lat, lon), planet);
|
||||
var c = Vector3.Transform(world, cam);
|
||||
if (c.Z < 0.10f) continue;
|
||||
var score = c.X * 2.0 + c.Z;
|
||||
if (score > bestScore) { bestScore = score; best = c; }
|
||||
}
|
||||
if (double.IsNegativeInfinity(bestScore)) return;
|
||||
var p = new Point(center.X + best.X * radius, center.Y - best.Y * radius);
|
||||
DrawLabelChip(ctx, label, p, InsetMode ? 9.0 : 10.5, labelBrush, toRight: false);
|
||||
}
|
||||
|
||||
/// <summary>带深色底衬的标签:压在明亮的地球上也读得清,且不会被画布边缘裁掉。</summary>
|
||||
private static void DrawLabelChip(DrawingContext ctx, string text, Point anchor,
|
||||
double fontSize, IBrush brush, bool toRight)
|
||||
{
|
||||
var formatted = new FormattedText(text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
|
||||
new Typeface(FontFamily.Default, FontStyle.Normal, FontWeight.SemiBold), fontSize, brush);
|
||||
var x = toRight ? anchor.X + 9 : Math.Max(3, anchor.X - formatted.Width - 9);
|
||||
var y = anchor.Y - formatted.Height - 4;
|
||||
ctx.DrawRectangle(ChipBg, null,
|
||||
new Rect(x - 5, y - 2, formatted.Width + 10, formatted.Height + 5), 4, 4);
|
||||
ctx.DrawText(formatted, new Point(x, y));
|
||||
}
|
||||
|
||||
private void DrawGraticule(DrawingContext ctx, Matrix4x4 cam, Matrix4x4 planet, Point center, double radius)
|
||||
@@ -732,11 +787,12 @@ public class CelestialView : Control
|
||||
{
|
||||
if (light.Z <= 0.02f) return;
|
||||
var p = new Point(center.X + light.X * radius, center.Y - light.Y * radius);
|
||||
ctx.DrawEllipse(SubsolarGlowBrush, null, p, 9, 9);
|
||||
ctx.DrawEllipse(null, SubsolarPen, p, 5, 5);
|
||||
var marker = InsetMode ? 6.5 : 5.0;
|
||||
ctx.DrawEllipse(SubsolarGlowBrush, null, p, marker * 2.5, marker * 2.5);
|
||||
ctx.DrawEllipse(null, SubsolarPen, p, marker, marker);
|
||||
if (withLabel)
|
||||
DrawText(ctx, Texts["directPoint"] + " " + DeclinationText(SubsolarLatitude),
|
||||
p.X + 12, p.Y - 9, 11.5, SubsolarBrush, FontWeight.SemiBold);
|
||||
DrawLabelChip(ctx, Texts["directPoint"] + " " + DeclinationText(SubsolarLatitude),
|
||||
p, 11.5, SubsolarBrush, toRight: p.X < center.X);
|
||||
}
|
||||
|
||||
private void DrawAxis(DrawingContext ctx, Matrix4x4 cam, Matrix4x4 planet, Point center, double radius,
|
||||
@@ -780,7 +836,7 @@ public class CelestialView : Control
|
||||
var cam = CameraMatrix(0, _camElev);
|
||||
|
||||
var theta = Deg2Rad(_orbitDeg);
|
||||
var earthPos = new Vector3((float)(-a * Math.Sin(theta)), 0, (float)(a * Math.Cos(theta)));
|
||||
var earthPos = new Vector3((float)(-a * Math.Sin(theta)), 0, (float)(-a * Math.Cos(theta)));
|
||||
var earthScreen = ToScreen(earthPos, cam, center);
|
||||
var lightWorld = Vector3.Normalize(-earthPos);
|
||||
var lightCam = Vector3.TransformNormal(lightWorld, cam);
|
||||
@@ -864,7 +920,7 @@ public class CelestialView : Control
|
||||
for (var i = 0; i <= 240; i++)
|
||||
{
|
||||
var t = i / 240.0 * Math.PI * 2;
|
||||
var p = new Vector3((float)(-a * Math.Sin(t)), 0, (float)(a * Math.Cos(t)));
|
||||
var p = new Vector3((float)(-a * Math.Sin(t)), 0, (float)(-a * Math.Cos(t)));
|
||||
var c = Vector3.Transform(p, cam);
|
||||
var sp = new Point(center.X + c.X, center.Y - c.Y);
|
||||
if (c.Z < 0)
|
||||
@@ -899,7 +955,7 @@ public class CelestialView : Control
|
||||
foreach (var s in seasons)
|
||||
{
|
||||
var t = Deg2Rad(s.AngleDeg);
|
||||
var pos = new Vector3((float)(-a * Math.Sin(t)), 0, (float)(a * Math.Cos(t)));
|
||||
var pos = new Vector3((float)(-a * Math.Sin(t)), 0, (float)(-a * Math.Cos(t)));
|
||||
var outer = pos * 1.19f;
|
||||
var p = ToScreen(outer, cam, center);
|
||||
ctx.DrawEllipse(SeasonDotBrush, null, ToScreen(pos, cam, center), 2.4, 2.4);
|
||||
@@ -985,6 +1041,7 @@ public class CelestialView : Control
|
||||
private static readonly IBrush AxisBrush = new SolidColorBrush(Color.FromArgb(220, 255, 214, 130));
|
||||
private static readonly IBrush SubsolarBrush = new SolidColorBrush(Color.FromArgb(240, 255, 236, 170));
|
||||
private static readonly IBrush SubsolarGlowBrush = new SolidColorBrush(Color.FromArgb(64, 255, 214, 110));
|
||||
private static readonly IBrush ChipBg = new SolidColorBrush(Color.FromArgb(185, 8, 16, 34));
|
||||
private static readonly IBrush TropicBrush = new SolidColorBrush(Color.FromArgb(240, 255, 196, 120));
|
||||
private static readonly IBrush PolarBrush = new SolidColorBrush(Color.FromArgb(210, 164, 210, 255));
|
||||
private static readonly Pen SubsolarPen = new Pen(new SolidColorBrush(Color.FromArgb(230, 255, 226, 150)), 1.4);
|
||||
|
||||
@@ -45,6 +45,7 @@ public sealed class EarthModelView : UserControl
|
||||
private StackPanel? _seasonPanel;
|
||||
private Border? _lessons;
|
||||
private Border? _closeupHost;
|
||||
private TextBlock? _closeupLabel;
|
||||
private ModelButton? _playButton;
|
||||
private ModelButton? _overheadButton;
|
||||
private ModelButton? _closeupButton;
|
||||
@@ -71,6 +72,8 @@ public sealed class EarthModelView : UserControl
|
||||
_runtime = runtime;
|
||||
_texts = ModelStrings.Load(context.DataDirectory, context.Language);
|
||||
_views = ResolveViews(runtime.Scene);
|
||||
// 自转模型主画布本身就是放大的地球,不需要再来一份特写
|
||||
_showCloseup = IsRevolution;
|
||||
|
||||
Background = new SolidColorBrush(Color.Parse("#05070F"));
|
||||
|
||||
@@ -535,13 +538,14 @@ public sealed class EarthModelView : UserControl
|
||||
});
|
||||
readouts.Children.Add(_cardDirect);
|
||||
readouts.Children.Add(_cardNote);
|
||||
readouts.Children.Add(new TextBlock
|
||||
_closeupLabel = new TextBlock
|
||||
{
|
||||
Text = _texts["closeup"],
|
||||
Foreground = MutedBrush,
|
||||
FontSize = 11,
|
||||
Margin = new Thickness(0, 6, 0, 0)
|
||||
});
|
||||
};
|
||||
readouts.Children.Add(_closeupLabel);
|
||||
readouts.Children.Add(_closeupHost);
|
||||
|
||||
var list = new StackPanel { Spacing = 2 };
|
||||
@@ -675,13 +679,15 @@ public sealed class EarthModelView : UserControl
|
||||
_cardTitle.Text = season != null
|
||||
? _texts[season.Key]
|
||||
: (IsRevolution ? _texts["seasons"] : _texts.Pick(_runtime.Scene.NameI18n, _texts["title"]));
|
||||
_cardDate!.Text = _canvas.CurrentDate + (season?.Date != null ? " · " + season.Date : "");
|
||||
_cardDate!.Text = IsRevolution ? _canvas.CurrentDate : _texts["dayNight"];
|
||||
_cardDirect!.Text = season?.DeclinationDeg.HasValue == true
|
||||
? FormatDeclination(season.DeclinationDeg.Value)
|
||||
: _canvas.DeclinationLabel;
|
||||
_cardNote!.Text = season != null
|
||||
? _texts.Pick(season.TeachingI18n, _texts["orbitTeach"])
|
||||
: _texts["orbitTeach"];
|
||||
_cardNote!.Text = !IsRevolution
|
||||
? _texts["rotationTeach"]
|
||||
: season != null
|
||||
? _texts.Pick(season.TeachingI18n, _texts["orbitTeach"])
|
||||
: _texts["orbitTeach"];
|
||||
|
||||
if (_showCloseup && (double.IsNaN(_lastDeclination) || Math.Abs(_lastDeclination - decl) > 0.04))
|
||||
{
|
||||
@@ -811,6 +817,7 @@ public sealed class EarthModelView : UserControl
|
||||
if (_lessons != null) _lessons.IsVisible = _showLessons;
|
||||
if (_seasonPanel != null) _seasonPanel.IsVisible = IsRevolution;
|
||||
if (_closeupHost != null) _closeupHost.IsVisible = _showCloseup;
|
||||
if (_closeupLabel != null) _closeupLabel.IsVisible = _showCloseup;
|
||||
}
|
||||
|
||||
/// <summary>带悬停过渡的按钮:本地基础色 + 悬停提亮。</summary>
|
||||
|
||||
@@ -106,6 +106,8 @@ internal static class DefaultTexts
|
||||
["sideview"] = "侧视",
|
||||
["zoom"] = "缩放",
|
||||
["orbitTeach"] = "太阳直射点在南北回归线之间往返,形成四季更替。",
|
||||
["rotationTeach"] = "晨昏线把地球分成昼半球与夜半球;自转产生昼夜交替与地方时差。",
|
||||
["dayNight"] = "昼夜交替周期 24 小时",
|
||||
["lat.equator"] = "赤道",
|
||||
["lat.tropicN"] = "北回归线 23.5°N",
|
||||
["lat.tropicS"] = "南回归线 23.5°S",
|
||||
@@ -157,6 +159,8 @@ internal static class DefaultTexts
|
||||
["sideview"] = "Side view",
|
||||
["zoom"] = "Zoom",
|
||||
["orbitTeach"] = "The subsolar point travels between the tropics, producing the seasons.",
|
||||
["rotationTeach"] = "The terminator splits day and night; rotation drives the day–night cycle and local time.",
|
||||
["dayNight"] = "Day–night cycle: 24 h",
|
||||
["lat.equator"] = "Equator",
|
||||
["lat.tropicN"] = "Tropic of Cancer 23.5°N",
|
||||
["lat.tropicS"] = "Tropic of Capricorn 23.5°S",
|
||||
|
||||
@@ -50,6 +50,8 @@ public sealed class OrbitDefinition
|
||||
public double SemiMajorAxis { get; set; } = 4.0;
|
||||
public double Eccentricity { get; set; } = 0.0167;
|
||||
public bool Show { get; set; } = true;
|
||||
/// <summary>节气方位声明:springTopSummerLeft = 上春分 / 左夏至(引擎按此布局绘制轨道)。</summary>
|
||||
public string SeasonLayout { get; set; } = "springTopSummerLeft";
|
||||
public List<SeasonPoint> Seasons { get; set; } = new();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user