Skip to content

Commit

Permalink
Add 3 or more finger touch pan + zoom support
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Elliott authored and PaulHax committed Apr 10, 2021
1 parent 3d72851 commit 83516c5
Showing 1 changed file with 55 additions and 57 deletions.
112 changes: 55 additions & 57 deletions CameraSpinControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,45 +802,40 @@ CameraSpinControls = function ( camera, domElement ) {

event.preventDefault();

switch ( event.touches.length ) {
if ( event.touches.length === 1 ) {
// 1 finger touch: rotate
if ( scope.enableRotate === false ) return;

case 1: // one-fingered touch: rotate

if ( scope.enableRotate === false ) return;

state = STATE.ROTATE;

if ( scope.startTrackballScreenCenter ) {

scope.target.setFromMatrixPosition(scope.trackballToObject);
var startDistance = scope.target.length();
scope.target.set(0, 0, -startDistance);
scope.target.applyQuaternion(scope.object.quaternion);
scope.target.add(scope.object.position);
scope.setTargetPosition(scope.target);

}

break;

case 2: // two-fingered touch: dolly-pan
state = STATE.ROTATE;

if ( scope.startTrackballScreenCenter ) {

if ( scope.enableZoom === false
&& scope.enablePan === false
&& scope.enableRotate === false) return;
scope.target.setFromMatrixPosition(scope.trackballToObject);
var startDistance = scope.target.length();
scope.target.set(0, 0, -startDistance);
scope.target.applyQuaternion(scope.object.quaternion);
scope.target.add(scope.object.position);
scope.setTargetPosition(scope.target);

handleTouchStartDollyPanRoll( event );
}

state = STATE.TOUCH_DOLLY_PAN;
} else if ( event.touches.length >= 2 ) {

// 2+ finger touch: dolly-pan

if ( scope.enableZoom === false
&& scope.enablePan === false
&& scope.enableRotate === false) return;

scope.spinControl.cancelSpin();
scope.spinControl.enabled = false;
handleTouchStartDollyPanRoll( event );

break;
state = STATE.TOUCH_DOLLY_PAN;

default:
scope.spinControl.cancelSpin();
scope.spinControl.enabled = false;
} else {

state = STATE.NONE;
state = STATE.NONE;

}

Expand All @@ -859,58 +854,61 @@ CameraSpinControls = function ( camera, domElement ) {
event.preventDefault();
event.stopPropagation();

switch ( event.touches.length ) {

// case 1: // one-fingered touch: rotate

// if ( scope.enableRotate === false ) return;

// break;
if ( event.touches.length >= 2) {

case 2: // two-fingered touch: dolly-pan
// dolly-pan
if ( scope.enableZoom === false && scope.enablePan === false ) return;

if ( scope.enableZoom === false && scope.enablePan === false ) return;
handleTouchMoveDollyPanRoll( event );

handleTouchMoveDollyPanRoll( event );

break;

default:
} else {

state = STATE.NONE;
state = STATE.NONE;

}
// 1 finger touch events are consumed by underlying SpinControls

}

function onTouchEnd( event ) {

if ( scope.enabled === false ) return;

if( event.touches.length === 1 ) {
if( event.touches.length === 0 ) {

state = STATE.NONE;
endEvent.state = state;
scope.dispatchEvent( endEvent );

} else if( event.touches.length === 1 ) {

if ( scope.startTrackballScreenCenter ) {

// Set pivot point back to center if going from 2+ fingers to 1
scope.target.setFromMatrixPosition(scope.trackballToObject);
var startDistance = scope.target.length();
scope.target.set(0, 0, -startDistance);
scope.target.applyQuaternion(scope.object.quaternion);
scope.target.add(scope.object.position);
scope.setTargetPosition(scope.target);

}

state = STATE.ROTATE;
scope.spinControl.enabled = true;
scope.spinControl.handleTouchStart( event );

} else if( event.touches.length === 0 ) {
// } else {

state = STATE.NONE;
endEvent.state = state;
scope.dispatchEvent( endEvent );
} else if( event.touches.length >= 2 ) {

handleTouchStartDollyPanRoll( event );

}


}

function onContextMenu( event ) {

event.preventDefault();
// if ( scope.enabled === false ) return;

// event.preventDefault();

}

Expand Down

0 comments on commit 83516c5

Please sign in to comment.