summaryrefslogtreecommitdiffstats
path: root/include/ui
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2011-09-14 10:53:18 -0700
committerJeff Brown <jeffbrown@google.com>2011-09-14 19:16:37 -0700
commitb59ab9f41faafb358afb4f951de96f34a656e0b4 (patch)
tree2fe7eefa2f4a044df7440378691264b644fc93f5 /include/ui
parentaab55bf3e323b73062bd932682886b19c062a8a0 (diff)
downloadframeworks_base-b59ab9f41faafb358afb4f951de96f34a656e0b4.zip
frameworks_base-b59ab9f41faafb358afb4f951de96f34a656e0b4.tar.gz
frameworks_base-b59ab9f41faafb358afb4f951de96f34a656e0b4.tar.bz2
Velocity Tracker II: The Revenge of Velocity Tracker
Bug: 5265529 Rewrote the velocity tracker to fit a polynomial curve to pointer movements using least squares linear regression. The velocity is simply the first derivative of this polynomial. Clients can also obtain an Estimator that describes the complete terms of the estimating polynomial including the coefficient of determination which provides a measure of the quality of the fit (confidence). Enhanced PointerLocation to display the movement curve predicted by the estimator in addition to the velocity vector. By default, the algorithm computes a 2nd degree (quadratic) polynomial based on a 100ms recent history horizon. Change-Id: Id377bef44117fce68fee2c41f90134ce3224d3a1
Diffstat (limited to 'include/ui')
-rw-r--r--include/ui/Input.h49
1 files changed, 40 insertions, 9 deletions
diff --git a/include/ui/Input.h b/include/ui/Input.h
index af899ef..438a1a0 100644
--- a/include/ui/Input.h
+++ b/include/ui/Input.h
@@ -620,10 +620,41 @@ private:
*/
class VelocityTracker {
public:
+ // Default polynomial degree. (used by getVelocity)
+ static const uint32_t DEFAULT_DEGREE = 2;
+
+ // Default sample horizon. (used by getVelocity)
+ // We don't use too much history by default since we want to react to quick
+ // changes in direction.
+ static const nsecs_t DEFAULT_HORIZON = 100 * 1000000; // 100 ms
+
struct Position {
float x, y;
};
+ struct Estimator {
+ static const size_t MAX_DEGREE = 2;
+
+ // Polynomial coefficients describing motion in X and Y.
+ float xCoeff[MAX_DEGREE + 1], yCoeff[MAX_DEGREE + 1];
+
+ // Polynomial degree (number of coefficients), or zero if no information is
+ // available.
+ uint32_t degree;
+
+ // Confidence (coefficient of determination), between 0 (no fit) and 1 (perfect fit).
+ float confidence;
+
+ inline void clear() {
+ degree = 0;
+ confidence = 0;
+ for (size_t i = 0; i <= MAX_DEGREE; i++) {
+ xCoeff[i] = 0;
+ yCoeff[i] = 0;
+ }
+ }
+ };
+
VelocityTracker();
// Resets the velocity tracker state.
@@ -645,10 +676,16 @@ public:
void addMovement(const MotionEvent* event);
// Gets the velocity of the specified pointer id in position units per second.
- // Returns false and sets the velocity components to zero if there is no movement
- // information for the pointer.
+ // Returns false and sets the velocity components to zero if there is
+ // insufficient movement information for the pointer.
bool getVelocity(uint32_t id, float* outVx, float* outVy) const;
+ // Gets a quadratic estimator for the movements of the specified pointer id.
+ // Returns false and clears the estimator if there is no information available
+ // about the pointer.
+ bool getEstimator(uint32_t id, uint32_t degree, nsecs_t horizon,
+ Estimator* outEstimator) const;
+
// Gets the active pointer id, or -1 if none.
inline int32_t getActivePointerId() const { return mActivePointerId; }
@@ -657,13 +694,7 @@ public:
private:
// Number of samples to keep.
- static const uint32_t HISTORY_SIZE = 10;
-
- // Oldest sample to consider when calculating the velocity.
- static const nsecs_t MAX_AGE = 100 * 1000000; // 100 ms
-
- // The minimum duration between samples when estimating velocity.
- static const nsecs_t MIN_DURATION = 5 * 1000000; // 5 ms
+ static const uint32_t HISTORY_SIZE = 20;
struct Movement {
nsecs_t eventTime;