Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrbitControls: pointers list only used for identification #27420

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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