From 5a585ff9fa2f6a8fb87c8bd9802406914fcfd039 Mon Sep 17 00:00:00 2001 From: Julien Heanley Date: Mon, 2 Jun 2014 20:32:43 +0100 Subject: [PATCH] Pan Gesture Prediction - Fixed issue where initial displacement could be close to zero This used to result in 0 pixel movement in first frame Change-Id: Ia12ba1660a6ae8c17c8596437dfbb3be5e506fb4 Signed-off-by: Julien Heanley --- .../update/gestures/scene-graph-pan-gesture.cpp | 20 ++++++++++++-------- .../update/gestures/scene-graph-pan-gesture.h | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/dali/internal/update/gestures/scene-graph-pan-gesture.cpp b/dali/internal/update/gestures/scene-graph-pan-gesture.cpp index 65c4e38..5c2a1b5 100644 --- a/dali/internal/update/gestures/scene-graph-pan-gesture.cpp +++ b/dali/internal/update/gestures/scene-graph-pan-gesture.cpp @@ -59,7 +59,7 @@ void PanGesture::AddGesture( const Dali::PanGesture& gesture ) mWritePosition %= PAN_GESTURE_HISTORY; } -void PanGesture::RemoveOldHistory(PanInfoHistory& panHistory, uint currentTime, uint maxAge, uint minEvents) +void PanGesture::RemoveOldHistory(PanInfoHistory& panHistory, unsigned int currentTime, unsigned int maxAge, unsigned int minEvents) { PanInfoHistoryConstIter endIter = panHistory.end(); PanInfoHistoryIter iter = panHistory.begin(); @@ -180,11 +180,14 @@ void PanGesture::PredictiveAlgorithm2(int eventsThisFrame, PanInfo& gestureOut, PanInfoHistoryIter iter = panHistory.begin(); Vector2 screenVelocity = gestureOut.screen.velocity; Vector2 localVelocity = gestureOut.local.velocity; + Vector2 screenDisplacement = gestureOut.screen.displacement; + Vector2 localDisplacement = gestureOut.local.displacement; bool havePreviousAcceleration = false; bool previousVelocity = false; float previousAccel = 0.0f; unsigned int lastTime(0); + unsigned int interpolationTime = (lastVSyncTime + mPredictionAmount) - gestureOut.time; while( iter != endIter ) { PanInfo currentGesture = *iter; @@ -206,11 +209,11 @@ void PanGesture::PredictiveAlgorithm2(int eventsThisFrame, PanInfo& gestureOut, { acceleration = velDiff / time; } - float interpolationTime = (float)((int)lastVSyncTime - (int)currentGesture.time); float newVelMag = 0.0f; + int currentInterpolation = (lastVSyncTime + mPredictionAmount) - currentGesture.time; if( !havePreviousAcceleration ) { - newVelMag = velMag + (acceleration * interpolationTime); + newVelMag = velMag + (acceleration * currentInterpolation); havePreviousAcceleration = true; } else @@ -224,6 +227,8 @@ void PanGesture::PredictiveAlgorithm2(int eventsThisFrame, PanInfo& gestureOut, } gestureOut.screen.velocity = currentGesture.screen.velocity * velMod; gestureOut.local.velocity = currentGesture.local.velocity * velMod; + screenDisplacement = gestureOut.screen.displacement + (gestureOut.screen.velocity * interpolationTime); + localDisplacement = gestureOut.local.displacement + (gestureOut.local.velocity * interpolationTime); screenVelocity = currentGesture.screen.velocity; localVelocity = currentGesture.local.velocity; previousAccel = acceleration; @@ -231,12 +236,11 @@ void PanGesture::PredictiveAlgorithm2(int eventsThisFrame, PanInfo& gestureOut, } // gestureOut's position is currently equal to the last event's position and its displacement is equal to last frame's total displacement // add interpolated distance and position to current - unsigned int interpolationTime = (lastVSyncTime + mPredictionAmount) - gestureOut.time; // work out interpolated velocity - gestureOut.screen.displacement = (gestureOut.screen.velocity * interpolationTime); - gestureOut.local.displacement = (gestureOut.local.velocity * interpolationTime); - gestureOut.screen.position += gestureOut.screen.displacement; - gestureOut.local.position += gestureOut.local.displacement; + gestureOut.screen.displacement = screenDisplacement; + gestureOut.local.displacement = localDisplacement; + gestureOut.screen.position = (gestureOut.screen.position - gestureOut.screen.displacement) + screenDisplacement; + gestureOut.local.position = (gestureOut.local.position - gestureOut.local.displacement) + localDisplacement; gestureOut.time += interpolationTime; } diff --git a/dali/internal/update/gestures/scene-graph-pan-gesture.h b/dali/internal/update/gestures/scene-graph-pan-gesture.h index a8300fd..fe0be5c 100644 --- a/dali/internal/update/gestures/scene-graph-pan-gesture.h +++ b/dali/internal/update/gestures/scene-graph-pan-gesture.h @@ -196,7 +196,7 @@ public: * @param[in] maxAge Maximum age of an event before removing (in millis) * @param[in] minEvents The minimum number of events to leave in history, oldest events are removed before newest */ - void RemoveOldHistory(PanInfoHistory& panHistory, uint currentTime, uint maxAge, uint minEvents); + void RemoveOldHistory(PanInfoHistory& panHistory, unsigned int currentTime, unsigned int maxAge, unsigned int minEvents); /** * USes last two gestures -- 2.7.4