Skip to content
Snippets Groups Projects
Commit cfe56709 authored by Alexander Rose's avatar Alexander Rose
Browse files

pinch input improvements and fixes

parent 76c9f6c2
No related branches found
No related tags found
No related merge requests found
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
* Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author David Sehnal <david.sehnal@gmail.com>
......@@ -73,9 +73,6 @@ namespace TrackballControls {
const _zoomStart = Vec2.zero()
const _zoomEnd = Vec2.zero()
let _touchZoomDistanceStart = 0
let _touchZoomDistanceEnd = 0
const _panStart = Vec2.zero()
const _panEnd = Vec2.zero()
......@@ -245,7 +242,7 @@ namespace TrackballControls {
// listeners
function onDrag({ pageX, pageY, buttons, modifiers, isStart }: DragInput) {
function onDrag({ pageX, pageY, buttons, isStart }: DragInput) {
_isInteracting = true;
if (isStart) {
......@@ -279,17 +276,9 @@ namespace TrackballControls {
_zoomStart[1] -= dy * 0.0001
}
function onPinch({ distance, isStart }: PinchInput) {
function onPinch({ fraction }: PinchInput) {
_isInteracting = true;
if (isStart) {
_touchZoomDistanceStart = distance
}
_touchZoomDistanceEnd = distance
const factor = (_touchZoomDistanceStart / _touchZoomDistanceEnd) * p.zoomSpeed
_touchZoomDistanceStart = _touchZoomDistanceEnd;
Vec3.scale(_eye, _eye, factor)
_zoomStart[1] -= (fraction - 1) * 0.1
}
function dispose() {
......
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
* Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
......@@ -117,6 +117,7 @@ export type MoveInput = {
export type PinchInput = {
delta: number,
fraction: number,
distance: number,
isStart: boolean
}
......@@ -324,7 +325,9 @@ namespace InputObserver {
buttons = ButtonsType.Flag.Secondary
onPointerDown(getCenterTouch(ev))
pinch.next({ distance: lastTouchDistance, delta: 0, isStart: true })
const touchDistance = getTouchDistance(ev)
lastTouchDistance = touchDistance
pinch.next({ distance: touchDistance, fraction: 1, delta: 0, isStart: true })
}
}
......@@ -338,12 +341,14 @@ namespace InputObserver {
onPointerMove(ev.touches[0])
} else if (ev.touches.length >= 2) {
const touchDistance = getTouchDistance(ev)
if (lastTouchDistance - touchDistance < 4) {
const touchDelta = lastTouchDistance - touchDistance
if (Math.abs(touchDelta) < 4) {
buttons = ButtonsType.Flag.Secondary
onPointerMove(getCenterTouch(ev))
} else {
pinch.next({
delta: lastTouchDistance - touchDistance,
delta: touchDelta,
fraction: lastTouchDistance / touchDistance,
distance: touchDistance,
isStart: false
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment