FlightControl-Master / MOOSE

Mission Object Oriented Scripting Environment (MOOSE) for lua mission scripting design in DCS World
http://flightcontrol-master.github.io/MOOSE/
GNU General Public License v3.0
290 stars 94 forks source link

Update on the ZONE_POLYGON class, so we can finally use it with drawings made in the Mission Editor as well #2054

Closed nielsvaes closed 9 months ago

nielsvaes commented 9 months ago

Supports closed line segments, rects and freely drawn polygons.

Added the correct way of generating a point within a polygon with trial and error

Added a way to get the surface area.

Added a helper class (_ZONE_TRIANGLE), which shouldn't ever be used on its own. It's there to support the update ZONE_POLYGON.

Some test code, assuming there's a poygon drawn in the mission editor called "poly":

-- make a new zone from a drawing
poly = ZONE_POLYGON:NewFromDrawing("poly")
-- draw the zone for everyone, include the individual triangles that make up the polygon
poly:DrawZone(-1, {1,0,0}, 1, {1,0,0}, 255, 4, false, true)
-- generate 500 random points, evenly distributed in the polygon
for i=1, 500 do
    COORDINATE:NewFromVec2(poly:GetRandomVec2()):CircleToAll(1000)
end

-- remove the drawing from the game
poly:UndrawZone()