Merge pull request #59 from tsoding/48

(#48) Finally fix the position adjusting during zooming
pull/61/head
Alexey Kutepov 5 years ago committed by GitHub
commit f937895801
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

Loading…
Cancel
Save