local cos, sin, floor, clamp, deg2rad, insert = math.cos, math.sin, math.floor, math.Clamp, math.rad, table.insert
function GeneratePartialPie(x, y, ang1, ang2, rad, thick, prec)
prec = clamp(prec or 256, 6, 256)
local vertices = {}
local ang, dist
local quality = floor(prec / 2)
dist = rad
for i = 1, quality do
ang = deg2rad(ang1 + (ang2 - ang1) * i / quality)
insert(vertices, {x = cos(ang) * dist + x, y = sin(ang) * dist + y})
end
dist = rad + thick
for i = 0, quality - 1 do
ang = deg2rad(ang1 + (ang2 - ang1) * (quality - i) / quality)
insert(vertices, {x = cos(ang) * dist + x, y = sin(ang) * dist + y})
end
return vertices
end
function GeneratePieSlice(x, y, ang1, ang2, rad, prec)
prec = clamp(prec or 256, 4, 256)
local vertices = {}
local ang
local quality = prec - 1
insert(vertices, {x = x, y = y})
for i = 1, quality do
ang = deg2rad(ang1 + (ang2 - ang1) * i / quality)
insert(vertices, {x = cos(ang) * rad + x, y = sin(ang) * rad + y})
end
return vertices
end
hook.Add("HUDPaint", "PartialPieTest", function()
surface.SetDrawColor(50, 155, 50, 255) --Drawin' green.
--surface.DrawPoly(GeneratePartialPie(ScrW() / 2, ScrH() / 2, -90, 90, 100, 10))
--Won't work... :-C
surface.DrawPoly(GeneratePieSlice(ScrW() / 2, ScrH() / 2, -90, 90, 105)) --Draw a filled pie.
surface.SetDrawColor(0, 0, 0, 255) --Drawin' black.
local t = GeneratePartialPie(ScrW() / 2, ScrH() / 2, -90, 90, 100, 10) --Build our polygon.
insert(t, t[1]) --To ease computation, re-add the first vertex.
local oldshiz --This will be the vertex before the currently iterated one.
for _i, shiz in pairs(t) do --Iterate through each vertex.
if _i > 1 then --If it is NOT the first one.
surface.DrawLine(oldshiz.x, oldshiz.y, shiz.x, shiz.y) --Draw a line from it to the old one.
end
oldshiz = shiz --This becomes the old one.
end
end)