A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
fix(camera): wheel zoom in and out are inverse (Task 24 review M3)
eyalgolanc0726fbc376f
diff --git a/unity/Assets/Scripts/Map/CameraController.cs b/unity/Assets/Scripts/Map/CameraController.csindex df55c5db5..9431b094a 100644--- a/unity/Assets/Scripts/Map/CameraController.cs+++ b/unity/Assets/Scripts/Map/CameraController.cs@@ -88,7 +88,8 @@ namespace Statecraft.Game.Mapvar zoom = input.OverUi ? 0f : input.Zoom;var drag = input.DragFromUi ? Vector2.zero : input.DragPan;rig.Yaw = Mathf.Repeat(rig.Yaw + input.Orbit * OrbitDegreesPerSecond * dt, 360f);- rig.Distance = Mathf.Clamp(rig.Distance * (1f - zoom * ZoomPerStep), MinDistance, MaxDistance);+ // (1 - step)^zoom: one notch in is exactly ZoomPerStep closer, and n notches out undo n notches in (Task 24 review M3).+ rig.Distance = Mathf.Clamp(rig.Distance * Mathf.Pow(1f - ZoomPerStep, zoom), MinDistance, MaxDistance);var yaw = Quaternion.Euler(0, rig.Yaw, 0);var move = input.Pan * (PanPerSecond * dt) - drag * DragPanPerPixel;var delta = yaw * new Vector3(move.x, 0, move.y) * rig.Distance;diff --git a/unity/Assets/Tests/EditMode/CameraInputTests.cs b/unity/Assets/Tests/EditMode/CameraInputTests.csindex 1bddd97ff..1951307aa 100644--- a/unity/Assets/Tests/EditMode/CameraInputTests.cs+++ b/unity/Assets/Tests/EditMode/CameraInputTests.cs@@ -250,4 +250,26 @@ public class CameraInputTests}finally { Object.DestroyImmediate(go); }}++ /// <summary>Task 24 review M3: zooming in then out by the same notches returns to the same distance.</summary>+ [Test]+ public void ZoomingInThenOutReturnsToTheStart()+ {+ var c = NewController(out var go);+ try+ {+ var rig = go.GetComponent<CameraRig>();+ foreach (var notches in new[] { 1f, 3f, 0.5f })+ {+ rig.Distance = 120000f;+ CameraController.Step(rig, c.Gather(Vector2.zero, Vector2.zero, notches, 0, false, null), 0.016f, Map);+ CameraController.Step(rig, c.Gather(Vector2.zero, Vector2.zero, -notches, 0, false, null), 0.016f, Map);+ Assert.AreEqual(120000f, rig.Distance, 1f, $"{notches} notches in, then out");+ }+ rig.Distance = 120000f;+ CameraController.Step(rig, c.Gather(Vector2.zero, Vector2.zero, -1f, 0, false, null), 0.016f, Map);+ Assert.AreEqual(120000f / 0.9f, rig.Distance, 1f, "one notch out undoes one notch in (10%)");+ }+ finally { Object.DestroyImmediate(go); }+ }}