отрисовка изображения в игру (без (м)имгуи)

w99zzl1

Участник
Автор темы
130
12
Версия MoonLoader
.026-beta
Мужчинки, всем привет. Помогите пожалуйста, хочу, чтобы на команду, у меня появлялась мини карта. Кинул мини карту по пути moonloader/resourse/map.png, добавив проверку с print, понял, что скрипт успешно загружает её, но при выводе - ничего не происходит


Lua:
local texture = renderLoadTextureFromFile(getGameDirectory() .. '\\moonloader\\resourse\\map.png')
local map = false

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand('map', function()
        map = not map
    end)

    while true do
        wait(0)
        if map then
            renderDrawTexture(texture, 200, 200, 300, 300, 0.0, 0xFFFFFFFF)
        end
    end
end

Нашел похожий скрипт моей надобности с открытым кодом:
Но у меня вопрос, как сделать так, чтобы масштаб карты был во весь масштаб окна? "Масштабирование карты на 100%". Чтобы в окне передавалось всё содержимое карты, вне зависимости от моего местонахождения
Lua:
im.OnFrame(function() return cfg.show and isCanRadarRender() end,
function()
    local flags = im.WindowFlags.NoDecoration + im.WindowFlags.AlwaysAutoResize + im.WindowFlags.NoBackground + im.WindowFlags.NoSavedSettings
    local sx, sy = getScreenResolution()
    local positionX, positionY, positionZ = getCharCoordinates(PLAYER_PED)
    displayRadar(false)
    cfg.width = 650
    cfg.height = 650
    
    im.SetNextWindowSize(vec2(cfg.width, cfg.height), im.Cond.Always)
    im.SetNextWindowPos(vec2(sx - cfg.width - -650, (sy - cfg.height - -600) * 0.5), im.Cond.Always, vec2(1, 0.5))
    im.Begin('radar', nil, flags)
    im.BeginChild('radarBorder', vec2(cfg.width * 1.2, cfg.height * 1.2), false)
    im.SetCursorPos(vec2((cfg.width * 1.2 - cfg.width) * 0.5, (cfg.height * 1.2 - cfg.height) * 0.5))
    renderLockedRadar(vec2(positionX, positionY), vec2(cfg.width, cfg.height), 1*1, im_cfg.map_texture, 20.0) - -- пытался играться с "cfg.scale", ничего не понял, как работает, в то же время, если ввести "1", мастаб карты уменьшиться, но слишком сильно, если ввести 2, мастаб уменьшить ЕЩЁ БОЛЬШЕ, додумался ввести -1, мастаб уменьшается ещё больше. В итоге выставил 1*1, вроде более подходящая на данный момент
    im.EndChild()
    im.End()
end).HideCursor = true

im.OnInitialize(function()
    im_cfg.map_texture = im.CreateTextureFromFile(assetsPath .. 'map2048.png')
    im_cfg.marker_texture = im.CreateTextureFromFile(assetsPath .. 'marker.png')
    im_cfg.north_texture = im.CreateTextureFromFile(assetsPath .. 'north.png')
    im.GetIO().IniFilename = nil
end)

