Skip to content

Commit 328c8c4

Browse files
authored
GlobeControls: Account for the ellipsoid scale (#1482)
* Account for the ellipsoid scale * Lint fix
1 parent 6fd1344 commit 328c8c4

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

src/three/renderer/controls/GlobeControls.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export class GlobeControls extends EnvironmentControls {
240240
super.adjustCamera( camera );
241241

242242
const { ellipsoidFrame, ellipsoidFrameInverse, ellipsoid, nearMargin, farMargin } = this;
243-
const maxRadius = Math.max( ...ellipsoid.radius );
243+
const maxRadius = this._getMaxWorldRadius();
244244
if ( camera.isPerspectiveCamera ) {
245245

246246
// adjust the clip planes
@@ -498,7 +498,7 @@ export class GlobeControls extends EnvironmentControls {
498498

499499
_updateZoom() {
500500

501-
const { zoomDelta, ellipsoid, zoomSpeed, zoomPoint, camera, maxZoom, state } = this;
501+
const { zoomDelta, zoomSpeed, zoomPoint, camera, maxZoom, state } = this;
502502

503503
if ( state !== ZOOM && zoomDelta === 0 ) {
504504

@@ -562,7 +562,7 @@ export class GlobeControls extends EnvironmentControls {
562562

563563
// calculate zoom in a similar way to environment controls so
564564
// the zoom speeds are comparable
565-
const dist = this.getDistanceToCenter() - ellipsoid.radius.x;
565+
const dist = this.getDistanceToCenter() - this._getMaxWorldRadius();
566566
const scale = zoomDelta * dist * zoomSpeed * 0.0025;
567567
const clampedScale = Math.max( scale, Math.min( this.getDistanceToCenter() - maxDistance, 0 ) );
568568

@@ -628,15 +628,15 @@ export class GlobeControls extends EnvironmentControls {
628628
// returns the perspective camera transition distance can move to based on globe size and fov
629629
_getPerspectiveTransitionDistance() {
630630

631-
const { camera, ellipsoid } = this;
631+
const { camera } = this;
632632
if ( ! camera.isPerspectiveCamera ) {
633633

634634
throw new Error();
635635

636636
}
637637

638638
// When the smallest fov spans 65% of the ellipsoid then we use the near controls
639-
const ellipsoidRadius = Math.max( ...ellipsoid.radius );
639+
const ellipsoidRadius = this._getMaxWorldRadius();
640640
const fovHoriz = 2 * Math.atan( Math.tan( MathUtils.DEG2RAD * camera.fov * 0.5 ) * camera.aspect );
641641
const distVert = ellipsoidRadius / Math.tan( MathUtils.DEG2RAD * camera.fov * 0.5 );
642642
const distHoriz = ellipsoidRadius / Math.tan( fovHoriz * 0.5 );
@@ -649,15 +649,15 @@ export class GlobeControls extends EnvironmentControls {
649649
// returns the max distance the perspective camera can move to based on globe size and fov
650650
_getMaxPerspectiveDistance() {
651651

652-
const { camera, ellipsoid } = this;
652+
const { camera } = this;
653653
if ( ! camera.isPerspectiveCamera ) {
654654

655655
throw new Error();
656656

657657
}
658658

659659
// allow for zooming out such that the ellipsoid is half the size of the largest fov
660-
const ellipsoidRadius = Math.max( ...ellipsoid.radius );
660+
const ellipsoidRadius = this._getMaxWorldRadius();
661661
const fovHoriz = 2 * Math.atan( Math.tan( MathUtils.DEG2RAD * camera.fov * 0.5 ) * camera.aspect );
662662
const distVert = ellipsoidRadius / Math.tan( MathUtils.DEG2RAD * camera.fov * 0.5 );
663663
const distHoriz = ellipsoidRadius / Math.tan( fovHoriz * 0.5 );
@@ -670,7 +670,7 @@ export class GlobeControls extends EnvironmentControls {
670670
// returns the transition threshold for orthographic zoom based on the globe size and camera settings
671671
_getOrthographicTransitionZoom() {
672672

673-
const { camera, ellipsoid } = this;
673+
const { camera } = this;
674674
if ( ! camera.isOrthographicCamera ) {
675675

676676
throw new Error();
@@ -680,7 +680,7 @@ export class GlobeControls extends EnvironmentControls {
680680
const orthoHeight = ( camera.top - camera.bottom );
681681
const orthoWidth = ( camera.right - camera.left );
682682
const orthoSize = Math.max( orthoHeight, orthoWidth );
683-
const ellipsoidRadius = Math.max( ...ellipsoid.radius );
683+
const ellipsoidRadius = this._getMaxWorldRadius();
684684
const ellipsoidDiameter = 2 * ellipsoidRadius;
685685
return 2 * orthoSize / ellipsoidDiameter;
686686

@@ -689,7 +689,7 @@ export class GlobeControls extends EnvironmentControls {
689689
// returns the minimum allowed orthographic zoom based on the globe size and camera settings
690690
_getMinOrthographicZoom() {
691691

692-
const { camera, ellipsoid } = this;
692+
const { camera } = this;
693693
if ( ! camera.isOrthographicCamera ) {
694694

695695
throw new Error();
@@ -699,7 +699,7 @@ export class GlobeControls extends EnvironmentControls {
699699
const orthoHeight = ( camera.top - camera.bottom );
700700
const orthoWidth = ( camera.right - camera.left );
701701
const orthoSize = Math.min( orthoHeight, orthoWidth );
702-
const ellipsoidRadius = Math.max( ...ellipsoid.radius );
702+
const ellipsoidRadius = this._getMaxWorldRadius();
703703
const ellipsoidDiameter = 2 * ellipsoidRadius;
704704
return 0.7 * orthoSize / ellipsoidDiameter;
705705

@@ -788,4 +788,11 @@ export class GlobeControls extends EnvironmentControls {
788788

789789
}
790790

791+
_getMaxWorldRadius() {
792+
793+
const { ellipsoid, ellipsoidFrame } = this;
794+
return Math.max( ...ellipsoid.radius ) * ellipsoidFrame.getMaxScaleOnAxis();
795+
796+
}
797+
791798
}

0 commit comments

Comments
 (0)