From 1c9a39a4257158a98557356c2932bcabb5ee99fd Mon Sep 17 00:00:00 2001 From: rexim Date: Thu, 21 Nov 2019 02:38:36 +0700 Subject: [PATCH 1/2] (#48) Finally fix the position adjusting during zooming --- src/boomer.nim | 3 ++- src/navigation.nim | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/boomer.nim b/src/boomer.nim index 57624ae..8b62b9d 100644 --- a/src/boomer.nim +++ b/src/boomer.nim @@ -350,7 +350,8 @@ proc main() = discard let dt = 1.0 / config.fps.float - camera.update(config, dt, mouse, screenshot) + camera.update(config, dt, mouse, screenshot, + vec2(wa.width.float32, wa.height.float32)) if flashlight: f = min(f + 6.0 * dt, 0.8) diff --git a/src/navigation.nim b/src/navigation.nim index 1b18c2a..3f8a5d9 100644 --- a/src/navigation.nim +++ b/src/navigation.nim @@ -17,12 +17,18 @@ type Camera* = object deltaScale*: float proc world*(camera: Camera, v: Vec2f): Vec2f = - (camera.position + v) / camera.scale + v / camera.scale -proc update*(camera: var Camera, config: Config, dt: float, mouse: Mouse, image: Image) = +proc update*(camera: var Camera, config: Config, dt: float, mouse: Mouse, image: Image, + windowSize: Vec2f) = if abs(camera.deltaScale) > 0.5: - # TODO(#48): camera position adjustment doesn't work anymore + let p0 = (mouse.curr - (windowSize * 0.5)) / camera.scale camera.scale = max(camera.scale + camera.delta_scale * dt, 0.01) + let p1 = (mouse.curr - (windowSize * 0.5)) / camera.scale + + echo p0, " ", p1 + camera.position += p0 - p1 + camera.delta_scale -= sgn(camera.delta_scale).float * config.scale_friction * dt if not mouse.drag and (camera.velocity.length > VELOCITY_THRESHOLD): From ba939316df8d42b3caeee92dc066e599d10fe8f5 Mon Sep 17 00:00:00 2001 From: rexim Date: Thu, 21 Nov 2019 02:44:25 +0700 Subject: [PATCH 2/2] (#48) Remove debug log --- src/navigation.nim | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/navigation.nim b/src/navigation.nim index 3f8a5d9..e78b048 100644 --- a/src/navigation.nim +++ b/src/navigation.nim @@ -25,8 +25,6 @@ proc update*(camera: var Camera, config: Config, dt: float, mouse: Mouse, image: let p0 = (mouse.curr - (windowSize * 0.5)) / camera.scale camera.scale = max(camera.scale + camera.delta_scale * dt, 0.01) let p1 = (mouse.curr - (windowSize * 0.5)) / camera.scale - - echo p0, " ", p1 camera.position += p0 - p1 camera.delta_scale -= sgn(camera.delta_scale).float * config.scale_friction * dt