diff --git a/init.lua b/init.lua index 6e0218f..e5c9c25 100644 --- a/init.lua +++ b/init.lua @@ -1,7 +1,9 @@ -- ===================================================================== --- lib-core.camera v0.2.0 — 2D Camera State + Free-Pan + Bounds-Clamping +-- lib-core.camera v0.3.0 — 2D Camera State + Free-Pan + Bounds-Clamping + Screen-Unproject -- See: meta/docs/superpowers/specs/2026-05-13-p3-5-camera-free-pan-design.md -- +-- v0.3.0 additions (additiv über v0.2.0): +-- - screen_to_world(sx, sy) — unproject screen-coord to world-coord -- v0.2.0 additions (additiv über v0.1.0): -- - Pan-API (keys / edge / drag, additiv, per-source toggle-bar) -- - Bounds-Clamping (always-on once set; clear_bounds to disable) @@ -232,6 +234,21 @@ function M.update(dt) end end +-- v0.3.0 NEW — Coordinate Unproject (Screen → World) + +function M.screen_to_world(sx, sy) + if type(sx) ~= "number" or type(sy) ~= "number" then + error("camera.screen_to_world: sx and sy must be numbers") + end + local w, h = engine.window.size() + -- Inverse of Raylib 2D camera transform (origin = center, no rotation): + -- screen.x = (world.x - target.x) * zoom + w/2 + -- → world.x = (screen.x - w/2) / zoom + target.x + local wx = (sx - w / 2) / zoom_v + target_x + local wy = (sy - h / 2) / zoom_v + target_y + return wx, wy +end + -- DEPRECATED-MVP: forward-compat stubs (siehe Spec §7): -- DEPRECATED-MVP: function M.follow(entity) -- lib-core.actor slice -- DEPRECATED-MVP: function M.lerp_to(target, dt) -- smooth-follow slice diff --git a/manifest.lib b/manifest.lib index 05b4914..80d782c 100644 --- a/manifest.lib +++ b/manifest.lib @@ -1 +1 @@ -{"id":"lib-core.camera","version":"0.2.0","api_min":"0.1","deps":[{"id":"lib-core.input","version":"0.3.0"}]} \ No newline at end of file +{"id":"lib-core.camera","version":"0.3.0","api_min":"0.1","deps":[{"id":"lib-core.input","version":"0.3.0"}]} \ No newline at end of file