Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TrackballControls.js issues with MacBook Pro trackpad scroll function

Tags:

three.js

Uncontrollable camera movement in a specific situation. I'm using the mouse scroll wheel to control zoom (pretty standard). Macbook trackpad scroll works with two finger contact and parallel, vertical movement. I haven't experimented with the zoom function when your fingers move apart. Use of the scroll function on the trackpad makes the scene zoom out "infinitely" no matter how far the user's fingers move.

Here's the breakdown:

  • Using Three.js > TrackballControls.js

  • Version of Three.js seems irrelevant.

  • Browser seems to make a slight difference. Problem is exacerbated in Chrome, more stable in Firefox but still there.

  • Sensitivity doesn't make too much difference. Both examples below use different ZoomSpeed constants.

Examples where the problem can be seen (Macbook required of course):

  • My current project

  • TrackballControls.js example page

Thank you for your time!

Added edit 23:00EDT 12/3/13 to specify question:

Sorry I didn't specify. The scroll function of the MacBook trackpad may be accidentally or purposefully used to render the site useless for the user upon each visit. Refresh is the only way to reset the problem. What is the best way to approach this? Detect OS and disable scroll is an option but also a ridiculous one. This is an accessibility problem for any site that uses TrackballControls.js. How are other devs addressing this? Any ideas? That is my question. Thank you for your time!

like image 622
ChrisTalbot Avatar asked Dec 28 '25 14:12

ChrisTalbot


1 Answers

I was having the same problem. Change the last line of code in the TrackballControl.js mousewheel event handler:

_zoomStart.y += ( 1 / delta ) * 0.05;

to this:

_zoomStart.y += delta * 0.01;

If your trackpad is anything like mine, it fires the mousewheel event more times but in smaller increments. Since the mousewheel delta was being inverted, the smaller increments were becoming larger increments, and since there were more of them, the zoom was being adjusted exponentially more. I'm not sure why it's inverted like that in the original code.

like image 59
protometa Avatar answered Dec 31 '25 19:12

protometa