Skip to content

Commit 6b19d22

Browse files
authored
OrbitControls: introduce zoom-to-cursor on touch events (#27384)
Signed-off-by: Guilherme Avila <[email protected]>
1 parent 50ec2a0 commit 6b19d22

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

examples/jsm/controls/OrbitControls.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ class OrbitControls extends EventDispatcher {
621621

622622
}
623623

624-
function updateMouseParameters( event ) {
624+
function updateZoomParameters( x, y ) {
625625

626626
if ( ! scope.zoomToCursor ) {
627627

@@ -632,13 +632,13 @@ class OrbitControls extends EventDispatcher {
632632
performCursorZoom = true;
633633

634634
const rect = scope.domElement.getBoundingClientRect();
635-
const x = event.clientX - rect.left;
636-
const y = event.clientY - rect.top;
635+
const dx = x - rect.left;
636+
const dy = y - rect.top;
637637
const w = rect.width;
638638
const h = rect.height;
639639

640-
mouse.x = ( x / w ) * 2 - 1;
641-
mouse.y = - ( y / h ) * 2 + 1;
640+
mouse.x = ( dx / w ) * 2 - 1;
641+
mouse.y = - ( dy / h ) * 2 + 1;
642642

643643
dollyDirection.set( mouse.x, mouse.y, 1 ).unproject( scope.object ).sub( scope.object.position ).normalize();
644644

@@ -662,7 +662,7 @@ class OrbitControls extends EventDispatcher {
662662

663663
function handleMouseDownDolly( event ) {
664664

665-
updateMouseParameters( event );
665+
updateZoomParameters( event.clientX, event.clientX );
666666
dollyStart.set( event.clientX, event.clientY );
667667

668668
}
@@ -729,7 +729,7 @@ class OrbitControls extends EventDispatcher {
729729

730730
function handleMouseWheel( event ) {
731731

732-
updateMouseParameters( event );
732+
updateZoomParameters( event.clientX, event.clientY );
733733

734734
if ( event.deltaY < 0 ) {
735735

@@ -957,6 +957,11 @@ class OrbitControls extends EventDispatcher {
957957

958958
dollyStart.copy( dollyEnd );
959959

960+
const centerX = ( event.pageX + position.x ) * 0.5;
961+
const centerY = ( event.pageY + position.y ) * 0.5;
962+
963+
updateZoomParameters( centerX, centerY );
964+
960965
}
961966

962967
function handleTouchMoveDollyPan( event ) {

0 commit comments

Comments
 (0)