Skip to content

Commit

Permalink
Fix #613
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Jul 15, 2024
1 parent f1fdf15 commit 4dd09e0
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/three/controls/GlobeControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from 'three';
import { EnvironmentControls, NONE } from './EnvironmentControls.js';
import { closestRayEllipsoidSurfacePointEstimate, makeRotateAroundPoint, mouseToCoords, setRaycasterFromCamera } from './utils.js';
import { Ellipsoid } from '../math/Ellipsoid.js';

const _invMatrix = new Matrix4();
const _rotMatrix = new Matrix4();
Expand All @@ -24,6 +25,7 @@ const _zoomPointUp = new Vector3();
const _toCenter = new Vector3();
const _latLon = {};
const _ray = new Ray();
const _ellipsoid = new Ellipsoid();

const _pointer = new Vector2();
const _prevPointer = new Vector2();
Expand Down Expand Up @@ -294,9 +296,12 @@ export class GlobeControls extends EnvironmentControls {
pointerTracker,
domElement,
tilesGroup,
ellipsoid
} = this;

// reuse cache variables
const pivotDir = _pos;
const newPivotDir = _targetRight;

// get the pointer and ray
pointerTracker.getCenterPoint( _pointer );
mouseToCoords( _pointer.x, _pointer.y, domElement, _pointer );
Expand All @@ -306,12 +311,14 @@ export class GlobeControls extends EnvironmentControls {
_invMatrix.copy( tilesGroup.matrixWorld ).invert();
raycaster.ray.applyMatrix4( _invMatrix );

closestRayEllipsoidSurfacePointEstimate( raycaster.ray, ellipsoid, _vec );
_vec.applyMatrix4( tilesGroup.matrixWorld );
// construct an ellipsoid that matches a sphere with the radius of the globe so
// the drag position matches where the initial click was
const pivotRadius = _vec.copy( pivotPoint ).applyMatrix4( _invMatrix ).length();
_ellipsoid.radius.setScalar( pivotRadius );

// reuse cache variables
const pivotDir = _pos;
const newPivotDir = _targetRight;
// find the hit point
closestRayEllipsoidSurfacePointEstimate( raycaster.ray, _ellipsoid, _vec );
_vec.applyMatrix4( tilesGroup.matrixWorld );

// get the point directions
_center.setFromMatrixPosition( tilesGroup.matrixWorld );
Expand Down

0 comments on commit 4dd09e0

Please sign in to comment.