Skip to content

Commit

Permalink
Merge branch 'transition-updates'
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Oct 25, 2024
2 parents d24ac8f + d9d1086 commit 3f0da05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
5 changes: 4 additions & 1 deletion example/googleMapsExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ function updateHash() {
// convert to DEG
orientationResult.azimuth *= MathUtils.RAD2DEG;
orientationResult.elevation *= MathUtils.RAD2DEG;
orientationResult.roll *= MathUtils.RAD2DEG;
cartographicResult.lat *= MathUtils.RAD2DEG;
cartographicResult.lon *= MathUtils.RAD2DEG;

Expand All @@ -213,6 +214,7 @@ function updateHash() {
params.set( 'height', cartographicResult.height.toFixed( 2 ) );
params.set( 'az', orientationResult.azimuth.toFixed( 2 ) );
params.set( 'el', orientationResult.elevation.toFixed( 2 ) );
params.set( 'roll', orientationResult.roll.toFixed( 2 ) );
window.history.replaceState( undefined, undefined, `#${ params }` );

}
Expand Down Expand Up @@ -241,11 +243,12 @@ function initFromHash() {
// get the az el fields for rotation if present
const az = parseFloat( params.get( 'az' ) );
const el = parseFloat( params.get( 'el' ) );
const roll = parseFloat( params.get( 'roll' ) ) || 0;

// extract the east-north-up frame into matrix world
WGS84_ELLIPSOID.getRotationMatrixFromAzElRoll(
lat * MathUtils.DEG2RAD, lon * MathUtils.DEG2RAD,
az * MathUtils.DEG2RAD, el * MathUtils.DEG2RAD, 0,
az * MathUtils.DEG2RAD, el * MathUtils.DEG2RAD, roll * MathUtils.DEG2RAD,
camera.matrixWorld, CAMERA_FRAME,
);

Expand Down
33 changes: 8 additions & 25 deletions src/three/controls/GlobeControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,7 @@ export class GlobeControls extends EnvironmentControls {

}

const {
camera,
tilesGroup,
pivotMesh,
} = this;
const { camera, pivotMesh } = this;

// if we're outside the transition threshold then we toggle some reorientation behavior
// when adjusting the up frame while moving the camera
Expand All @@ -190,23 +186,6 @@ export class GlobeControls extends EnvironmentControls {
// fire basic controls update
super.update( deltaTime );

if ( camera.isPerspectiveCamera ) {

// clamp the camera distance
let distanceToCenter = this.getDistanceToCenter();
const maxDistance = this._getMaxPerspectiveDistance();
if ( distanceToCenter > maxDistance ) {

_vec.setFromMatrixPosition( tilesGroup.matrixWorld ).sub( camera.position ).normalize().multiplyScalar( - 1 );
camera.position.setFromMatrixPosition( tilesGroup.matrixWorld ).addScaledVector( _vec, maxDistance );
camera.updateMatrixWorld();

distanceToCenter = maxDistance;

}

}

// update the camera planes and the ortho camera position
this.updateCameraClipPlanes( camera );

Expand Down Expand Up @@ -482,10 +461,11 @@ export class GlobeControls extends EnvironmentControls {
// the zoom speeds are comparable
const dist = this.getDistanceToCenter() - ellipsoid.radius.x;
const scale = zoomDelta * dist * zoomSpeed * 0.0025;
const clampedScale = Math.max( scale, Math.min( this.getDistanceToCenter() - maxDistance, 0 ) );

// zoom out directly from the globe center
this.getVectorToCenter( _vec ).normalize();
this.camera.position.addScaledVector( _vec, scale );
this.camera.position.addScaledVector( _vec, clampedScale );
this.camera.updateMatrixWorld();

this.zoomDelta = 0;
Expand All @@ -502,7 +482,10 @@ export class GlobeControls extends EnvironmentControls {
const normalizedDelta = Math.pow( 0.95, Math.abs( scale * 0.05 ) );
const scaleFactor = scale > 0 ? 1 / Math.abs( normalizedDelta ) : normalizedDelta;

camera.zoom = Math.max( this._getMinOrthographicZoom(), Math.min( maxZoom, camera.zoom * scaleFactor * zoomSpeed ) );
const maxScaleFactor = minZoom / camera.zoom;
const clampedScaleFactor = Math.max( scaleFactor * zoomSpeed, Math.min( maxScaleFactor, 1 ) );

camera.zoom = Math.min( maxZoom, camera.zoom * clampedScaleFactor );
camera.updateProjectionMatrix();

this.zoomDelta = 0;
Expand Down Expand Up @@ -641,7 +624,7 @@ export class GlobeControls extends EnvironmentControls {
const orthoSize = Math.min( orthoHeight, orthoWidth );
const ellipsoidRadius = Math.max( ...ellipsoid.radius );
const ellipsoidDiameter = 2 * ellipsoidRadius;
return 0.5 * orthoSize / ellipsoidDiameter;
return 0.7 * orthoSize / ellipsoidDiameter;

}

Expand Down

0 comments on commit 3f0da05

Please sign in to comment.