瀏覽代碼

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 2 年之前
父節點
當前提交
9e12fd1fac
共有 1 個文件被更改,包括 14 次插入2 次删除
  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;
 
 			}