Skip to content

Commit

Permalink
OrbitControls: pointers list only used for identification (mrdoob#27420)
Browse files Browse the repository at this point in the history
Signed-off-by: Guilherme Avila <[email protected]>
  • Loading branch information
sciecode authored and AdaRoseCannon committed Jan 15, 2024
1 parent 6d410e6 commit 1fb4a3f
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions examples/jsm/controls/OrbitControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,64 +825,70 @@ class OrbitControls extends EventDispatcher {

}

function handleTouchStartRotate() {
function handleTouchStartRotate( event ) {

if ( pointers.length === 1 ) {

rotateStart.set( pointers[ 0 ].pageX, pointers[ 0 ].pageY );
rotateStart.set( event.pageX, event.pageY );

} else {

const x = 0.5 * ( pointers[ 0 ].pageX + pointers[ 1 ].pageX );
const y = 0.5 * ( pointers[ 0 ].pageY + pointers[ 1 ].pageY );
const position = getSecondPointerPosition( event );

const x = 0.5 * ( event.pageX + position.x );
const y = 0.5 * ( event.pageY + position.y );

rotateStart.set( x, y );

}

}

function handleTouchStartPan() {
function handleTouchStartPan( event ) {

if ( pointers.length === 1 ) {

panStart.set( pointers[ 0 ].pageX, pointers[ 0 ].pageY );
panStart.set( event.pageX, event.pageY );

} else {

const x = 0.5 * ( pointers[ 0 ].pageX + pointers[ 1 ].pageX );
const y = 0.5 * ( pointers[ 0 ].pageY + pointers[ 1 ].pageY );
const position = getSecondPointerPosition( event );

const x = 0.5 * ( event.pageX + position.x );
const y = 0.5 * ( event.pageY + position.y );

panStart.set( x, y );

}

}

function handleTouchStartDolly() {
function handleTouchStartDolly( event ) {

const position = getSecondPointerPosition( event );

const dx = pointers[ 0 ].pageX - pointers[ 1 ].pageX;
const dy = pointers[ 0 ].pageY - pointers[ 1 ].pageY;
const dx = event.pageX - position.x;
const dy = event.pageY - position.y;

const distance = Math.sqrt( dx * dx + dy * dy );

dollyStart.set( 0, distance );

}

function handleTouchStartDollyPan() {
function handleTouchStartDollyPan( event ) {

if ( scope.enableZoom ) handleTouchStartDolly();
if ( scope.enableZoom ) handleTouchStartDolly( event );

if ( scope.enablePan ) handleTouchStartPan();
if ( scope.enablePan ) handleTouchStartPan( event );

}

function handleTouchStartDollyRotate() {
function handleTouchStartDollyRotate( event ) {

if ( scope.enableZoom ) handleTouchStartDolly();
if ( scope.enableZoom ) handleTouchStartDolly( event );

if ( scope.enableRotate ) handleTouchStartRotate();
if ( scope.enableRotate ) handleTouchStartRotate( event );

}

Expand Down Expand Up @@ -1213,7 +1219,7 @@ class OrbitControls extends EventDispatcher {

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

handleTouchStartRotate();
handleTouchStartRotate( event );

state = STATE.TOUCH_ROTATE;

Expand All @@ -1223,7 +1229,7 @@ class OrbitControls extends EventDispatcher {

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

handleTouchStartPan();
handleTouchStartPan( event );

state = STATE.TOUCH_PAN;

Expand All @@ -1245,7 +1251,7 @@ class OrbitControls extends EventDispatcher {

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

handleTouchStartDollyPan();
handleTouchStartDollyPan( event );

state = STATE.TOUCH_DOLLY_PAN;

Expand All @@ -1255,7 +1261,7 @@ class OrbitControls extends EventDispatcher {

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

handleTouchStartDollyRotate();
handleTouchStartDollyRotate( event );

state = STATE.TOUCH_DOLLY_ROTATE;

Expand Down Expand Up @@ -1347,7 +1353,7 @@ class OrbitControls extends EventDispatcher {

function addPointer( event ) {

pointers.push( event );
pointers.push( event.pointerId );

}

Expand All @@ -1357,7 +1363,7 @@ class OrbitControls extends EventDispatcher {

for ( let i = 0; i < pointers.length; i ++ ) {

if ( pointers[ i ].pointerId == event.pointerId ) {
if ( pointers[ i ] == event.pointerId ) {

pointers.splice( i, 1 );
return;
Expand Down Expand Up @@ -1385,9 +1391,9 @@ class OrbitControls extends EventDispatcher {

function getSecondPointerPosition( event ) {

const pointer = ( event.pointerId === pointers[ 0 ].pointerId ) ? pointers[ 1 ] : pointers[ 0 ];
const pointerId = ( event.pointerId === pointers[ 0 ] ) ? pointers[ 1 ] : pointers[ 0 ];

return pointerPositions[ pointer.pointerId ];
return pointerPositions[ pointerId ];

}

Expand Down

0 comments on commit 1fb4a3f

Please sign in to comment.