implement touch to move for mobile

This commit is contained in:
Romain Beaumont 2021-03-21 00:32:46 +00:00
parent 807ce65b89
commit 247f7d4eec

View file

@ -246,6 +246,17 @@ async function connect (options) {
document.addEventListener('mozpointerlockchange', changeCallback, false)
document.addEventListener('webkitpointerlockchange', changeCallback, false)
let lastTouch
document.addEventListener('touchmove', (e) => {
if (lastTouch !== undefined) {
moveCallback({ movementX: e.touches[0].pageX - lastTouch.pageX, movementY: e.touches[0].pageY - lastTouch.pageY })
}
lastTouch = e.touches[0]
})
document.addEventListener('touchend', () => {
lastTouch = undefined
})
renderer.domElement.requestPointerLock = renderer.domElement.requestPointerLock ||
renderer.domElement.mozRequestPointerLock ||
renderer.domElement.webkitRequestPointerLock