Skip to content

Commit

Permalink
feat: fix gestures
Browse files Browse the repository at this point in the history
  • Loading branch information
owulveryck committed Nov 24, 2023
1 parent e02b4df commit b15ea8e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
17 changes: 12 additions & 5 deletions client/worker_gesture_processing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}

32 changes: 25 additions & 7 deletions client/workersHandling.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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';
Expand Down

0 comments on commit b15ea8e

Please sign in to comment.