плавающий renderFontDrawText

demuert

Новичок
Автор темы
2
0
Версия MoonLoader
.027.0-preview
как сделать нормальный renderFontDrawText по 3д координатам, чтобы он не плавал за движением камеры или перса и был всегда на нужных координатах.

я делаю кастомный dl с инфой об авто, мне нужно, чтобы текст всегда был на позиции авто, но он бля плавает при моём движении
__________________
как фиксить братва, мб есть альтернативы рендера текста


Lua:
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local showhealth = imgui.ImBool(false)
local showid = imgui.ImBool(false)
local showmodel = imgui.ImBool(false)
local showdistance = imgui.ImBool(false)
local windowRender = imgui.ImBool(false)

local distanceLimitValue = 300.0
local distanceLimit = imgui.ImFloat(distanceLimitValue)

local active = false
local font = renderCreateFont("Arial", 9, 7)
local sw, sh = getScreenResolution()


local screenX, screenY = getScreenResolution()

function isVehicleVisible(x, y, z)
    local camX, camY, camZ = getActiveCameraCoordinates()
    local cx, cy, cz = getActiveCameraPointAt()

    local dirX, dirY, dirZ = cx - camX, cy - camY, cz - camZ
    local len = math.sqrt(dirX^2 + dirY^2 + dirZ^2)
    dirX, dirY, dirZ = dirX / len, dirY / len, dirZ / len

    local toVehX, toVehY, toVehZ = x - camX, y - camY, z - camZ
    local toLen = math.sqrt(toVehX^2 + toVehY^2 + toVehZ^2)
    toVehX, toVehY, toVehZ = toVehX / toLen, toVehY / toLen, toVehZ / toLen

    local dot = dirX * toVehX + dirY * toVehY + dirZ * toVehZ
    
    return dot > 0.707
end


function main()
    while not isSampAvailable() do wait(0) end

    sampRegisterChatCommand('cdl', function() active = not active end)
    sampRegisterChatCommand('cdlset', function() windowRender.v = not windowRender.v end)

    while true do
        wait(0)
        imgui.Process = windowRender.v

        if not active then goto continue end

        local myX, myY, myZ = getCharCoordinates(playerPed)

        for i = 1, 2000 do
            local result, vehHandle = sampGetCarHandleBySampVehicleId(i)
            if result and doesVehicleExist(vehHandle) and isCarOnScreen(vehHandle) then
                local x, y, z = getCarCoordinates(vehHandle)
                local dist = getDistanceBetweenCoords3d(myX, myY, myZ, x, y, z)

                if dist <= distanceLimit.v and isVehicleVisible(x, y, z) then
                    local sx, sy = convert3DCoordsToScreen(x, y, z)

                    if sx and sy then
                        local health = getCarHealth(vehHandle)
                        local model = getCarModel(vehHandle)

                        local tId = showid.v and ('ID: ' .. i .. '\n') or ''
                        local tHealth = showhealth.v and ('Health: ' .. math.floor(health) .. '\n') or ''
                        local tModel = showmodel.v and ('Model ID: ' .. model .. '\n') or ''
                        local tDist = showdistance.v and ('Distance: ' .. math.floor(dist)) or ''
                        local text = tId .. tHealth .. tModel .. tDist

                        if text ~= '' then
                            renderFontDrawText(font, text, sx, sy, 0xFFFFFFFF)
                        end
                    end
                end
            end
        end

        ::continue::
    end
end
local arrayVars = {showhealth, showid, showdistance, showmodel}

function imgui.OnDrawFrame()
    if windowRender.v then
        imgui.SetNextWindowSize(imgui.ImVec2(350, 300), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 5.5, sh / 2.7), imgui.Cond.FirstUseEver)
        imgui.Begin(u8('Настройки кастомного /dl'), windowRender)

        local text = u8('Включение отображения нужной информации:')
        local textWidth = imgui.CalcTextSize(text).x
        local windowWidth = imgui.GetWindowSize().x
        imgui.SetCursorPosX((windowWidth - textWidth) * 0.5)
        imgui.Text(text)

        imgui.Checkbox(u8('ХП авто'), showhealth)
        imgui.Checkbox(u8('ID авто'), showid)
        imgui.Checkbox(u8('Расстояние к авто'), showdistance)
        imgui.Checkbox(u8('Модель авто'), showmodel)

        local buttonWidth = 150
        local spacing = 10
        local totalWidth = (buttonWidth * 2) + spacing
        imgui.SetCursorPosX((windowWidth - totalWidth) * 0.5)

        if imgui.Button(u8('Включить всё'), imgui.ImVec2(buttonWidth, 25)) then
            for k, v in ipairs(arrayVars) do v.v = true end
        end
        imgui.SameLine()
        if imgui.Button(u8('Выключить всё'), imgui.ImVec2(buttonWidth, 25)) then
            for k, v in ipairs(arrayVars) do v.v = false end
        end

        local distanceText = u8("Макс. дистанция отображения: %.0f м"):format(distanceLimit.v)
        local textDistWidth = imgui.CalcTextSize(distanceText).x
        imgui.SetCursorPosX((windowWidth - textDistWidth) * 0.5)
        imgui.Text(distanceText)

        local sliderWidth = 300
        imgui.SetCursorPosX((windowWidth - sliderWidth) * 0.5)
        imgui.PushItemWidth(sliderWidth)
        imgui.SliderFloat("##distanceSlider", distanceLimit, 1.0, 500.0, "%.0f", 1.0)
        imgui.PopItemWidth()

        imgui.End()
    end
