Skip to content

Commit

Permalink
add restriction for moving
Browse files Browse the repository at this point in the history
  • Loading branch information
clairebb1005 committed Jun 30, 2021
1 parent 2d26937 commit 2379a50
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/js/viewer/ViewerPanoAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ export class ViewerPanoAPI {
}

onMouseMove(event){
// get depth data
const raycaster = this.getRaycaster(event);
const distance = this.depthAtPointer(event);
const cursorLocation = raycaster.ray.origin.addScaledVector(raycaster.ray.direction, distance);

// get cursor data
const currentPos = this.viewerAPI.image.currentImage.pos;
const newLocalPos = this.getCursorLocation(event);
Expand All @@ -236,10 +241,20 @@ export class ViewerPanoAPI {
}
});

// limit distance to current mesh
const bestLocalPos = this.viewerAPI.toLocal(this.bestImg.pos);
const [dx, dy] = [this.camera.position.x - bestLocalPos.x, this.camera.position.y - bestLocalPos.y];
const currDistance = Math.sqrt(dx * dx + dy * dy);
const [deepx, deepy] = [this.camera.position.x - cursorLocation.x, this.camera.position.y - cursorLocation.y]
const currDeepDistance = Math.sqrt(deepx * deepx + deepy * deepy);

// difference between "camera to img" and "camera to raycaster"
const diff = Math.abs(currDistance-currDeepDistance)

// avoid duplication
// if the nearest image of mouse position is not the same as the previous one
// if the nearest image of mouse position is not the same as the previous one, and the diff is smaller than 1
// create new mesh and remove old mesh, and save latest mesh and image
if (this.bestImg != this.lastBestImg) {
if (this.bestImg != this.lastBestImg && diff < 1) {
var x = 0, y = 0, z = -2

// clickable meshes are the bestImg
Expand Down

0 comments on commit 2379a50

Please sign in to comment.