Use extrapolation to solve mousemove event lag

After some searching on this site, I realize that I have no control over the frequency of events of the mousemove browser.

So, I want to apply some kind of extrapolation method to solve the mousemove delay mousemove .

I record every mouse position when the mousemove event mousemove and calculates the acceleration (use the final difference to get the speed and then the acceleration).

After that, in the render() function, I measure the delta time elapsed since the last call to the render() function. Finally, I extrapolate the position with acceleration and dt .

But I do not see a significant effect using this method. Something is wrong?

EDIT: here I am making a small example. (sorry for unclear questions)

https://gist.github.com/3858124

+4
source share
2 answers

Immediately after I insert my code into the gist, I understand the problem, and then fix the error.

The problem is this:

I use the NDC coordinate to calculate the derivative, while for extrapolation I use the world space coordinate.

This is the new code:

https://gist.github.com/3858277

Conclusion: Some influence on the delayed mouseevent , but not so much. And as a (bad) side effect, a shootout will occur when the mouse movement makes emergency braking.

I'm still looking for a better solution. Any opinion / suggestion is welcome. Thanks.

+1
source

I'm not sure what you will do better with extrapolation. All current browsers support one stream for javascript, which can be behind a tab (Chrome) or in a browser window (Firefox). Therefore, if you do the work in a script, brower will not raise any mousemove events at all while your script is running *.

Thus, the best way to improve the mousemove refresh rate is to optimize your other javascript to get out of the mousemove event path. One way is to use more asynchronous calls. Thus, you can write your code to call setTimeout(nextFunc, 0) with the next step of the loop, which transfers control back from your script and allows you to fire events until the next step of your loop.

* An exception to the rule for single threads and synchronous computing is WebWorkers, which allows you to perform a specific set of actions in parallel with the rest of the execution, mainly those that are not DOM-related.

0
source

Source: https://habr.com/ru/post/1438412/


All Articles