Skip to content

Commit

Permalink
Field rename, fix rotation height snapping (#451)
Browse files Browse the repository at this point in the history
* Update zoom member names

* Fix error

* Fix rotation offset snapping

* formatting
  • Loading branch information
gkjohnson committed Jan 16, 2024
1 parent ba4da54 commit 344fcab
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions example/src/controls/TileControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ export class TileControls {
this.rotationSpeed = 5;
this.minAltitude = 0;
this.maxAltitude = 0.45 * Math.PI;
this.minDistance = 10;
this.maxDistance = Infinity;
this.minZoomDistance = 10;
this.maxZoomDistance = Infinity;
this.reorientOnDrag = true;
this.reorientOnZoom = false;

// internal state
this.pointerTracker = new PointerTracker();
this.actionHeightOffset = 0;

this.dragPointSet = false;
this.dragPoint = new Vector3();
this.startDragPoint = new Vector3();

this.rotationPointSet = false;
this.rotationPoint = new Vector3();
Expand Down Expand Up @@ -102,7 +102,7 @@ export class TileControls {

if ( this.domElement ) {

throw new Error( 'GlobeControls: Controls already attached to element' );
throw new Error( 'TileControls: Controls already attached to element' );

}

Expand Down Expand Up @@ -207,7 +207,6 @@ export class TileControls {

this.state = DRAG;
this.dragPoint.copy( hit.point );
this.startDragPoint.copy( hit.point );
this.dragPointSet = true;

this.pivotMesh.position.copy( hit.point );
Expand Down Expand Up @@ -413,6 +412,7 @@ export class TileControls {
this.rotationPointSet = false;
this.scene.remove( this.pivotMesh );
this.pivotMesh.visible = true;
this.actionHeightOffset = 0;

}

Expand All @@ -422,7 +422,6 @@ export class TileControls {
camera,
cameraRadius,
dragPoint,
startDragPoint,
up,
} = this;

Expand All @@ -447,17 +446,23 @@ export class TileControls {
// when dragging the camera and drag point may be moved
// to accommodate terrain so we try to move it back down
// to the original point.
if ( this.state === DRAG ) {
if ( ( this.state === DRAG || this.state === ROTATE ) && this.actionHeightOffset !== 0 ) {

_delta.subVectors( startDragPoint, dragPoint );
camera.position.add( _delta );
dragPoint.copy( startDragPoint );
const { actionHeightOffset } = this;
camera.position.addScaledVector( up, - actionHeightOffset );
dragPoint.addScaledVector( up, - actionHeightOffset );

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

hit.distance -= actionHeightOffset;

}

}

this.actionHeightOffset = 0;

if ( hit ) {

const dist = hit.distance;
Expand All @@ -466,6 +471,7 @@ export class TileControls {
const delta = cameraRadius - dist;
camera.position.addScaledVector( up, delta );
dragPoint.addScaledVector( up, delta );
this.actionHeightOffset = delta;

}

Expand All @@ -486,8 +492,8 @@ export class TileControls {
zoomPoint,
zoomDirection,
camera,
minDistance,
maxDistance,
minZoomDistance,
maxZoomDistance,
raycaster,
pointerTracker,
domElement,
Expand Down Expand Up @@ -518,14 +524,14 @@ export class TileControls {
// scale the distance based on how far there is to move
if ( scale < 0 ) {

const remainingDistance = Math.min( 0, dist - maxDistance );
const remainingDistance = Math.min( 0, dist - maxZoomDistance );
scale = scale * ( dist - 0 ) * 0.01;
scale = Math.max( scale, remainingDistance );

} else {

const remainingDistance = Math.max( 0, dist - minDistance );
scale = scale * ( dist - minDistance ) * 0.01;
const remainingDistance = Math.max( 0, dist - minZoomDistance );
scale = scale * ( dist - minZoomDistance ) * 0.01;
scale = Math.min( scale, remainingDistance );

}
Expand Down

0 comments on commit 344fcab

Please sign in to comment.