diff options
Diffstat (limited to 'math.lua')
-rw-r--r-- | math.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/math.lua b/math.lua new file mode 100644 index 0000000..cd6745e --- /dev/null +++ b/math.lua @@ -0,0 +1,24 @@ +local M = {} + +function M.lerp(a,b,t) return (1-t)*a + t*b end +function M.smoothstep(x) + if x<0 then return 0 end + if x>1 then return 1 end + return x*x*(3 - 2*x) +end +function M.slerp(a,b,t) return M.lerp(a,b,M.smoothstep(t)) end + + +function M.sign(x) + if x == 0 then return 0 + elseif x < 0 then return -1 + elseif x > 0 then return 1 + end +end + +function M.clamp(x,minv,maxv) + return math.min(math.max(x,minv),maxv) +end + + +return M |