Skip to content

Commit

Permalink
feat(tools): Add invert zoom option (#574)
Browse files Browse the repository at this point in the history
* fix: Double click handling, and related issues

* PR comments

* Add length tool as default to show bug in click issue

* feat: Add invert to zoom direction

* Undo the changelog formatting changes

* Reverted change
  • Loading branch information
wayfarer3130 authored Apr 26, 2023
1 parent f64bb23 commit 7d41449
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ build
.env.production.local
.yarn

# Backup files created by various tools
*.bak
*~

lerna-debug.log
npm-debug.log*
yarn-debug.log*
Expand Down
10 changes: 6 additions & 4 deletions packages/tools/src/tools/ZoomTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class ZoomTool extends BaseTool {
initialMousePosWorld: Types.Point3;
dirVec: Types.Point3;

// Apparently TS says super _must_ be the first call? This seems a bit opinionated.
constructor(
toolProps: PublicToolProps = {},
defaultToolProps: ToolProps = {
Expand All @@ -28,6 +27,7 @@ class ZoomTool extends BaseTool {
maxZoomScale: 30,
pinchToZoom: true,
pan: true,
invert: false,
},
}
) {
Expand Down Expand Up @@ -146,7 +146,7 @@ class ZoomTool extends BaseTool {
const { parallelScale, focalPoint, position } = camera;

const zoomScale = 1.5 / size[1];
const k = deltaY * zoomScale;
const k = deltaY * zoomScale * (this.configuration.invert ? -1 : 1);

let parallelScaleToSet = (1.0 - k) * parallelScale;

Expand All @@ -169,7 +169,7 @@ class ZoomTool extends BaseTool {
// and the initial mouse position by some amount until ultimately we
// reach the mouse position at the focal point
const zoomScale = 5 / size[1];
const k = deltaY * zoomScale;
const k = deltaY * zoomScale * (this.configuration.invert ? -1 : 1);
parallelScaleToSet = (1.0 - k) * parallelScale;

positionToSet = vec3.scaleAndAdd(
Expand Down Expand Up @@ -244,7 +244,9 @@ class ZoomTool extends BaseTool {
-viewPlaneNormal[2],
];

const k = deltaY * zoomScale;
const k = this.configuration.invert
? deltaY / zoomScale
: deltaY * zoomScale;

let tmp = k * directionOfProjection[0];
position[0] += tmp;
Expand Down

0 comments on commit 7d41449

Please sign in to comment.