From b15ea8e6df3d709f8041655945a1eb813d59df6a Mon Sep 17 00:00:00 2001 From: Olivier Wulveryck Date: Fri, 24 Nov 2023 15:52:24 +0100 Subject: [PATCH] feat: fix gestures --- client/worker_gesture_processing.js | 17 ++++++++++----- client/workersHandling.js | 32 ++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/client/worker_gesture_processing.js b/client/worker_gesture_processing.js index 481fcee..37f154e 100644 --- a/client/worker_gesture_processing.js +++ b/client/worker_gesture_processing.js @@ -50,16 +50,23 @@ async function fetchStream() { function checkSwipeDirection(json) { - if (json.left > 200 && json.right < 75 && json.up < 100 && json.down < 100) { + if (json.left > 400 && json.right < 100 && json.up < 100 && json.down < 100) { return 'left'; - } else if (json.right > 200 && json.left < 75 && json.up < 100 && json.down < 100) { + } else if (json.right > 400 && json.left < 100 && json.up < 100 && json.down < 100) { return 'right'; - } else if (json.up > 200 && json.right < 100 && json.left < 100 && json.down < 75) { + } else if (json.up > 400 && json.right < 100 && json.left < 100 && json.down < 100) { return 'up'; - } else if (json.down > 200 && json.right < 100 && json.up < 75 && json.left < 100) { + } else if (json.down > 400 && json.right < 100 && json.up < 100 && json.left < 100) { return 'down'; + } else if (json.right > 600 && json.down > 600 && json.up < 50 && json.left < 50 ) { + return 'topright-to-bottomleft' + } else if (json.left > 600 && json.down > 600 && json.up < 50 && json.right < 50 ) { + return 'topleft-to-bottomright' + } else if (json.left > 600 && json.up > 600 && json.down < 50 && json.right < 50 ) { + return 'bottomleft-to-topright' + } else if (json.right > 600 && json.up > 600 && json.down < 50 && json.left < 50 ) { + return 'bottomright-to-topleft' } else { return 'none'; } } - diff --git a/client/workersHandling.js b/client/workersHandling.js index 4088d41..c9430a0 100644 --- a/client/workersHandling.js +++ b/client/workersHandling.js @@ -53,10 +53,28 @@ gestureWorker.onmessage = (event) => { switch (data.type) { case 'gesture': - if (event.data.value == 'left') { - document.getElementById('content').contentWindow.postMessage( JSON.stringify({ method: 'left' }), '*' ); - } else if (event.data.value == 'right') { - document.getElementById('content').contentWindow.postMessage( JSON.stringify({ method: 'right' }), '*' ); + + switch (event.data.value) { + case 'left': + document.getElementById('content').contentWindow.postMessage( JSON.stringify({ method: 'left' }), '*' ); + break; + case 'right': + document.getElementById('content').contentWindow.postMessage( JSON.stringify({ method: 'right' }), '*' ); + break; + case 'topleft-to-bottomright': + document.getElementById('content').contentWindow.postMessage( JSON.stringify({ method: 'right' }), '*' ); + break; + case 'topright-to-bottomleft': + document.getElementById('content').contentWindow.postMessage( JSON.stringify({ method: 'left' }), '*' ); + break; + case 'bottomright-to-topleft': + iFrame.style.zIndex = 1; + break; + case 'bottomleft-to-topright': + iFrame.style.zIndex = 4; + break; + default: + // Code to execute if none of the above cases match } break; case 'error': @@ -69,14 +87,14 @@ gestureWorker.onmessage = (event) => { let messageTimeout; function clearLaser() { - // Function to call when no message is received for 300 ms + // Function to call when no message is received for 300 ms updateLaserPosition(-10,-10); } // Listen for updates from the worker eventWorker.onmessage = (event) => { // Reset the timer every time a message is received - clearTimeout(messageTimeout); - messageTimeout = setTimeout(clearLaser, 300); + clearTimeout(messageTimeout); + messageTimeout = setTimeout(clearLaser, 300); // To hide the message (e.g., when you start drawing in WebGL again) messageDiv.style.display = 'none';