Hi!
I would like to combine DeviceOrientationControls with a custom logic that allow user to rotate camera around Y axis using touch move gestures. Basically I would like to achieve the same behavior (for touch devices) of this app: https://showroom.littleworkshop.fr
I’ve implemented a simple logic which seems to work ok for the touch gestures and temporarily disable the DeviceOrientationControls in case of a touchmove event (otherwise the camera orientation can’t change):
camera.position.set(0, 0, 0)
camera.rotation.set(0, 0, 0)
const controls = new THREE.DeviceOrientationControls(camera)
let lastPageX
let deltaPageX
let isTouchMove = false
document.addEventListener("touchstart", e => {
isTouchMove = false
lastPageX = e.pageX
}, false)
document.addEventListener("touchmove", e => {
isTouchMove = true
controls.enabled = false
deltaPageX = e.pageX - lastPageX
lastPageX = e.pageX
// console.log(deltaPageX)
camera.rotation.y += deltaPageX * .007
}, false)
document.addEventListener("touchend", e => {
isTouchMove = false
controls.enabled = true
}, false)
// in the animate function
function animate () {
controls.update()
// [...]
requestAnimationFrame(animate)
}
My problem is that as soon as the touchmove event has finished I need to re-enable DeviceOrientationControls. But doing that the camera rotation switch back to the orientation calculated from the device orientation, it does not get the new rotation (from the touch gesture) as the new “starting point”.
Any idea how to solve this problem?