Skip to content

Commit 05a1cac

Browse files
committed
add reverse distance method
1 parent e6131e0 commit 05a1cac

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

common/webapp/src/js/BlueMapApp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ export class BlueMapApp {
470470
let targetY = MathUtils.lerp(this.mapViewer.map.terrainHeightAt(cm.position.x, cm.position.z) + 3, 0, targetDistance / 500);
471471

472472
let startAngle = cm.angle;
473-
let targetAngle = Math.min(Math.PI / 2, startAngle, this.mapControls.getMaxPerspectiveAngleForDistance(targetDistance));
473+
let targetAngle = Math.min(Math.PI / 2, startAngle, MapControls.getMaxPerspectiveAngleForDistance(targetDistance));
474474

475475
let startOrtho = cm.ortho;
476476
let startTilt = cm.tilt;

common/webapp/src/js/controls/map/MapControls.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {MouseZoomControls} from "./mouse/MouseZoomControls";
2828
import {MouseRotateControls} from "./mouse/MouseRotateControls";
2929
import {MouseAngleControls} from "./mouse/MouseAngleControls";
3030
import {MathUtils, Vector2, Vector3} from "three";
31-
import {Manager, Pan, Pinch, Rotate, Tap, DIRECTION_ALL, DIRECTION_VERTICAL} from "hammerjs";
31+
import {DIRECTION_ALL, DIRECTION_VERTICAL, Manager, Pan, Pinch, Rotate, Tap} from "hammerjs";
3232
import {softClamp} from "../../util/Utils";
3333
import {MapHeightControls} from "./MapHeightControls";
3434
import {KeyMoveControls} from "./keyboard/KeyMoveControls";
@@ -39,10 +39,10 @@ import {TouchMoveControls} from "./touch/TouchMoveControls";
3939
import {TouchRotateControls} from "./touch/TouchRotateControls";
4040
import {TouchAngleControls} from "./touch/TouchAngleControls";
4141
import {TouchZoomControls} from "./touch/TouchZoomControls";
42-
import {PlayerMarker} from "../../markers/PlayerMarker";
4342
import {reactive} from "vue";
4443

4544
const HALF_PI = Math.PI * 0.5;
45+
const HALF_PI_DIV = 1 / HALF_PI;
4646

4747
export class MapControls {
4848

@@ -173,7 +173,7 @@ export class MapControls {
173173
this.manager.distance = softClamp(this.manager.distance, this.minDistance, this.maxDistance, 0.8);
174174

175175
// max angle for current distance
176-
let maxAngleForZoom = this.getMaxPerspectiveAngleForDistance(this.manager.distance);
176+
let maxAngleForZoom = MapControls.getMaxPerspectiveAngleForDistance(this.manager.distance);
177177

178178
// rotation
179179
this.mouseRotate.update(delta, map);
@@ -215,10 +215,15 @@ export class MapControls {
215215
this.touchZoom.reset();
216216
}
217217

218-
getMaxPerspectiveAngleForDistance(distance) {
218+
static getMaxPerspectiveAngleForDistance(distance) {
219219
return MathUtils.clamp((1 - Math.pow(Math.max(distance - 5, 0.001) * 0.0005, 0.5)) * HALF_PI,0, HALF_PI)
220220
}
221221

222+
// getMaxPerspectiveAngleForDistance but in reverse (its simple maths, they said)
223+
static getMaxDistanceForPerspectiveAngle(angle) {
224+
return Math.pow(-(angle * HALF_PI_DIV) + 1, 2) * 2000 + 5;
225+
}
226+
222227
initializeHammer() {
223228
let touchTap = new Tap({ event: 'tap', pointers: 1, taps: 1, threshold: 5 });
224229
let touchMove = new Pan({ event: 'move', pointers: 1, direction: DIRECTION_ALL, threshold: 0 });

0 commit comments

Comments
 (0)