1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

Merge branch 'lua_aux_util' into 'master'

Add range to "aux_util.findNearestTo".

See merge request OpenMW/openmw!1620
This commit is contained in:
uramer 2022-02-01 22:37:16 +00:00
commit f873703bdb

View File

@ -13,20 +13,25 @@ local aux_util = {}
-- @function [parent=#util] findNearestTo -- @function [parent=#util] findNearestTo
-- @param openmw.util#Vector3 point -- @param openmw.util#Vector3 point
-- @param openmw.core#ObjectList objectList -- @param openmw.core#ObjectList objectList
-- @param #number minDist (optional) ignore objects that are closer than minDist
-- @param #number maxDist (optional) ignore objects that are farther than maxDist
-- @return openmw.core#GameObject, #number the nearest object and the distance -- @return openmw.core#GameObject, #number the nearest object and the distance
function aux_util.findNearestTo(point, objectList) function aux_util.findNearestTo(point, objectList, minDist, maxDist)
local res = nil local res = nil
local resDist = nil local resDist = nil
local minDist = minDist or 0
for i = 1, #objectList do for i = 1, #objectList do
local obj = objectList[i] local obj = objectList[i]
local dist = (obj.position - point):length() local dist = (obj.position - point):length()
if i == 1 or dist < resDist then if dist >= minDist and (not res or dist < resDist) then
res = obj res = obj
resDist = dist resDist = dist
end end
end end
if res and (not maxDist or resDist <= maxDist) then
return res, resDist return res, resDist
end end
end
return aux_util return aux_util