В общем делаю миникарту в игре, есть функция запечатления определенной зоны в 3д пространстве в 2д картинку, как правильно сопоставить или соотнести координаты в такой системе что бы миникарта показывала пропорциональное отношение игрока и карты?
Вот собственно код карты
function render.RunInStencilContext(context)
render.SetStencilEnable(true)
render.ClearStencil()
context()
render.SetStencilEnable(false)
end
function render.SetStencilWriteTestReferenceValues(value)
render.SetStencilTestMask(value)
render.SetStencilWriteMask(value)
end
function render.SetStencilFailZFailPassOperations(flag)
render.SetStencilPassOperation(flag)
render.SetStencilZFailOperation(flag)
end
function CreateMinimapForCurrentMap(w, h, x, y, ox, oy, height_multiplier, t, a)
if w == nil then w = 712 end
if h == nil then h = w end
if x == nil then x = 0 end
if y == nil then y = x end
if ox == nil then ox = 0 end
if oy == nil then oy = ox end
if height_multiplier == nil then height_multiplier = 1 end
if a == nil then a=Angle(90,90,0) end
if t == nil then t = {} end
data = {
angles = a,
origin = Vector(ox, oy, t.height * height_multiplier),
x = x, y = y, w = w, h = h,
bloomtone= false,
drawviewmodel= false,
ortho= true,
ortholeft= t.size_w,
orthoright= t.size_e,
orthotop= t.size_s,
orthobottom= t.size_n
}
local tbl = nil
render.RunInStencilContext(function()
render.SetStencilWriteTestReferenceValues(255)
render.SetStencilFailZFailPassOperations(STENCILOPERATION_REPLACE)
render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_ALWAYS)
render.SuppressEngineLighting(true)
render.SetColorModulation(0, 1, 0)
render.SetBlend(.4)
render.RenderView(data)
tbl = render.Capture({format="jpeg", quality= 100, w=w, h=h, x=x, y=y})
render.SuppressEngineLighting(false)
render.SetColorModulation(1, 1, 1)
render.SetBlend(1)
render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_EQUAL)
end)
return tbl
end
local ortho_value = 1000
local scale = 0.2
function EasyMinimapFragment(ox, oy, height)
return CreateMinimapForCurrentMap(nil, nil, nil, nil, ox, oy, nil, {
size_w= -ortho_value,
size_e= ortho_value,
size_s= -ortho_value,
size_n= ortho_value,
height= height or ortho_value
})
end
file.Write("test7.jpg", EasyMinimapFragment(1000,0, 10))
hook.Add("HUDPaint", "DrawFragment", function()
-- surface.SetDrawColor(255,255,255)
-- surface.SetMaterial(Material("data/test4.jpg"))
-- surface.DrawTexturedRect(100, 100, 200, 200)
-- surface.DrawLine(100,100,200,200)
-- surface.DrawLine(100,200,200,100)
-- surface.SetDrawColor(255,0,0)
-- surface.DrawCircle(0, 0, 3)
end)
if ValidPanel(MapPanel) then
MapPanel:Remove()
end
MapPanel = vgui.Create "DPanel"
function MapPanel:Paint(w,h)
surface.SetDrawColor(0,0,0)
surface.DrawRect(0, 0, w, h)
surface.SetDrawColor(255,255,255)
surface.SetMaterial(Material("data/test7.jpg"))
local pos = LocalPlayer():GetPos()
--surface.DrawTexturedRect(-pos.x, pos.y, w, h)
surface.DrawTexturedRect(-pos.x / ortho_value * w, pos.y / ortho_value * h, ortho_value, ortho_value, ortho_value)
surface.SetDrawColor(255,0,0)
surface.DrawCircle( w / 2, h /2, 5)
end
function MapPanel:Think()
end
MapPanel:SetPos(100, 100)
MapPanel:SetSize(400, 400)