mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 06:04:35 +00:00
added mathx.inverse_lerp, mathx.remap_range, mathx.remap_range_clamped
This commit is contained in:
parent
097c19bda5
commit
b019767a16
15
mathx.lua
15
mathx.lua
@ -77,6 +77,21 @@ function mathx.bilerp(a, b, c, d, u, v)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--get the lerp factor on a range, inverse_lerp(6, 0, 10) == 0.6
|
||||||
|
function mathx.inverse_lerp(v, min, max)
|
||||||
|
return (v - min) / (max - min)
|
||||||
|
end
|
||||||
|
|
||||||
|
--remap a value from one range to another
|
||||||
|
function mathx.remap_range(v, in_min, in_max, out_min, out_max)
|
||||||
|
return mathx.lerp(out_min, out_max, mathx.inverse_lerp(v, in_min, in_max))
|
||||||
|
end
|
||||||
|
|
||||||
|
--remap a value from one range to another, staying within that range
|
||||||
|
function mathx.remap_range_clamped(v, in_min, in_max, out_min, out_max)
|
||||||
|
return mathx.lerp(out_min, out_max, mathx.clamp01(mathx.inverse_lerp(v, in_min, in_max)))
|
||||||
|
end
|
||||||
|
|
||||||
--easing curves
|
--easing curves
|
||||||
--(generally only "safe" for 0-1 range, see mathx.clamp01)
|
--(generally only "safe" for 0-1 range, see mathx.clamp01)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user