From c385c6abdc5ce2c0a303f926d5ae42b99f453fb1 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 16 Mar 2015 09:15:53 -0700 Subject: [PATCH] Remove the "min velocity" hack from ParticleClimbingRamp Previously, we had a problem with this physics simulation not actually hitting the edge of the box and causing the scrollable contents to fall back down. To avoid that problem, we enforced a minimum velocity for the particle to ensure that it always hit the edge of the box. However, when that min velocity kicked in, the results were visually unappealing. This CL fixes the underlying problem. The fix is to apply the impluse from gravity after updating the particle's position. In that way, we slightly over estimate the particle's position in every step of the simulation, ensuring that we don't miss the edge of the box due to errors in our simulation. With this change, we no longer need the min velocity hack. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/1008423002 --- framework/animation/mechanics.dart | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/framework/animation/mechanics.dart b/framework/animation/mechanics.dart index d862d75c8..5df283361 100644 --- a/framework/animation/mechanics.dart +++ b/framework/animation/mechanics.dart @@ -5,7 +5,6 @@ import 'dart:math' as math; const double kGravity = -0.980; -const double _kMinVelocity = 0.01; abstract class System { void update(double deltaT); @@ -132,12 +131,12 @@ class ParticleClimbingRamp extends System { } void update(double deltaT) { - particle.applyImpluse(kGravity * slope * deltaT); - // If we don't apply a min velocity, error terms in the simulation can - // prevent us from reaching the targetPosition before gravity overtakes our - // initial velocity and we start rolling down the hill. - particle.velocity = math.max(_kMinVelocity, particle.velocity); particle.update(deltaT); + // Note that we apply the impluse from gravity after updating the particle's + // position so that we overestimate the distance traveled by the particle. + // That ensures that we actually hit the edge of the box and don't wind up + // reversing course. + particle.applyImpluse(kGravity * slope * deltaT); box.confine(particle); } } -- GitLab