Calculating scroll inertia/momentum?

How would I calculate the scrolling momentum for a scroll event?

I understand that there have to be two timestamps at the beginning of the scrolling at the end. There also has to be an "axis change" variable which is basically the amount to scroll by without inertia.

This is my current code responsible for ending of scrolling:

if ((type == kMXTEnd || type == kMXTMovedOut) && _isScrolling)
        long int finishTime = MXTimestamp();
        printf("SCEnd: Ending scroll at %ld\n",finishTime-_beginTime);

        /* scrollX is the change in X axis */
        /* finishTime is time from touch down to touch up */

        printf("  * Time: %ld ChangeX: %f\n",finishTime,scrollX);

        _isScrolling = FALSE;
        _originalScrollPoint = _scrollPoint;

Is it possible to calculate an "inertia addition" for that? Like an additional offset gained by inertia which I can scroll by in addition to the primary scroll value. Or do I need to get additional variables?

I need this because I'm writing my own UI toolkit, which isn't really based on anything.

задан Linus Juhlin 20 November 2019 в 10:30