Bladeren bron

TrackballControls: Fix multi-touch in `onTouchEnd()`. (#24631)

* Fix camera runaway after zoom gesture

problem is observed on mobile phone, when lifting one finger after multitouch gesture, the camera will change dramatically as if swiped from that position to where first finger is

* Update TrackballControls.js

Co-authored-by: Michael Herzog <[email protected]>
Xiaolin Pu 3 jaren geleden
bovenliggende
commit
9e12fd1fac
1 gewijzigde bestanden met toevoegingen van 14 en 2 verwijderingen
  1. 14 2
      examples/jsm/controls/TrackballControls.js

+ 14 - 2
examples/jsm/controls/TrackballControls.js

@@ -700,8 +700,20 @@ class TrackballControls extends EventDispatcher {
 
 				case 2:
 					_state = STATE.TOUCH_ZOOM_PAN;
-					_moveCurr.copy( getMouseOnCircle( event.pageX - _movePrev.x, event.pageY - _movePrev.y ) );
-					_movePrev.copy( _moveCurr );
+
+					for ( let i = 0; i < _pointers.length; i ++ ) {
+
+						if ( _pointers[ i ].pointerId !== event.pointerId ) {
+
+							const position = _pointerPositions[ _pointers[ i ].pointerId ];
+							_moveCurr.copy( getMouseOnCircle( position.x, position.y ) );
+							_movePrev.copy( _moveCurr );
+							break;
+
+						}
+
+					}
+
 					break;
 
 			}