local N={}do N.__index=N function N.new(j,C)return setmetatable({freq=j,goal=C;pos=C,vel=0},N)end function N.step(j,N)local C=(j.freq*2)*math.pi local f=j.goal local o=j.pos local l=j.vel local b=o-f local A=math.exp(-C*N)local J=(b*(1+C*N)+l*N)*A+f local R=(l*(1-C*N)-b*((C*C)*N))*A j.pos=J j.vel=R return J end end CameraUtils.Spring=N

local Spring = {} do
	Spring.__index = Spring

	-- Initialize to a given undamped frequency and default position
	function Spring.new(freq, pos)
		return setmetatable({
			freq = freq,
			goal = pos,
			pos = pos,
			vel = 0,
		}, Spring)
	end

	-- Advance the spring simulation by `dt` seconds
	function Spring:step(dt)
		local f = self.freq*2*math.pi
		local g = self.goal
		local p0 = self.pos
		local v0 = self.vel

		local offset = p0 - g
		local decay = math.exp(-f*dt)

		local p1 = (offset*(1 + f*dt) + v0*dt)*decay + g
		local v1 = (v0*(1 - f*dt) - offset*(f*f*dt))*decay

		self.pos = p1
		self.vel = v1

		return p1
	end
end

CameraUtils.Spring = Spring
