Skip to content

Commit

Permalink
GlobeControls jumping fix (#448)
Browse files Browse the repository at this point in the history
* Some fixes for camera "jump"

* Fixes
  • Loading branch information
gkjohnson authored Jan 16, 2024
1 parent 2d2e76e commit 3382b20
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions example/src/controls/TileControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,16 +454,18 @@ export class TileControls {
camera.position.add( _delta );
dragPoint.copy( startDragPoint );

// adjust the height
hit.distance -= _delta.length();

}

// cast down from the camera
if ( hit ) {

const dist = hit.distance;
if ( dist < cameraRadius ) {

const delta = cameraRadius - dist;
camera.position.copy( hit.point ).addScaledVector( raycaster.ray.direction, - cameraRadius );
camera.position.addScaledVector( up, delta );
dragPoint.addScaledVector( up, delta );

}
Expand Down Expand Up @@ -776,17 +778,17 @@ export class TileControls {

if ( pivot ) {

// perform a simple realignment by rotating the camera and adjusting the height
const dist = pivot.distanceTo( camera.position );
camera.position.copy( pivot ).addScaledVector( newUp, dist );
camera.quaternion.premultiply( _quaternion );
camera.updateMatrixWorld();
// perform a simple realignment by rotating the camera around the pivot
makeRotateAroundPoint( pivot, _quaternion, _rotMatrix );
camera.matrixWorld.premultiply( _rotMatrix );
camera.matrixWorld.decompose( camera.position, camera.quaternion, _vec );

}

}

up.copy( newUp );
camera.updateMatrixWorld();

}

Expand Down

0 comments on commit 3382b20

Please sign in to comment.