Tangent fix (#43)
* Fixed tangent mis calculation * fixed possible error null reference
This commit is contained in:
@@ -315,6 +315,10 @@ do -- INIT UTIL
|
||||
|
||||
---@param points Array<Vec2>
|
||||
function UTIL.enlargeConvexHull(points, meters)
|
||||
if points == nil or #points == 0 then
|
||||
return {}
|
||||
end
|
||||
|
||||
---@type Array<Vec2>
|
||||
local allpoints = {}
|
||||
|
||||
@@ -383,6 +387,10 @@ end
|
||||
---@return Array<Vec2>
|
||||
function UTIL.GetTangentHullPointsFromOrigin(hull, origin)
|
||||
|
||||
if hull == nil or #hull <= 0 then
|
||||
return {}
|
||||
end
|
||||
|
||||
local function orientation(a, b, c)
|
||||
-- Returns >0 if c is to the left of ab, <0 if to the right, 0 if colinear
|
||||
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
|
||||
|
||||
@@ -222,6 +222,7 @@ function BattleManager:GetRandomPoint(origin, groups)
|
||||
|
||||
local hulls = Spearhead.Util.getSeparatedConvexHulls(points, 50)
|
||||
local hull = Spearhead.Util.randomFromList(hulls) --[[@as Array<Vec2>]]
|
||||
if not hull then return nil end
|
||||
local enlargedHull = Spearhead.Util.enlargeConvexHull(hull, 25)
|
||||
local shootPoints = Spearhead.Util.GetTangentHullPointsFromOrigin(enlargedHull, origin)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user