end

function apply_custom_style()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    local ImVec2 = imgui.ImVec2

    style.WindowPadding = ImVec2(15, 15)
    style.WindowRounding = 5.0
    style.FramePadding = ImVec2(5, 5)
    style.FrameRounding = 4.0
    style.ItemSpacing = ImVec2(12, 8)
    style.ItemInnerSpacing = ImVec2(8, 6)
    style.IndentSpacing = 25.0
    style.ScrollbarSize = 15.0
    style.ScrollbarRounding = 9.0
    style.GrabMinSize = 5.0
    style.GrabRounding = 3.0

    colors[clr.Text] = ImVec4(0.80, 0.80, 0.83, 1.00)
    colors[clr.TextDisabled] = ImVec4(0.24, 0.23, 0.29, 1.00)
    colors[clr.WindowBg] = ImVec4(0.06, 0.05, 0.07, 1.00)
    colors[clr.ChildWindowBg] = ImVec4(0.07, 0.07, 0.09, 1.00)
    colors[clr.PopupBg] = ImVec4(0.07, 0.07, 0.09, 1.00)
    colors[clr.Border] = ImVec4(0.80, 0.80, 0.83, 0.88)
    colors[clr.BorderShadow] = ImVec4(0.92, 0.91, 0.88, 0.00)
    colors[clr.FrameBg] = ImVec4(0.10, 0.09, 0.12, 1.00)
    colors[clr.FrameBgHovered] = ImVec4(0.24, 0.23, 0.29, 1.00)
    colors[clr.FrameBgActive] = ImVec4(0.56, 0.56, 0.58, 1.00)
    colors[clr.TitleBg] = ImVec4(0.10, 0.09, 0.12, 1.00)
    colors[clr.TitleBgCollapsed] = ImVec4(1.00, 0.98, 0.95, 0.75)
    colors[clr.TitleBgActive] = ImVec4(0.07, 0.07, 0.09, 1.00)
    colors[clr.MenuBarBg] = ImVec4(0.10, 0.09, 0.12, 1.00)
    colors[clr.ScrollbarBg] = ImVec4(0.10, 0.09, 0.12, 1.00)
    colors[clr.ScrollbarGrab] = ImVec4(0.80, 0.80, 0.83, 0.31)
    colors[clr.ScrollbarGrabHovered] = ImVec4(0.56, 0.56, 0.58, 1.00)
    colors[clr.ScrollbarGrabActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
    colors[clr.ComboBg] = ImVec4(0.19, 0.18, 0.21, 1.00)
    colors[clr.CheckMark] = ImVec4(0.80, 0.80, 0.83, 0.31)
    colors[clr.SliderGrab] = ImVec4(0.80, 0.80, 0.83, 0.31)
    colors[clr.SliderGrabActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
    colors[clr.Button] = ImVec4(0.10, 0.09, 0.12, 1.00)
    colors[clr.ButtonHovered] = ImVec4(0.24, 0.23, 0.29, 1.00)
    colors[clr.ButtonActive] = ImVec4(0.56, 0.56, 0.58, 1.00)
    colors[clr.Header] = ImVec4(0.10, 0.09, 0.12, 1.00)
    colors[clr.HeaderHovered] = ImVec4(0.56, 0.56, 0.58, 1.00)
    colors[clr.HeaderActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
    colors[clr.ResizeGrip] = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.ResizeGripHovered] = ImVec4(0.56, 0.56, 0.58, 1.00)
    colors[clr.ResizeGripActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
    colors[clr.CloseButton] = ImVec4(0.40, 0.39, 0.38, 0.16)
    colors[clr.CloseButtonHovered] = ImVec4(0.40, 0.39, 0.38, 0.39)
    colors[clr.CloseButtonActive] = ImVec4(0.40, 0.39, 0.38, 1.00)
    colors[clr.PlotLines] = ImVec4(0.40, 0.39, 0.38, 0.63)
    colors[clr.PlotLinesHovered] = ImVec4(0.25, 1.00, 0.00, 1.00)
    colors[clr.PlotHistogram] = ImVec4(0.40, 0.39, 0.38, 0.63)
    colors[clr.PlotHistogramHovered] = ImVec4(0.25, 1.00, 0.00, 1.00)
    colors[clr.TextSelectedBg] = ImVec4(0.25, 1.00, 0.00, 0.43)
    colors[clr.ModalWindowDarkening] = ImVec4(1.00, 0.98, 0.95, 0.73)
end

apply_custom_style()
 
Последнее редактирование:

demuert

Новичок
Автор темы
2
0
Проблема в самом renderFontDrawText. Вряд-ли это можно исправить. Как вариант, используй DrawList из mimgui.
может знаешь какие-то проекты на lua, где нормальная отрисовка текста по координатам.
может есть какие-то костыли, ещё чёт. буду признателен
 

Winstаl

Известный
853
334
может знаешь какие-то проекты на lua, где нормальная отрисовка текста по координатам.
может есть какие-то костыли, ещё чёт. буду признателен
Напрямую через DirectX