OBBsquaredDistance
Definition
-- @/lua/common/mathlib.lua:1367
function OBBsquaredDistance(c1, x1, y1, z1, p)
tmpv1:setSub2(p, c1)
local x1sql, y1sql, z1sql = x1:squaredLength(), y1:squaredLength(), z1:squaredLength()
local a, b, c = tmpv1:dot(x1), tmpv1:dot(y1), tmpv1:dot(z1)
if abs(a) < x1sql and abs(b) < y1sql and abs(c) < z1sql then return 0 end -- fix small r2 num accuracy
a, b, c = min(max(a/max(x1sql, 1e-30),-1),1), min(max(b/max(y1sql, 1e-30),-1),1), min(max(c/max(z1sql, 1e-30),-1),1)
return square(a*x1.x+b*y1.x+c*z1.x-tmpv1.x) + square(a*x1.y+b*y1.y+c*z1.y-tmpv1.y) + square(a*x1.z+b*y1.z+c*z1.z-tmpv1.z)
end
Callers
@/gameplay/missionTypes/delivery/customNodes/VehicleInTargetAreaNode.lua
updateData.bbHalfAxis2:set(be:getObjectOOBBHalfAxisXYZ(id, 2))
local dist = OBBsquaredDistance(updateData.bbCenter, updateData.bbHalfAxis0, updateData.bbHalfAxis1, updateData.bbHalfAxis2, center)
if dist <= sqrDist then
@/lua/common/mathlib.lua
function overlapsOBB_Sphere(c1, x1, y1, z1, c2, r2)
return OBBsquaredDistance(c1, x1, y1, z1, c2) <= r2*r2
end