• Finding Opposite Position?
    3 replies, posted
How would I go about finding the exact opposite position of a polygon? (I''ve drawn a polygon and I want the exact same one but flipped on the other side of the screen.)
[lua] function ReversePoly(polydatatbl) local centerx = ScrW() * 0.5 local centery = ScrH() * 0.5 local newpolytbl = {} for index, coords in pairs(polydatatbl) do local newxpos = centerx - coords[x] local newypos = centery - coords[y] newpolytbl[#newpolytbl+1] = {newxpos, newypos} end return newpolytbl end -- DEMO local triangle = { { x = 100, y = 200 }, { x = 150, y = 100 }, { x = 200, y = 200 } } local tri2 = ReversePoly(triangle) hook.Add("HUDPaint", "PolygonTest", function() surface.SetDrawColor(255, 0, 0) draw.NoTexture() surface.DrawPoly(triangle) surface.DrawPoly(tri2) end) [/lua] untested (setting up srcds :v:) [editline]value[/editline] [QUOTE=OzymandiasJ;46331733]You really shouldn't be calling "RevesePoly" every frame tho, like seriously.[/QUOTE] True, updated code
You really shouldn't be calling "RevesePoly" every frame tho, like seriously.
Have that reverse poly thing print out the new X and Y variables then you should copy those
Sorry, you need to Log In to post a reply to this thread.