local A=require(script.Parent:WaitForChild("\090\111\111\109\067\111\110\116\114\111\108\108\101\114"))local X={}do X.__index=X local A=CFrame.new()local function U(A)local X,U=A:toAxisAngle()return X*U end local function r(X)local U=X.magnitude if U>1e-05 then return CFrame.fromAxisAngle(X,U)end return A end local function l(A)local X,U,r,l,b,q,v,j,s,Y,d,y=A:components()return CFrame.new(0,0,0,l,b,q,v,j,s,Y,d,y)end function X.new()return setmetatable({lastCFrame=nil},X)end function X.Step(b,A,X)local q=b.lastCFrame or X b.lastCFrame=X local v=X.p local j=l(X)local s=q.p local Y=l(q)local d=(v-s)/A local y=U(j*Y:inverse())/A local function D(A)local X=d*A+v local U=r(y*A)*j return U+X end return{extrapolate=D;posVelocity=d;rotVelocity=y}end function X.Reset(A)A.lastCFrame=nil end end


local ZoomController =  require(script.Parent:WaitForChild("ZoomController"))

local TransformExtrapolator = {} do
	TransformExtrapolator.__index = TransformExtrapolator

	local CF_IDENTITY = CFrame.new()

	local function cframeToAxis(cframe)
		local axis, angle = cframe:toAxisAngle()
		return axis*angle
	end

	local function axisToCFrame(axis)
		local angle = axis.magnitude
		if angle > 1e-5 then
			return CFrame.fromAxisAngle(axis, angle)
		end
		return CF_IDENTITY
	end

	local function extractRotation(cf)
		local _, _, _, xx, yx, zx, xy, yy, zy, xz, yz, zz = cf:components()
		return CFrame.new(0, 0, 0, xx, yx, zx, xy, yy, zy, xz, yz, zz)
	end

	function TransformExtrapolator.new()
		return setmetatable({
			lastCFrame = nil,
		}, TransformExtrapolator)
	end

	function TransformExtrapolator:Step(dt, currentCFrame)
		local lastCFrame = self.lastCFrame or currentCFrame
		self.lastCFrame = currentCFrame

		local currentPos = currentCFrame.p
		local currentRot = extractRotation(currentCFrame)

		local lastPos = lastCFrame.p
		local lastRot = extractRotation(lastCFrame)

		-- Estimate velocities from the delta between now and the last frame
		-- This estimation can be a little noisy.
		local dp = (currentPos - lastPos)/dt
		local dr = cframeToAxis(currentRot*lastRot:inverse())/dt

		local function extrapolate(t)
			local p = dp*t + currentPos
			local r = axisToCFrame(dr*t)*currentRot
			return r + p
		end

		return {
			extrapolate = extrapolate,
			posVelocity = dp,
			rotVelocity = dr,
		}
	end

	function TransformExtrapolator:Reset()
		self.lastCFrame = nil
	end
end
