Merge pull request #59 from tsoding/48

(#48) Finally fix the position adjusting during zooming
This commit is contained in:
Alexey Kutepov 2019-11-21 02:52:57 +07:00 committed by GitHub
commit f937895801
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

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

View File

@ -17,12 +17,16 @@ 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
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):