Closed sixFingers closed 8 years ago
Forgot to document: you would call the method this way:
local intersections = hash:intersectionsWithSegment(startX, startY, endX, endY)
.. then you would iterate the results like:
for _, intersection in ipairs(intersections) do
-- t = ray parameter
-- x, y = intersection point
-- shape = intersecting shape
local shape, t, x, y = unpack(intersection)
@vrld Hi, just pinging to check if this PR is being considered useful. I keep cloning from here :)
Sorry, I've been quite busy the past few weeks.
This looks tremendously useful! Thanks :+1:
Oh well, you did the work. I just juggled with what you made available :)
Thanks again for the wonderful library, 90% of my game is Hardon Collider. Nonetheless, i often miss the ability to rapidly cast a ray and get a list of collisions ordered from the origin of the ray toward the ray's direction. This would complement well the other side of the api (which tells: given a shape, give me ray intersections).. with a "given a ray, give me the shapes". I'm proposing a very simple addition to the code. May be not optimized, but works fast enough for me. The pr only includes a single method for the
Spatialhash
class,intersectionsWithSegment
which tries to mimickShape
'sintersectionsWithRay
. It's called "with segment" since only the points lying on the given segment will be returned.