forked from organicmaps/organicmaps
Tuned kinetic scroll
This commit is contained in:
parent
230de3ef48
commit
6d361300ba
1 changed files with 12 additions and 7 deletions
|
@ -5,6 +5,12 @@
|
|||
namespace df
|
||||
{
|
||||
|
||||
double const kKineticDuration = 0.375;
|
||||
double const kKineticFeedback = 0.2;
|
||||
double const kKineticFadeoff = 5.0;
|
||||
double const kKineticThreshold = 10.0;
|
||||
double const kKineticInertia = 0.8;
|
||||
|
||||
class KineticScrollAnimation : public BaseModelViewAnimation
|
||||
{
|
||||
public:
|
||||
|
@ -23,7 +29,7 @@ public:
|
|||
{
|
||||
// current position = target position - amplutide * e ^ (elapsed / duration)
|
||||
// we calculate current position not based on start position, but based on target position
|
||||
return m2::AnyRectD(m_targetCenter - m_direction * exp(-GetT()), m_angle, m_localRect);
|
||||
return m2::AnyRectD(m_targetCenter - m_direction * exp(-kKineticFadeoff * GetT()), m_angle, m_localRect);
|
||||
}
|
||||
|
||||
m2::AnyRectD GetTargetRect() const override
|
||||
|
@ -75,7 +81,7 @@ void KineticScroller::GrabViewRect(ScreenBase const & modelView, double timeStam
|
|||
// velocity on pixels
|
||||
double v = pxDeltaLength / elapsed;
|
||||
// at this point length(m_direction) already in pixel space, and delta normalized
|
||||
m_direction = delta * 0.8 * v + m_direction * 0.2;
|
||||
m_direction = delta * kKineticInertia * v + m_direction * (1.0 - kKineticInertia);
|
||||
|
||||
m_lastTimestamp = timeStamp;
|
||||
m_lastRect = modelView.GlobalRect();
|
||||
|
@ -89,17 +95,16 @@ void KineticScroller::CancelGrab()
|
|||
|
||||
unique_ptr<BaseModelViewAnimation> KineticScroller::CreateKineticAnimation(ScreenBase const & modelView)
|
||||
{
|
||||
static double VELOCITY_THRESHOLD = 10.0 * VisualParams::Instance().GetVisualScale();
|
||||
if (m_direction.Length() < VELOCITY_THRESHOLD)
|
||||
static double kVelocityThreshold = kKineticThreshold * VisualParams::Instance().GetVisualScale();
|
||||
if (m_direction.Length() < kVelocityThreshold)
|
||||
return unique_ptr<BaseModelViewAnimation>();
|
||||
|
||||
double const KINETIC_DURATION = 0.375;
|
||||
// Before we start animation we have to convert length(m_direction) from pixel space to mercator space
|
||||
m2::PointD center = m_lastRect.GlobalCenter();
|
||||
double glbLength = 0.5 * (modelView.PtoG(modelView.GtoP(center) + m_direction) - center).Length();
|
||||
double glbLength = kKineticFeedback * (modelView.PtoG(modelView.GtoP(center) + m_direction) - center).Length();
|
||||
return unique_ptr<BaseModelViewAnimation>(new KineticScrollAnimation(m_lastRect,
|
||||
m_direction.Normalize() * glbLength,
|
||||
KINETIC_DURATION));
|
||||
kKineticDuration));
|
||||
}
|
||||
|
||||
} // namespace df
|
||||
|
|
Loading…
Add table
Reference in a new issue