Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

test(map): the no-sky check accounts for the top-bar frustum shift (fix round 1, item 9 / review M5)

eyalgolanc539924a1815
diff --git a/unity/Assets/Scripts/Map/CameraRig.cs b/unity/Assets/Scripts/Map/CameraRig.cs
index 3d7ee771a..48e66dd50 100644
--- a/unity/Assets/Scripts/Map/CameraRig.cs
+++ b/unity/Assets/Scripts/Map/CameraRig.cs
@@ -14,6 +14,9 @@ namespace Statecraft.Game.Map
/// <summary>Share of the screen height (0..1) the UI covers at the top. The view is shifted so LookAt sits in the
/// middle of the map area below it (an off-centre frustum: picking rays and WorldToScreenPoint follow it).</summary>
public float TopInset;
+ /// <summary>The largest inset the projection applies (TopInset is clamped to it); at this pitch and FOV the top of
+ /// the view still looks down, so the sky never shows (MapSceneTests.TheCameraClearsToTheSeaColour).</summary>
+ public const float MaxTopInset = 0.5f;
DepthOfField _dof;
/// <summary>The global post-processing volume Init creates. Its runtime VolumeProfile must be owned by the caller
@@ -54,7 +57,7 @@ namespace Statecraft.Game.Map
if (TopInset <= 0f) return;
// NDC y = (m11 y + m12 z) / -z, so m12 = s moves every point down by s: the centre of the area below the bar
// (NDC y from -1 to 1 - 2 TopInset) is at -TopInset.
- var p = cam.projectionMatrix; p[1, 2] = Mathf.Clamp(TopInset, 0f, 0.5f); cam.projectionMatrix = p;
+ var p = cam.projectionMatrix; p[1, 2] = Mathf.Clamp(TopInset, 0f, MaxTopInset); cam.projectionMatrix = p;
}
}
}
diff --git a/unity/Assets/Tests/EditMode/SettlementTests.cs b/unity/Assets/Tests/EditMode/SettlementTests.cs
index 0dc414c4b..15ed61f3b 100644
--- a/unity/Assets/Tests/EditMode/SettlementTests.cs
+++ b/unity/Assets/Tests/EditMode/SettlementTests.cs
@@ -169,8 +169,14 @@ public class MapSceneTests
var cam = Camera.main;
Assert.AreEqual(CameraClearFlags.SolidColor, cam.clearFlags);
Assert.AreEqual(MapBuilder.BiomeColours["sea"], cam.backgroundColor);
- Assert.Less(CameraRig.Pitch - CameraRig.Fov / 2, 90f);
- Assert.Greater(CameraRig.Pitch - CameraRig.Fov / 2, 0f, "the top of the view looks down: no sky to show");
+ // Fix round 1 (review M5): the top-bar inset shifts the frustum up, so check the worst case the rig allows: the
+ // top ray rises to atan((1 + inset) tan(Fov/2)) above the axis. Analytically, and on the camera's own rays.
+ var worst = Mathf.Rad2Deg * Mathf.Atan((1 + CameraRig.MaxTopInset) * Mathf.Tan(Mathf.Deg2Rad * CameraRig.Fov / 2));
+ Assert.Greater(CameraRig.Pitch - worst, 0f, "the top of the view looks down at the largest inset: no sky to show");
+ var rig = cam.GetComponent<CameraRig>();
+ rig.TopInset = 1f; rig.Apply(); // clamped to MaxTopInset
+ foreach (var x in new[] { 0f, 0.5f, 1f })
+ Assert.Less(cam.ViewportPointToRay(new Vector3(x, 1f, 0)).direction.y, 0f, $"top edge at x={x} looks down");
}
/// <summary>Playtest 1, item 3: with the top bar covering the top <c>TopInset</c> of the screen, the look-at point is