Script to Save Specified Camera View?

I found this script at https://www.wowinterface.com/forums/showthread.php?t=58245

local function SetCameraZoom(level)
    local zoom = GetCameraZoom()
    local delta = zoom-level
    if delta > 0 then
        CameraZoomIn(delta)
    else
        CameraZoomOut(-delta)
    end
end

It works for the most part, but I’m running into situations where it will trigger twice (I think?) and zoom more than intended. Is there a way to specify a camera zoom distance without calling the CameraZoomIn and CameraZoomOut functions? I know you can use SaveView(), but you have to manually set your camera in-game before it will function as intended.

This is the offending script:

local function OnEvent(self, event)
    if IsInInstance() then return end
    if IsMounted() or UnitInVehicle("player") then
        SetCVar("test_cameraOverShoulder", 0)
        SetCameraZoom(15)
    else
        SetCVar("test_cameraOverShoulder", 1)
        SetCameraZoom(7)
    end
end

local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_MOUNT_DISPLAY_CHANGED")
f:RegisterEvent("UNIT_ENTERED_VEHICLE")
f:RegisterEvent("UNIT_EXITED_VEHICLE")
f:SetScript("OnEvent", OnEvent)

It appears that UNIT_ENTERED_VEHICLE and UNIT_EXITED_VEHICLE cause SetCameraZoom’s unintended effects. Being able to save specific camera settings to call instead of using SetCameraZoom would make this problem irrelevant.

The SetCameraZoom function does the actual zooming so maybe instead:

local function SetCameraZoom(zoom)
	local toZoom = GetCameraZoom() - zoom
	local zoomMode = toZoom > 0 and CameraZoomIn or CameraZoomOut
	zoomMode(math.abs(toZoom)) 
end

If you wanted to replace things happening automatically on certain events with a manual process you could combine this with:

_G.SLASH_ZaqZoom1 = "/zz"
SlashCmdList.ZaqZoom = function(msg)
	if msg ~= "" then 
		SetCameraZoom(15) 
	else
		SetCameraZoom(7)
	end
end

where /zz zooms in and /zz [with any key] zooms out. You can change the 7 and 15 amounts.

This is not using the SetCVar lines.

1 Like

You could maybe get inspiration from how DynamicCam is realizing its SetZoom() and SetZoomUsingCVar() functions:
https://github.com/mpstark/LibCamera/blob/master/LibCamera.lua

1 Like

I tried your new function, Fizzlemizz. I have the same issue with it when it tries to activate the zoom functions while the camera is already zooming. It causes extra zoom in some cases.

After I posted this, I went digging in the DynamicCam code and found that mpstark uses a lengthy function to set the zoom level. This tells me that it’s probably not so simple to do. He posts his libraries on GitHub, so I grabbed them from there and started using his LibCamera:StopZooming() and LibCamera:SetZoom() functions instead. It’s working as intended now. Thanks for the help, guys.

1 Like