From: Aaron Kennedy Date: Wed, 27 Jul 2011 04:23:49 +0000 (+1000) Subject: Don't jump around when maximumEasingTime is specified X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=c57a9238e94942d883f79de8d1ac277092903790;p=konrad%2Fqtdeclarative.git Don't jump around when maximumEasingTime is specified Task-number: QTBUG-20436 Change-Id: I477c42d55e712e141403b3a95d1c9b0685df5f0d Reviewed-on: http://codereview.qt.nokia.com/2240 Reviewed-by: Qt Sanity Bot Reviewed-by: Michael Brasser --- diff --git a/src/declarative/util/qdeclarativesmoothedanimation.cpp b/src/declarative/util/qdeclarativesmoothedanimation.cpp index b77db89..2200d2c 100644 --- a/src/declarative/util/qdeclarativesmoothedanimation.cpp +++ b/src/declarative/util/qdeclarativesmoothedanimation.cpp @@ -123,20 +123,23 @@ bool QSmoothedAnimation::recalc() sd = s; } else if (maximumEasingTime != -1 && tf > (maximumEasingTime / 1000.)) { qreal met = maximumEasingTime / 1000.; - td = tf - met; - - qreal c1 = td; - qreal c2 = (tf - td) * vi - tf * velocity; - qreal c3 = -0.5 * (tf - td) * vi * vi; - - qreal vp1 = (-c2 + sqrt(c2 * c2 - 4 * c1 * c3)) / (2. * c1); - - vp = vp1; - a = vp / met; - d = a; - tp = (vp - vi) / a; - sp = vi * tp + 0.5 * a * tp * tp; - sd = sp + (td - tp) * vp; + // tp| |td + // vp_ _______ + // / \ + // vi_ / \ + // \ + // \ _ 0 + // |ta| |ta| + // + qreal ta = met / 2.; + a = (s - (vi * tf - 0.5 * vi * ta)) / (tf * ta - ta * ta); + + vp = vi + a * ta; + d = vp / ta; + tp = ta; + sp = vi * ta + 0.5 * a * tp * tp; + sd = sp + vp * (tf - 2 * ta); + td = tf - ta; } else { qreal c1 = 0.25 * tf * tf; qreal c2 = 0.5 * vi * tf - s; diff --git a/src/declarative/util/qdeclarativesmoothedanimation_p_p.h b/src/declarative/util/qdeclarativesmoothedanimation_p_p.h index 0ce2eab..161fb11 100644 --- a/src/declarative/util/qdeclarativesmoothedanimation_p_p.h +++ b/src/declarative/util/qdeclarativesmoothedanimation_p_p.h @@ -103,7 +103,7 @@ private: qreal d; // Deceleration qreal tf; // Total time qreal tp; // Time at which peak velocity occurs - qreal td; // Time at which decelleration begins + qreal td; // Time at which deceleration begins qreal vp; // Velocity at tp qreal sp; // Displacement at tp qreal sd; // Displacement at td