Android touch double tap detection (Refs #173) [skip ci]

This commit is contained in:
saschawillems 2017-03-25 11:51:32 +01:00
parent 9edc993bf9
commit bf82026295
2 changed files with 21 additions and 5 deletions

View file

@ -1181,6 +1181,9 @@ int32_t VulkanExampleBase::handleAppInput(struct android_app* app, AInputEvent*
switch (action) {
case AMOTION_EVENT_ACTION_UP: {
vulkanExample->lastTapTime = AMotionEvent_getEventTime(event);
vulkanExample->touchPos.x = AMotionEvent_getX(event, 0);
vulkanExample->touchPos.y = AMotionEvent_getY(event, 0);
vulkanExample->touchTimer = 0.0;
vulkanExample->touchDown = false;
vulkanExample->camera.keys.up = false;
@ -1188,9 +1191,22 @@ int32_t VulkanExampleBase::handleAppInput(struct android_app* app, AInputEvent*
break;
}
case AMOTION_EVENT_ACTION_DOWN: {
// Detect double tap
int64_t eventTime = AMotionEvent_getEventTime(event);
if (eventTime - vulkanExample->lastTapTime <= vks::android::DOUBLE_TAP_TIMEOUT) {
float deadZone = (160.f / vks::android::screenDensity) * vks::android::DOUBLE_TAP_SLOP * vks::android::DOUBLE_TAP_SLOP;
float x = AMotionEvent_getX(event, 0) - vulkanExample->touchPos.x;
float y = AMotionEvent_getY(event, 0) - vulkanExample->touchPos.y;
if ((x * x + y * y) < deadZone) {
vulkanExample->keyPressed(TOUCH_DOUBLE_TAP);
vulkanExample->touchDown = false;
}
}
else {
vulkanExample->touchDown = true;
}
vulkanExample->touchPos.x = AMotionEvent_getX(event, 0);
vulkanExample->touchPos.y = AMotionEvent_getY(event, 0);
vulkanExample->touchDown = true;
break;
}
case AMOTION_EVENT_ACTION_MOVE: {
@ -1210,7 +1226,6 @@ int32_t VulkanExampleBase::handleAppInput(struct android_app* app, AInputEvent*
vulkanExample->touchPos.x = eventX;
vulkanExample->touchPos.y = eventY;
break;
}
default:

View file

@ -77,6 +77,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Base", "Base", "{09B9A54B-F
ProjectSection(SolutionItems) = preProject
base\camera.hpp = base\camera.hpp
base\frustum.hpp = base\frustum.hpp
base\keycodes.hpp = base\keycodes.hpp
base\threadpool.hpp = base\threadpool.hpp
base\vulkanandroid.cpp = base\vulkanandroid.cpp
base\vulkanandroid.h = base\vulkanandroid.h