Skip to content

Commit 392e37a

Browse files
mix3dJamesAPetts
authored andcommitted
fix: 🐛 setSlice offset when scrolling/rotating after pan (#79)
* cache sliceCenter for camera offset calc in setSlice
1 parent c932efe commit 392e37a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/VTKViewport/vtkInteractorStyleMPRSlice.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
7474
const cache = {
7575
sliceNormal: [0, 0, 0],
7676
sliceRange: [0, 0],
77+
sliceCenter: [],
7778
};
7879

7980
function updateScrollManipulator() {
@@ -301,6 +302,12 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
301302

302303
const clampedSlice = clamp(slice, ...range);
303304

305+
let cameraOffset = [0, 0, 0];
306+
if (cache.sliceCenter.length) {
307+
const oldPos = camera.getFocalPoint();
308+
vtkMath.subtract(oldPos, cache.sliceCenter, cameraOffset);
309+
}
310+
304311
const center = [
305312
(bounds[0] + bounds[1]) / 2.0,
306313
(bounds[2] + bounds[3]) / 2.0,
@@ -323,12 +330,18 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
323330
zeroPoint[2] + dop[2] * clampedSlice,
324331
];
325332

333+
// Cache the center for comparison to calculate the next camera offset
334+
cache.sliceCenter = [...slicePoint];
335+
326336
const cameraPos = [
327337
slicePoint[0] - dop[0] * distance,
328338
slicePoint[1] - dop[1] * distance,
329339
slicePoint[2] - dop[2] * distance,
330340
];
331341

342+
vtkMath.add(slicePoint, cameraOffset, slicePoint);
343+
vtkMath.add(cameraPos, cameraOffset, cameraPos);
344+
332345
camera.setPosition(...cameraPos);
333346
camera.setFocalPoint(...slicePoint);
334347
return slicePoint;

0 commit comments

Comments
 (0)