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