Skip to content
This repository has been archived by the owner on Mar 5, 2021. It is now read-only.

Fix zooming too fast with trackpad #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MathieuLoutre
Copy link
Contributor

Throttle the changeOrthograpghicScale call so it executes less often. Handle the 0 case for detail and scroll delta on the trackpad.

@elisee
Copy link
Contributor

elisee commented Aug 24, 2016

Hi! Thanks for the pull request.

Is the throttle really required? update should be called a fixed number of times per second (60) so maybe we just need to adjust the multipliers or something?

We've been working on extracting all the reusable logic around Three.js from superpowers-game into superpowers-common-plugins (but it is not yet used in most editors) and I recently fixed the zoom speed on Mac for the Camera3DControls by simply using deltaY > 0 or < 0: superpowers/superpowers-common-plugins@7d10099. Maybe we should just do it like so here too?

@MathieuLoutre
Copy link
Contributor Author

Interesting. To give you an order of magnitude, in one scroll on a mouse the orthographic scale is changed 4 times, with the trackpad it changes 30-40 times. Tweaking the zoomSpeed doesn't seem to do anything meaningful with the trackpad, and same thing for the multiplier (I've tried 0.5-1.3 in value range). The problem really seem to be that it's called 10x more often than the mouse and the value is crazily amplified (moreover I'm not sure changing the multiplier/zoomSpeed would affect the mouse positively). If you've got more pointers, I'm happy to try.

What's the best way for me to try the new common plugin architecture? From what I see, it's not using the Input class anymore but the principle remains the same. I think if this gets called 40x instead of 4x you'll get the same result.

@elisee
Copy link
Contributor

elisee commented Aug 28, 2016

Camera2DControls.update is only be called 60 times per second, no matter how many times Input.onMouseWheel is called, so if throttling setOrthographicScale 13 times per second (75ms interval) helps, I guess that means your trackpad's scroll behavior has some built-in inertia?

I'd rather we find a clean way to disable / ignore that inertia that do a somewhat arbitrary throttle.

What's the best way for me to try the new common plugin architecture? From what I see, it's not using the Input class anymore but the principle remains the same. I think if this gets called 40x instead of 4x you'll get the same result.

Hmm I'm not sure we currently have any released plugin that use it? cc @bilou84. We've been toying with a pure THREE.js system that will use it but nothing ready yet (and probably won't be for a while). It probably has the same issue with inertia though.

@MathieuLoutre
Copy link
Contributor Author

You're correct, the OSX trackpad has inertia (generates a few more 0 delta events at the end of the scroll) but also generates more events from a single gesture. I appreciate the throttle is not exactly the "cleanest" way to achieve this, but it seems quite common (along with debouncing): jquery/jquery-mousewheel#36

There are a few more workarounds in that thread talking about normalising the delta (which Input already does) and limiting the total "sum" of deltas. It all seems fairly clunky to be fair but if any of these solutions appeal more to you, I'm happy to take a look and implement another. Let me know!

@elisee
Copy link
Contributor

elisee commented Sep 30, 2016

Ok finally got around to test this. On Windows it makes scrolling very slow sadly.

I wish I could test on Mac correctly but I don't have a trackpad or magic mouse so it works fine with my regular mouse IIRC.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants