From 87bd9178bf5cd99d8b87cf8ddd489fb39b8cfdc8 Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Mon, 21 Nov 2016 10:27:53 +0100 Subject: [PATCH] added swipe contorls to fly controls component --- src/game-lib-component-fly-controls.js | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/game-lib-component-fly-controls.js b/src/game-lib-component-fly-controls.js index 37103b7..42434b2 100644 --- a/src/game-lib-component-fly-controls.js +++ b/src/game-lib-component-fly-controls.js @@ -134,6 +134,47 @@ GameLib.D3.ComponentFlyControls.prototype.onSetParentEntity = function( document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock || document.webkitExitPointerLock; } + // Swipe + + document.addEventListener('touchstart', function(evt) { + + component.xDown = evt.touches[0].clientX; + component.yDown = evt.touches[0].clientY; + + }, false); + + document.addEventListener('touchmove', function(evt) { + + if ( ! component.xDown || ! component.yDown ) { + return; + } + + var xUp = evt.touches[0].clientX; + var yUp = evt.touches[0].clientY; + + var xDiff = component.xDown - xUp; + var yDiff = component.yDown - yUp; + + if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/ + if ( xDiff > 0 ) { + /* left swipe */ + } else { + /* right swipe */ + } + } else { + if ( yDiff > 0 ) { + /* up swipe */ + } else { + /* down swipe */ + } + } + + component.yaw -= xDiff * 0.002; + component.pitch -= yDiff * 0.002; + + }, false); + + // Mouse move document.addEventListener('mousemove', function (event) {