From 2eb9b14cc2421b7ac485d11a8147f1b7049ec339 Mon Sep 17 00:00:00 2001 From: saschawillems Date: Mon, 6 Mar 2017 22:11:19 +0100 Subject: [PATCH] Added basic Android touch movement (Refs #173) --- base/vulkanexamplebase.cpp | 21 ++++++++++++++++++++- base/vulkanexamplebase.h | 2 ++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index 8c43dbc3..e253581c 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -327,11 +327,22 @@ void VulkanExampleBase::renderLoop() fpsTimer = 0.0f; frameCounter = 0; } + + bool updateView = false; + + // Check touch state (for movement) + if (touchDown) { + touchTimer += frameTimer; + } + if (touchTimer >= 1.0) { + camera.keys.up = true; + viewChanged(); + } + // Check gamepad state const float deadZone = 0.0015f; // todo : check if gamepad is present // todo : time based and relative axis positions - bool updateView = false; if (camera.type != Camera::CameraType::firstperson) { // Rotate @@ -1169,9 +1180,17 @@ int32_t VulkanExampleBase::handleAppInput(struct android_app* app, AInputEvent* int32_t action = AMotionEvent_getAction(event); switch (action) { + case AMOTION_EVENT_ACTION_UP: { + vulkanExample->touchTimer = 0.0; + vulkanExample->touchDown = false; + vulkanExample->camera.keys.up = false; + return 1; + break; + } case AMOTION_EVENT_ACTION_DOWN: { vulkanExample->touchPos.x = AMotionEvent_getX(event, 0); vulkanExample->touchPos.y = AMotionEvent_getY(event, 0); + vulkanExample->touchDown = true; break; } case AMOTION_EVENT_ACTION_MOVE: { diff --git a/base/vulkanexamplebase.h b/base/vulkanexamplebase.h index 55a2a6de..3897361f 100644 --- a/base/vulkanexamplebase.h +++ b/base/vulkanexamplebase.h @@ -202,6 +202,8 @@ public: int32_t x; int32_t y; } touchPos; + bool touchDown = false; + double touchTimer = 0.0; /** @brief Product model and manufacturer of the Android device (via android.Product*) */ std::string androidProduct; #elif defined(VK_USE_PLATFORM_WAYLAND_KHR)