mirror of
https://github.com/tsoding/boomer
synced 2024-11-18 09:28:37 +00:00
Merge pull request #59 from tsoding/48
(#48) Finally fix the position adjusting during zooming
This commit is contained in:
commit
f937895801
@ -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…
Reference in New Issue
Block a user