Team Spartan Cookies & Milk Forums
Polygon Help needed - Printable Version

+- Team Spartan Cookies & Milk Forums (https://teamscm.co.uk)
+-- Forum: Garry's Mod (https://teamscm.co.uk/forum-4.html)
+--- Forum: Starfall (https://teamscm.co.uk/forum-7.html)
+--- Thread: Polygon Help needed (/thread-1469.html)



Polygon Help needed - Destiny's Player - 08-12-2015

Basically, I need to somehow make a function which would automatically create a polygon and an outline of lines around it. Here's what I have so far.

function Draw(press,ptable,col,alpha)
local Polygon = render.createPoly(--something)
if press == 1 then
render.setColor(col[1]+20,col[2]+20,col[3]+20,alpha)
else
render.setColor(col[1],col[2],col[3],alpha)
end
render.drawPoly(Polygon)

render.setColor(255,255,255,alpha)
for i=1,#ptable do
--render.drawLine
end
--[[render.drawLine(p1x,p1y,p2x,p2y)
render.drawLine(p2x,p2y,p3x,p3y)
render.drawLine(p3x,p3y,p4x,p4y)
render.drawLine(p4x,p4y,p1x,p1y)]]
end

And I can't figure out, what to do to actually make it work. Mostly, I can't figure out how to make the polygon work... Can you even compose a polygon in multiple steps? ptable can be input in any way possible, right now I'm thinking about having tables within tables with both x and y in each slot.


RE: Polygon Help needed - Person8880 - 08-12-2015

Well first of all, render.createPoly is not something you need to or should be using. It's a leftover from old and bad code that was over paranoid with polygons.

All you need for a polygon is a table like this:
{
{ x = 0, y = 0, u = 0, v = 0 },
{ x = 10, y = 0, u = 1, v = 0 },
{ x = 10, y = 10, u = 1, v = 1 },
{ x = 0, y = 10, u = 0, v = 1 }
}

Compose it however you want. If you want lines to go around the outside, then you just have to connect the dots between your polygon vertices.


RE: Polygon Help needed - Destiny's Player - 08-12-2015

Thanks! I was not aware of that. It all works now, just finished replacing all of my previous mess with that lone function.