mirror of
https://github.com/tsoding/boomer
synced 2024-11-16 12:12:47 +00:00
Merge pull request #62 from tsoding/54
(#54) Make all deceleration animations depend on the current speed of the animation
This commit is contained in:
commit
e0ac5b6299
@ -84,12 +84,13 @@ type Flashlight = object
|
||||
|
||||
const
|
||||
INITIAL_FL_DELTA_RADIUS = 100.0
|
||||
FL_DELTA_RADIUS_DECELERATION = 400.0
|
||||
FL_DELTA_RADIUS_DECELERATION = 5.0
|
||||
|
||||
proc update(flashlight: var Flashlight, dt: float32) =
|
||||
flashlight.radius = max(0.0, flashlight.radius + flashlight.deltaRadius * dt)
|
||||
|
||||
if abs(flashlight.deltaRadius) > 0.5:
|
||||
flashlight.deltaRadius -= sgn(flashlight.deltaRadius).float32 * FL_DELTA_RADIUS_DECELERATION * dt
|
||||
flashlight.deltaRadius -= flashlight.deltaRadius * FL_DELTA_RADIUS_DECELERATION * dt
|
||||
|
||||
if flashlight.isEnabled:
|
||||
flashlight.shadow = min(flashlight.shadow + 6.0 * dt, 0.8)
|
||||
@ -347,6 +348,7 @@ proc main() =
|
||||
of Button1:
|
||||
mouse.prev = mouse.curr
|
||||
mouse.drag = true
|
||||
camera.velocity = vec2(0.0, 0.0)
|
||||
|
||||
of Button4: # Scroll up
|
||||
if (xev.xkey.state and ControlMask) > 0.uint32 and flashlight.isEnabled:
|
||||
|
@ -10,9 +10,8 @@ type Config* = object
|
||||
const defaultConfig* = Config(
|
||||
scrollSpeed: 1.0,
|
||||
dragVelocityFactor: 10.0,
|
||||
# TODO(#54): For a natual feel dragFriction probably should depend on velocity
|
||||
dragFriction: 600.0,
|
||||
scaleFriction: 10.0,
|
||||
dragFriction: 2.0,
|
||||
scaleFriction: 4.0,
|
||||
fps: 60
|
||||
)
|
||||
|
||||
|
@ -27,8 +27,8 @@ proc update*(camera: var Camera, config: Config, dt: float, mouse: Mouse, image:
|
||||
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
|
||||
camera.delta_scale -= camera.delta_scale * dt * config.scale_friction
|
||||
|
||||
if not mouse.drag and (camera.velocity.length > VELOCITY_THRESHOLD):
|
||||
camera.position += camera.velocity * dt
|
||||
camera.velocity -= camera.velocity.normalize * (config.dragFriction * dt)
|
||||
camera.velocity -= camera.velocity * dt * config.dragFriction
|
||||
|
Loading…
Reference in New Issue
Block a user