balakethelock / SuperAPI

The companion compatibility addon to the 1.12.1 client mod SuperWoW
10 stars 7 forks source link

autoFoV #7

Closed shikulja closed 1 month ago

shikulja commented 2 months ago

I tried to implement it here, in general it works, maybe using a timer can be replaced with something https://github.com/shikulja/VanillaGraphicBoost/blob/master/VanillaGraphicBoost.lua

local DEBUG_MODE = false

local function DebugPrint(message)
    if DEBUG_MODE then
        DEFAULT_CHAT_FRAME:AddMessage("Debug: " .. message)
    end
end

local function IsSuperWoWLoaded()
    -- https://github.com/balakethelock/SuperWoW/wiki/Features
    return type(SetAutoloot) ~= "nil" and type(Clickthrough) ~= "nil"
end

    DebugPrint("SuperWoW loaded: " .. (IsSuperWoWLoaded() and "Yes" or "No"))

if IsSuperWoWLoaded() then
    --https://github.com/fosley/WowFovChanger/blob/master/WowFovChanger/WowFovChanger.dat
    --https://github.com/Quinchilion/WoWFoVFix/blob/master/src/WoWFoVFix/WoWFoVFix.cpp
local function CalculateFoV(screenWidth, screenHeight)
    local DEGREES_TO_RADIANS = math.pi / 180
    local RADIANS_TO_DEGREES = 180 / math.pi

    -- Base FoV value for a 4:3 screen ratio
    local BASE_FIELD_OF_VIEW = 90 * DEGREES_TO_RADIANS
    local BASE_SCREEN_RATIO = 4.0 / 3.0
    local BASE_VIEW_DISTANCE = BASE_SCREEN_RATIO / math.tan(BASE_FIELD_OF_VIEW / 2)

    local MAX_FIELD_OF_VIEW = 170 * DEGREES_TO_RADIANS
    local MIN_FIELD_OF_VIEW = 30 * DEGREES_TO_RADIANS

    if screenWidth == 0 or screenHeight == 0 then
        DebugPrint("Screen size is zero, using default FoV")
        return BASE_FIELD_OF_VIEW
    end

    local screenRatio = screenWidth / screenHeight
    local newFoV = 2 * math.atan(screenRatio / BASE_VIEW_DISTANCE)
    newFoV = math.max(math.min(newFoV, MAX_FIELD_OF_VIEW), MIN_FIELD_OF_VIEW)

    DebugPrint("Calculated FoV (Degrees): " .. newFoV * RADIANS_TO_DEGREES)
    return newFoV
end

local function ApplyFoV()
    local resolution = GetCVar("gxResolution")
    local xIndex = string.find(resolution, "x")
    local screenWidth, screenHeight = tonumber(string.sub(resolution, 1, xIndex - 1)), tonumber(string.sub(resolution, xIndex + 1))
    --local screenWidth, screenHeight = GetScreenWidth(), GetScreenHeight()
    DebugPrint("Screen size: " .. screenWidth .. "x" .. screenHeight)
    local optimalFoV = CalculateFoV(screenWidth, screenHeight)
    --ConsoleExec("FoV ".. optimalFoV)
    SetCVar("FoV", optimalFoV)
    DebugPrint("Applied FoV: " .. optimalFoV)
end

-- Функция для проверки изменения разрешения экрана
local function CheckForResolutionChange()
    local currentResolution = GetCVar("gxResolution")
    if currentResolution ~= previousResolution then
        DebugPrint("Resolution change detected")
        ApplyFoV()
        previousResolution = currentResolution
    end
end

-- Инициализация переменной для хранения предыдущего разрешения
local previousResolution = GetCVar("gxResolution")
DebugPrint("Initial resolution: " .. previousResolution)

-- Создание таймера для проверки изменения разрешения каждые 5 секунд
local frame = CreateFrame("Frame")
local function OnUpdate()
    CheckForResolutionChange()
end
frame:SetScript("OnUpdate", OnUpdate)
frame:Show()
DebugPrint("Timer started")

I was thinking of creating a convenient GUI with sliders for managing graphics, and, if possible, a description of how they work and marking them depending on the impact on performance. But I've already played enough.

AyrianaWoW commented 1 month ago

AutoFOV isn't required, just a way to translate the values into actual degrees that we can understand.

1.57 (default) is 90 degrees Horizontal FOV 2.094 is 120 degrees 2.355 is 135 degrees 3.14 is 180 degrees

According to the author, the values are in radians as that's how it is handled in WoW. Take the degrees you want, multiple by 180, then take that result and multiply by Pi to get the radians value. I suppose reversing it is to take Radians, divide by Pi, then divide the result by 180 to get degrees.

You seem like an adept coder, so if you can implement this, test it, and submit as a pull request that would be awesome!