PaulHax / spin-controls

Arcball style controls for three.js Object3Ds and Cameras. Featuring pointer to trackball accuracy and unlimited rotation.
https://paulhax.github.io/spin-controls/
MIT License
78 stars 12 forks source link

Momentum is not working properly #6

Closed OksanaBaga closed 3 years ago

OksanaBaga commented 3 years ago

Hi, I have an issue with momentum. It works well, but sometimes it stops spinning after a few spins, especially if you are using the touchpad. This can be clearly seen in your demo as well. Do you have any ideas for improving this?

PaulHax commented 3 years ago

Hello, thanks for the issue. I agree, the momentum is... touchy. Couple at hand parameters that might help cope:

spinControl.dampingFactor = 0.5;  //  Decreases to keep spinning longer after pointer release. Default is 1.0
spinControl.rotateSensitivity = 1.5;  // Increase for a "gain" factor on transferring pointer movement to ball rotation.  

When setting rotateSensitivity to something besides 1, we do loose the point clicked on generally stays under the pointer.

PaulHax commented 3 years ago

For me, the bugaboo with the "momentum" is when the pointer movement lacks "follow through" upon pointer up. If there is no pointer movement between the last update call and the pointer up event, the spin velocity is set to zero. For a better feel on touchscreens, and especially touchpads, perhaps damping the angular velocity on pointer up would be better. Already tried something like that in onTouchEnd of SpinControls.js

// To support subtle touches do big dampening, not zeroing it
var deltaTime = ( event.timeStamp - _lastPointerEventTime ) / 1000.0;
_angularVelocity.multiplyScalar( 1 / ( 10 * deltaTime * _this.dampingFactor + 1 ) ) 

But perhaps you are seeing something completely different, aka a real bug, with "it stops spinning after a few spins."

OksanaBaga commented 3 years ago

@PaulHax Thanks for your reply! Playing with the damping factor and spin sensitivity helped a little. I think you understood correctly, my problem is

when the pointer movement lacks "follow through" upon pointer up.

I do the same movements with the mouse touchpad, but sometimes the "momentum" works correctly, and sometimes not. By the way, the external mouse works fine, for me the problem is only on the touch pad.

I did some debugging and found this piece of code that triggers on mouse up event.

if( !_this.hasPointerMovedThisFrame || !_this.enableDamping ) {
    _angularVelocity.set( 0, 0, 0 );
}

If I comment this, then everything works as expected.