feat(camera): v0.3.0 — add screen_to_world(sx, sy) unproject (P.3.6)

This commit is contained in:
Axel Meyer
2026-05-14 14:26:50 +02:00
parent 0e730e7c45
commit 5028877566
2 changed files with 19 additions and 2 deletions

View File

@@ -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

View File

@@ -1 +1 @@
{"id":"lib-core.camera","version":"0.2.0","api_min":"0.1","deps":[{"id":"lib-core.input","version":"0.3.0"}]}
{"id":"lib-core.camera","version":"0.3.0","api_min":"0.1","deps":[{"id":"lib-core.input","version":"0.3.0"}]}