1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-12-12 17:13:07 +00:00

Add range to "aux_util.findNearestTo".

This commit is contained in:
Petr Mikheev 2022-01-31 22:40:27 +01:00
parent 93b3b9df90
commit 899199c8ed

View file

@ -13,19 +13,24 @@ 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
return res, resDist if res and (not maxDist or resDist <= maxDist) then
return res, resDist
end
end end
return aux_util return aux_util