Could someone please explain me how it works?
Manual says
nlerp(a, b, y) Reverse linear interpolation: if lerp(a, b, x) = y, then unlerp(a, b, y) = x. Calculates (y - a) / (b - a).
but to be fair i don't get it.
The manual gave the full definition: it calculates (y - a) / (b - a), which is the opposite of lerp. So unlerp(a, b, lerp(a, b, x)) = x. E.g. lerp(10, 20, 0.5) gives 15, so unlerp(10, 20, 15) gives 0.5.
Develop games in your browser. Powerful, performant & highly capable.
Yes, that part of manual I can understand ;P
Let me rephrase my question. What about practical use of unlerp
I can easily comprehend what e.g. lerp(self.x,target.x,dt) do, but unlerp?
I know i'm missing something simple.
One possible use of unlerp is to do scrollbar math.
http://dl.dropbox.com/u/5426011/examples13/unlerp_scroll.capx
In layman's terms, it gives you the percentage of point between two values.
You have points A and B and you want to know where your "x" between points is in relation to those points. So you do unlerp(A,B,x) to see where the x is standing relative to the range between A and B.
Thanks for the examples of using unlerp guys! It's SUPER useful stuff.