local u=require(cameraModule)local R=IDENTITYCF u.UpVector=Vector3.new(0,1,0)u.TransitionRate=.15 u.UpCFrame=IDENTITYCF function u.GetUpVector(R,u)return u end function u.CalculateUpCFrame(u)local X=u.UpVector local S=u:GetUpVector(X)local V=game.Workspace.CurrentCamera.CFrame.RightVector local Q=getRotationBetween(X,S,V)local A=IDENTITYCF:Lerp(Q,u.TransitionRate)u.UpVector=A*X u.UpCFrame=A*u.UpCFrame R=u.UpCFrame end function u.Update(R,u)if R.activeCameraController then local X,S=R.activeCameraController:Update(u)R.activeCameraController:ApplyVRTransform()R:CalculateUpCFrame()R.activeCameraController:UpdateUpCFrame(R.UpCFrame)local V=S:Inverse()*X X=(S*R.UpCFrame)*V if R.activeCameraController.lastCameraTransform then R.activeCameraController.lastCameraTransform=X R.activeCameraController.lastCameraFocus=S end if R.activeOcclusionModule then X,S=R.activeOcclusionModule:Update(u,X,S)end game.Workspace.CurrentCamera.CFrame=X game.Workspace.CurrentCamera.Focus=S if R.activeTransparencyController then R.activeTransparencyController:Update()end end end


local Camera = require(cameraModule)

local lastUpCFrame = IDENTITYCF

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
	
	lastUpCFrame = 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.activeCameraController.lastCameraTransform) then
			self.activeCameraController.lastCameraTransform = newCameraCFrame
			self.activeCameraController.lastCameraFocus = newCameraFocus
		end
		
		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
