summaryrefslogtreecommitdiff
path: root/math.lua
blob: cd6745e624f749cdfdcc226803879c3327214e91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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