function renderLockedRadar(center, size, scale, map, rounding)
    local cursorPos = im.GetCursorPos()
    local screenPos = im.GetCursorScreenPos()
    local ratio = size.x / size.y
    local minIconSize = math.min(size.x, size.y) / cfg.iconSize
    local strUniq = string.format('radar<%s; %s, %s>:', screenPos.x, screenPos.y, scale)

    im.BeginChild('##child' .. strUniq, size, nil)
    local dw = im.GetWindowDrawList()
    im.SetCursorPos(vec2(0, 0))
    im.InvisibleButton('##invBtn', size)

    local function transform3DtoGlobal2D(pos)
        return vec2(pos.x + 3000, -pos.y + 3000)
    end
    local function transform3Dto2D(pos)
        local gc = transform3DtoGlobal2D(pos)
        local gcnorm = vec2(gc.x / 6000, gc.y / 6000)
        local cen, square = transform3DtoGlobal2D(center), vec2(0, 0)
        if ratio >= 1 then
            square.x = ((gcnorm.x + scale) - (gcnorm.x - scale)) * 6000
            square.y = ((gcnorm.y + scale / ratio) - (gcnorm.y - scale / ratio)) * 6000
        else
            square.x = ((gcnorm.x + scale * ratio) - (gcnorm.x - scale * ratio)) * 6000
            square.y = ((gcnorm.y + scale) - (gcnorm.y - scale)) * 6000
        end
        return vec2(size.x * (gc.x - (cen.x - square.x / 2)) / square.x, size.y * (gc.y - (cen.y - square.y / 2)) / square.y)
    end
    local function drawRadar()
        local gc = vec2(transform3DtoGlobal2D(center).x / 6000, transform3DtoGlobal2D(center).y / 6000)
        if ratio >= 1 then
            dw:AddImage(map, screenPos, vec2(screenPos.x + size.x, screenPos.y + size.y), vec2(gc.x - scale, gc.y - scale / ratio), vec2(gc.x + scale, gc.y + scale / ratio), 0xFFFFFFFF)
        else
            dw:AddImage(map, screenPos, vec2(screenPos.x + size.x, screenPos.y + size.y), vec2(gc.x - scale * ratio, gc.y - scale), vec2(gc.x + scale * ratio, gc.y + scale), 0xFFFFFFFF)
        end
    end
    local function drawRadarCenter()
        local glcen = transform3Dto2D(center)
        local cen = vec2(screenPos.x + glcen.x, screenPos.y + glcen.y)
        local radius = minIconSize * 0.5
        local colors = {
            a = im.GetColorU32Vec4(im.ImVec4(0.68, 0.83, 1, 1)),
            b = im.GetColorU32Vec4(im.ImVec4(0.1, 0.1, 0.1, 0.2)),
            c = im.GetColorU32Vec4(im.ImVec4(1, 1, 1, 1)),
        }
        local theta = math.rad(45 - getAdaptiveHeading())
        local a = rotatePoint(vec2(cen.x - radius, cen.y - radius), cen, theta)
        local b = rotatePoint(vec2(cen.x, cen.y - radius), cen, theta)
        local c = rotatePoint(vec2(cen.x - radius, cen.y), cen, theta)

        dw:AddCircleFilled(vec2(cen.x, cen.y), minIconSize * 1.5, colors.b, minIconSize * 1.5 * 1.5)
        dw:AddCircleFilled(vec2(cen.x, cen.y), minIconSize * 1, colors.b, minIconSize * 1 * 1.5)
        dw:AddTriangleFilled(a, b, c, colors.a)
        dw:AddCircleFilled(vec2(cen.x, cen.y), radius, colors.a, radius * 1.5)
    end
    local function drawMapIcon()
        for k, v in pairs(im_cfg.map_icons) do
            local gl = transform3Dto2D(vec2(v.position.x, v.position.y))
            local res, px, py = getPointInRect(0, 0, size.x, size.y, gl.x, gl.y)
            local sz = minIconSize * 1

            if not res then
                dw:AddImage(v.texture, vec2(screenPos.x + px - sz, screenPos.y + py - sz), vec2(screenPos.x + px + sz, screenPos.y + py + sz), vec2(0, 0), vec2(1, 1), 0xFFFFFFFF)
            end
        end
    end
    local function drawGangZone()
        for k, v in pairs(im_cfg.gang_zone) do
            local glStart = transform3Dto2D(vec2(v.squareStart.x, v.squareStart.y))
            local glEnd = transform3Dto2D(vec2(v.squareEnd.x, v.squareEnd.y))
            local resStart, xstart, ystart = getPointInRect(0, 0, size.x, size.y, glStart.x, glStart.y)
            local resEnd, xend, yend = getPointInRect(0, 0, size.x, size.y, glEnd.x, glEnd.y)

            if not (resStart and resEnd) then
                dw:AddRectFilled(vec2(screenPos.x + xstart, screenPos.y + ystart), vec2(screenPos.x + xend, screenPos.y + yend), v.color, 0.0)
            end
        end
    end
    local function drawPlayers()
        for k, v in pairs(getAllChars()) do
            local posX, posY, posZ = getCharCoordinates(v)
            local gl = transform3Dto2D(vec2(posX, posY))
            local res, px, py = getPointInRect(0, 0, size.x, size.y, gl.x, gl.y)
            local res_, id = sampGetPlayerIdByCharHandle(v)

            if not res and res_ and v ~= PLAYER_PED then
                local colors = {
                    a = im.GetColorU32Vec4(im.ImVec4(1.0, 0.96, 0.61, 1.0)),
                    b = im.GetColorU32Vec4(im.ImVec4(0.0, 0.0, 0.0, 0.2)),
                }
                dw:AddCircleFilled(vec2(screenPos.x + px, screenPos.y + py), minIconSize * 0.8, colors.b, minIconSize * 0.5 * 1.5)
                dw:AddCircleFilled(vec2(screenPos.x + px, screenPos.y + py), minIconSize * 0.55, colors.b, minIconSize * 0.55 * 1.5)
                dw:AddCircleFilled(vec2(screenPos.x + px, screenPos.y + py), minIconSize * 0.4, colors.a, minIconSize * 0.4 * 1.5)
            end
        end
    end
    local function drawGlobalIcon()
        local sz = minIconSize * 1.0

        local res, px, py = getPointInRect(0, 0, size.x, size.y, size.x / 2, 0)
        dw:AddImage(im_cfg.north_texture, vec2(screenPos.x + px - sz, screenPos.y + py - sz), vec2(screenPos.x + px + sz, screenPos.y + py + sz), vec2(0, 0), vec2(1, 1), 0xFFFFFFFF)
       
        local result, posX, posY, posZ = getTargetBlipCoordinates()
        if result then
            local gl = transform3Dto2D(vec2(posX, posY))
            local res, px, py = getPointInRect(0, 0, size.x, size.y, gl.x, gl.y)
            dw:AddImage(im_cfg.marker_texture, vec2(screenPos.x + px - sz, screenPos.y + py - sz), vec2(screenPos.x + px + sz, screenPos.y + py + sz), vec2(0, 0), vec2(1, 1), 0xFFFFFFFF)
        end
    end

    drawRadar()
    drawGangZone()
    drawMapIcon()
    drawPlayers()
    drawRadarCenter()
    im.EndChild()

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

meowprd

Тот самый Котовский
Проверенный
1,302
732
Не совсем понятно чего в итоге хочешь добиться.
Тема названа "без м(имгуи)" в теле код с mimgui и обычным рабочим renderDrawTexture.

В целом, твой код с базовой отрисовкой текстуры полностью рабочий.
Смотреть надо либо в лог, либо ковырять саму картинку
 

w99zzl1

Участник
Автор темы
130
12
Не совсем понятно чего в итоге хочешь добиться.
Тема названа "без м(имгуи)" в теле код с mimgui и обычным рабочим renderDrawTexture.

В целом, твой код с базовой отрисовкой текстуры полностью рабочий.
Смотреть надо либо в лог, либо ковырять саму картинку
Просто хочу сделать отрисовку изображения, с возможностью менять его позицию и размер. Этот код не работает(( Я не знаю почему

А код тут это пример