Perfect Human Interface wrote:However, would this really be linear if it's recalculated every sample? Should there not be a check to see if current sample is changed from previous sample?
That's why I asked what you're heading for, because while it is strictly linear
per moment, you won't see a straight line of change over a longer period.
when a and b change per sample:
-1|0|1|-1 with t mapped to 4 samples, will result in -1, 0.5, -1
-1|-1|-1|-1 with t mapped to 4 samples, will result in -1, -1, -1
when a never changes during transition:
-1|0|1|-1 with t mapped to 4 samples, will result in -1, 0, -1
-1|-1|-1|-1 with t mapped to 4 samples, will result in -1, -1, -1
You see that the first example goes to more extremes in between. Both will result in straight lines, but the first one will seem more hectic. So, if you go with the first one, but don't want "sharp angles", you could go with qarp, which is quadratic interpolation. Easier said, qarp is the linear interpolation of two linear interpolations, and therefore requires 3 samples and t.
Code: Select all
lerp(lerp(a, b, t), lerp(b, c, t), t)
or
(a + t * (b - a)) + t * ((b + t * (c - b)) - (a + t * (b - a)))
Note: requires at least one intermediate step to avoid calculating a + t * (b - a) two times
Another more curvy (read: smoother) approach would be cosine interpolation:
Code: Select all
(a + b + (a - b) * cos(t * 180°)) / 2
Other interpolations are too demanding.