// this is best read with a monospace font as it makes some ascii diagrams // polygons are basically what they are in computer graphics and geometry - a set of 3d points that connect together to create a shape. // theyre mainly used in NotITG to create shapes procedurally, something useful for doing some visual effects that required 3d models or just general shapes without images/models // to start off, to define a polygon youll want to use something like this: // this will define a polygon with no attributes. you can define attributes to it like vertex count (points of the polygon) like so: // it doesnt matter which one you do since you can define all of the attributes in lua later on // to actually use the polygon, youll have to either put the code that controls it in an InitCommand or use it elsewhere in your code // DO NOTE: please dont modify vertex positions every frame! this will make it do it on the cpu in lua code which is dumb, straining, and can result in crashes and av's. please use vertex shaders instead!! // you can first specify the amount of vertices with mypolygon:SetNumVertices(count) // and then to set the position of these polygons youd want to use a for loop like this: for i = 1, count do -- first we set the position mypolygon:SetVertexPosition( i - 1, -- the index of the vertex, basically its count. its 0-indexed, meaning youd want to subtract 1 from a standard lua for loop math.sin(i / count * math.pi), -- the x position math.cos(i / count * math.pi), -- the y position -- the configuration here makes it a circle, and the more vertices you specify the higher "quality" itll have 0, -- theres also the z position, but its rarely ever used because polygons are most commonly used for 2d shapes rather than full-on 3d shapes. youd ideally want to use models for those, but you do you ) -- set the color mypolygon:SetVertexColor(i - 1, 1, 0, 0, 1) -- r, g, b, a end // you can also set the polygon mode, which changes it to be either filled in or wireframe-d mypolygon:SetPolygonMode(0) -- for filled in mypolygon:SetPolygonMode(1) -- for wireframe // polygons also have a bunch of drawmodes which define what really "defines" the shape that they have. lets go through them one by one: // in these explanations ill be using examples: "i0" means index 0 mypolygon:SetDrawMode('triangles') // this renders your polygon in triangles; i0, i1 and i2 will connect to form a triangle, then i3, i4 and i5 will connect to form a triangle, etc etc. [citation needed?] // // i0 - i1 // \ / // i2 mypolygon:SetDrawMode('quads') // this is similar to triangles, but instead for rectangles; i0, i1, i2 and i3 will connect to form a rectangle, i4, i5, i6 and i7 will connect, etc [also citation needed? ive never used both but i think this is what they do] // // i0 - i3 i4 - i7 // | | | | // i1 - i2 i5 - i6 mypolygon:SetDrawMode('quadstrip') // this one tries to form a connected set of rectangles based on what vertices you define. its a bit hard to explain: // say we have i0, i1, i2 and i3 in the shape of a rectangle. quadstrip will form a rectangle // if you add i4 and i5 that make i2, i3, i4 and i5 connect into a rectangle then it will add onto the shape, making it one long shape // // i0 - i3 - i4 // | | | // i1 - i2 - i5 // // this will keep stacking onto itself over and over. im pretty sure this is how holds are rendered in itg and how luafields usually handle rendering holds mypolygon:SetDrawMode('fan') // this will form a literal fan. you define i0, the middle point, and then every index will connect to the next/previous index and also i0 // // i0-------i1 // | '. / // | '. / // | .i2 // | .'' // i3 mypolygon:SetDrawMode('strip') // i, honestly dont quite understand what this one does. but it doesnt seem too useful // // i0 no i2 // diagram // sorry // i3 :( i4 mypolygon:SetDrawMode('linestrip') // this is basically just hey google, draw me a line // // i0 i3 ---- i4 // \''.... | | // \ '''|''... | // i1 ---- i2 ''i5 // theres also textures, accompanied by normals, but i havent *quite* figured out how those work so my legal team does not allow me to speak of them