Tried my luck with DrawPloy in a HUD hook, when I ran into a wall:
[img]https://dl.dropboxusercontent.com/u/14214411/problem.jpg[/img]
Left side is DrawPoly and at the right side, the points from the loop.
Any idea how to solve this?
[scr below]
[lua]
local sin,cos,rad = math.sin,math.cos,math.rad -- Should be faster
HUDTest = {}
local function HUDMakeAdd(x2,y2) -- Lazy
local xx, yy = x2,y2
table.insert(HUDTest,{ x = xx, y = yy })
end
-- [x y = pos, l = length, s = start angle] --
local function HUDMake(x,y,l,s)
local il = 22-l
-- Starting from the inner top and ends at the upper top
for I = 1,il do
local reverseI = il-I+1
local tmp = rad(reverseI*5+s)
local xx,yy = cos(tmp)*60+x, sin(tmp)*60+y
HUDMakeAdd(xx,yy)
end
for I = 1,il do
local tmp = rad(I*5+s)
local xx,yy = cos(tmp)*70+x, sin(tmp)*70+y
HUDMakeAdd(xx,yy)
end
end
HUDMake(100,200,0,120) -- Makes the table .. no need to run this every frame
hook.Add( "HUDPaint", "nrpHUD", function()
surface.SetDrawColor(0,0,0,255)
draw.NoTexture()
surface.DrawPoly(HUDTest)
-- Debug stuff --
local oldx,oldy = HUDTest[#HUDTest].x,HUDTest[#HUDTest].y
for I=1,#HUDTest do
local t = HUDTest[I]
surface.DrawCircle(t.x+50,t.y,1,Color(255,255,255))
surface.DrawLine(t.x+50,t.y,oldx+50,oldy)
oldx,oldy = t.x,t.y
end
surface.SetTextPos(40,120)
surface.DrawText("Polys: "..#HUDTest)
end)
[/lua]
Make sure the points are being iterated from left to right; clockwise.
DrawPoly can only draw convex polygons. You will need to cut your polygon into triangles or quads and draw them separately.
Solved
Thx for the help .. I knew I forgot something.
Sorry, you need to Log In to post a reply to this thread.