From 2d8e49766252749ef586ffd988c9858666c01995 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 21 Nov 2015 09:18:04 +0200 Subject: [PATCH] Improve detection of the pinch gesture Previously it was way too lenient about rotational movement of the points. --- source/input/gesturedetector.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/input/gesturedetector.cpp b/source/input/gesturedetector.cpp index 112121e..d626c5d 100644 --- a/source/input/gesturedetector.cpp +++ b/source/input/gesturedetector.cpp @@ -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; -- 2.43.0