1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 09:23:54 +00:00
openmw/files/builtin_scripts/openmw_aux/util.lua

32 lines
1.2 KiB
Lua

-------------------------------------------------------------------------------
-- `openmw_aux.util` defines utility functions that are implemented in Lua rather than in C++.
-- Implementation can be found in `resources/vfs/openmw_aux/util.lua`.
-- @module util
-- @usage local aux_util = require('openmw_aux.util')
local aux_util = {}
-------------------------------------------------------------------------------
-- Finds the nearest object to the given point in the given list.
-- Ignores cells, uses only coordinates. Returns the nearest object,
-- and the distance to it. If objectList is empty, returns nil.
-- @function [parent=#util] findNearestTo
-- @param openmw.util#Vector3 point
-- @param openmw.core#ObjectList objectList
-- @return openmw.core#GameObject, #number the nearest object and the distance
function aux_util.findNearestTo(point, objectList)
local res = nil
local resDist = nil
for i = 1, #objectList do
local obj = objectList[i]
local dist = (obj.position - point):length()
if i == 1 or dist < resDist then
res = obj
resDist = dist
end
end
return res, resDist
end
return aux_util