]> git.tdb.fi Git - libs/gui.git/commitdiff
Improve detection of the pinch gesture
authorMikko Rasa <tdb@tdb.fi>
Sat, 21 Nov 2015 07:18:04 +0000 (09:18 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 21 Nov 2015 07:18:04 +0000 (09:18 +0200)
Previously it was way too lenient about rotational movement of the points.

source/input/gesturedetector.cpp

index 112121ee456a86736876b01e23c09a394045c498..d626c5d08efc6dcbd909083651045c7f056c98db 100644 (file)
@@ -133,9 +133,13 @@ void GestureDetector::start_gesture()
                TouchPoint &p2 = points[1];
                float ddx = p.down_x-p2.down_x;
                float ddy = p.down_y-p2.down_y;
-               if(p.x*p2.x+p.y*p2.y<0 && (p.x*ddx+p.y*ddy)*(p2.x*ddx+p2.y*ddy)<0)
-                       /* If the points moved in different directions and also both away from
-                       or towards the other, it's a pinch gesture. */
+               float away = p.x*ddx+p.y*ddy;
+               float turn = p.y*ddx-p.x*ddy;
+               float away2 = -(p2.x*ddx+p2.y*ddy);
+               float turn2 = -(p2.y*ddx-p2.x*ddy);
+               if(away*away2>0 && abs(away)>abs(turn) && abs(away2)>abs(turn2))
+                       /* If the points moved away from or towards each other without rotating
+                       significantly, it's a pinch gesture. */
                        current_gesture = GESTURE_PINCH;
                else
                        invalid_gesture = true;