Skip to content

Commit f9f28bf

Browse files
committed
Enforce minimum distance to new camera focal point
1 parent 98716ba commit f9f28bf

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/Viewer.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Constants } from './Constants.js';
1111
import { getCurrentTime } from './Util.js';
1212

1313
const THREE_CAMERA_FOV = 50;
14+
const MINIMUM_DISTANCE_TO_NEW_FOCAL_POINT = .75;
1415

1516
export class Viewer {
1617

@@ -203,6 +204,7 @@ export class Viewer {
203204

204205
const renderDimensions = new THREE.Vector2();
205206
const clickOffset = new THREE.Vector2();
207+
const toNewFocalPoint = new THREE.Vector3();
206208
const outHits = [];
207209

208210
return function(mouse) {
@@ -216,10 +218,14 @@ export class Viewer {
216218
this.mousePosition.set(mouse.offsetX, mouse.offsetY);
217219
this.raycaster.intersectSplatMesh(this.splatMesh, outHits);
218220
if (outHits.length > 0) {
219-
this.previousCameraTarget.copy(this.controls.target);
220-
this.nextCameraTarget.copy(outHits[0].origin);
221-
this.transitioningCameraTarget = true;
222-
this.transitioningCameraTargetStartTime = getCurrentTime();
221+
const intersectionPoint = outHits[0].origin;
222+
toNewFocalPoint.copy(intersectionPoint).sub(this.camera.position);
223+
if (toNewFocalPoint.length() > MINIMUM_DISTANCE_TO_NEW_FOCAL_POINT) {
224+
this.previousCameraTarget.copy(this.controls.target);
225+
this.nextCameraTarget.copy(intersectionPoint);
226+
this.transitioningCameraTarget = true;
227+
this.transitioningCameraTargetStartTime = getCurrentTime();
228+
}
223229
}
224230
}
225231
};

0 commit comments

Comments
 (0)