Skip to content

Commit

Permalink
Add isBoxIntersectingSphere (#1856)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZH-Hristov authored Sep 19, 2024
1 parent 211813b commit 48fb79f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lua/starfall/libs_sh/trace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ function trace_library.intersectRayWithOBB(rayStart, rayDelta, boxOrigin, boxAng
if pos then return vwrap(pos), vwrap(normal), fraction end
end

--- Performs a box-sphere intersection and returns whether there was an intersection or not.
-- @param Vector boxMins The minimum extents of the World Axis-Aligned box.
-- @param Vector boxMaxs The maximum extents of the World Axis-Aligned box.
-- @param Vector spherePos Position of the sphere.
-- @param number sphereRadius The radius of the sphere.
-- @return boolean true if there is an intersection, false otherwise.
function trace_library.isBoxIntersectingSphere(boxMins, boxMaxs, spherePos, sphereRadius)
vec_SetUnpacked(minbox_vec, boxMins[1], boxMins[2], boxMins[3])
vec_SetUnpacked(maxbox_vec, boxMaxs[1], boxMaxs[2], boxMaxs[3])
vec_SetUnpacked(origin_vec, spherePos[1], spherePos[2], spherePos[3])
return util.IsBoxIntersectingSphere(minbox_vec, maxbox_vec, origin_vec, sphereRadius)
end

--- Does a ray plane intersection returning the position hit or nil if not hit
-- @param Vector rayStart The origin of the ray
-- @param Vector rayDelta The direction and length of the ray
Expand Down

0 comments on commit 48fb79f

Please sign in to comment.