So, I'm trying to make a GTA-director-mode-style recording addon (yes, I know, a ton of work and probably extremely painful) and I was trying to replicate the 'recording' circle.
I slightly modded the wiki's drawpoly example that creates a circle (pretty terribly because I'm atrocious at maths), and it seems okay, except there is a slight gap (about one or two segments) when the circle gets drawn. How would I fix this and draw it in a more proper way?
[CODE]
local Tex_white = surface.GetTextureID( "vgui/white" )
local function DrawPercentageCircle( x, y, radius, seg, progression )
local cir = { [1] = { x = x, y = y } }
local cir2 = { [1] = { x = x, y = y } }
for i = 0, seg do
local a = math.rad( ( i / seg ) * -360 )
cir[#cir+1] = { x = x - math.sin( a ) * radius, y = y - math.cos( a ) * radius }
end
for i = 0, progression do
table.insert( cir2, cir[next(cir)+1] )
table.remove( cir, next(cir)+1 )
end
surface.SetTexture( Tex_white )
surface.SetDrawColor( 255, 0, 0, 255 )
surface.DrawPoly( cir )
surface.SetDrawColor( 0, 0, 0, 255 )
surface.DrawPoly( cir2 )
end
[/CODE]
-snip-
I'm just bad at math, one minute it works, another it doesn't. I'll do more testing.
Bump, anyone know?
[code]
function surface.DrawSector(x, y, r, ang, rot)
local segments = 360
local segmentstodraw = 360 * (ang/360)
rot = rot* (segments/360)
local poly = {}
local temp = {}
temp['x'] = x
temp['y'] = y
table.insert(poly, temp)
for i = 1+rot, segmentstodraw+rot do
local temp = {}
temp['x'] = math.cos( (i*(360/segments) )*(math.pi/180) ) * r + x
temp['y'] = math.sin( (i*(360/segments) )*(math.pi/180) ) * r + y
table.insert(poly, temp)
end
surface.DrawPoly(poly)
end
[/code]
r for radius in units, ang (0-360) for angle of the sector in degrees, rot for the rotational offset of the sector in degrees.
[QUOTE=Arizard;48443655][code]
function surface.DrawSector(x, y, r, ang, rot)
local segments = 360
local segmentstodraw = 360 * (ang/360)
rot = rot* (segments/360)
local poly = {}
local temp = {}
temp['x'] = x
temp['y'] = y
table.insert(poly, temp)
for i = 1+rot, segmentstodraw+rot do
local temp = {}
temp['x'] = math.cos( (i*(360/segments) )*(math.pi/180) ) * r + x
temp['y'] = math.sin( (i*(360/segments) )*(math.pi/180) ) * r + y
table.insert(poly, temp)
end
surface.DrawPoly(poly)
end
[/code]
r for radius in units, ang (0-360) for angle of the sector in degrees, rot for the rotational offset of the sector in degrees.[/QUOTE]
Thanks for this, but drawing a circle with a 360 radius looks like it would if the radius was 359. Any ideas why?
Sorry, you need to Log In to post a reply to this thread.