提交 c385c6ab 编写于 作者: A Adam Barth

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
上级 d761ebde
......@@ -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);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册