local M=require(cameraModule)M.UpVector=Vector3.new(0,1,0)M.TransitionRate=.15 M.UpCFrame=IDENTITYCF function M.GetUpVector(v,M)return M end function M.CalculateUpCFrame(M)local v=M.UpVector local s=M:GetUpVector(v)local k=game.Workspace.CurrentCamera.CFrame.RightVector local N=getRotationBetween(v,s,k)local b=IDENTITYCF:Lerp(N,M.TransitionRate)M.UpVector=b*v M.UpCFrame=b*M.UpCFrame end function M.Update(v,M)if v.activeCameraController then local s,k=v.activeCameraController:Update(M)v.activeCameraController:ApplyVRTransform()v:CalculateUpCFrame()v.activeCameraController:UpdateUpCFrame(v.UpCFrame)local N=k:Inverse()*s s=(k*v.UpCFrame)*N if v.activeOcclusionModule then s,k=v.activeOcclusionModule:Update(M,s,k)end game.Workspace.CurrentCamera.CFrame=s game.Workspace.CurrentCamera.Focus=k if v.activeTransparencyController then v.activeTransparencyController:Update()end end end


local Camera = require(cameraModule)

Camera.UpVector = Vector3.new(0, 1, 0)
Camera.TransitionRate = 0.15
Camera.UpCFrame = IDENTITYCF

function Camera:GetUpVector(oldUpVector)
	return oldUpVector
end

function Camera:CalculateUpCFrame()
	local oldUpVector = self.UpVector
	local newUpVector = self:GetUpVector(oldUpVector)
	
	local backup = game.Workspace.CurrentCamera.CFrame.RightVector
	local transitionCF = getRotationBetween(oldUpVector, newUpVector, backup)
	local vecSlerpCF = IDENTITYCF:Lerp(transitionCF, self.TransitionRate)
	
	self.UpVector = vecSlerpCF * oldUpVector
	self.UpCFrame = vecSlerpCF * self.UpCFrame
end

function Camera:Update(dt)
	if self.activeCameraController then	
		local newCameraCFrame, newCameraFocus = self.activeCameraController:Update(dt)
		self.activeCameraController:ApplyVRTransform()
		
		self:CalculateUpCFrame()
		self.activeCameraController:UpdateUpCFrame(self.UpCFrame)
		
		local offset = newCameraFocus:Inverse() * newCameraCFrame
		newCameraCFrame = newCameraFocus * self.UpCFrame * offset
		
		if self.activeOcclusionModule then
			newCameraCFrame, newCameraFocus = self.activeOcclusionModule:Update(dt, newCameraCFrame, newCameraFocus)
		end
		
		game.Workspace.CurrentCamera.CFrame = newCameraCFrame
		game.Workspace.CurrentCamera.Focus = newCameraFocus
		
		if self.activeTransparencyController then
			self.activeTransparencyController:Update()
		end
	end
end
