vrld / HC

General purpose collision detection library for the use with LÖVE.
http://hc.readthedocs.org/
404 stars 48 forks source link

Suggestion: `shapesAtPoint(x, y)` or `shapesCollideWith(shape)` functions that operate instantaneously and guarantee their arguments are transient #59

Closed ghost closed 5 years ago

ghost commented 6 years ago

Use-case: I'd like to make a game that uses clicking-and-dragging as a core UI element. I'm looking for a clean, efficient way to determine whether the user has clicked an item, and I thought HC would make a good basis for this; the spatial hash should let the program focus only on the likely candidates for clicking instead of iterating over them all to find matches.

But, there's no direct support for this use-case. I can imagine other use-cases that are similar in scope to this, for example "instantaneous area-of-effect thing happens; which shapes are affected?".

The suggested methods would return a list of shapes that collide with or intersect a specified point, or with a shape specified on-the-fly without adding the shape to the spatial hash.

I'm aware the hash uses weak refs, but there's no guarantee that transient shapes will be destroyed promptly, which undermines these use cases.

ghost commented 6 years ago

Ah, I see there may already be support for the former case in #8? That wasn't in the docs at RTD yet, so I didn't see it! That probably solves my immediate use-case, though the instantaneous-shapes bit might still be useful.

vrld commented 5 years ago

Better late than never...

weakman54 commented 5 years ago

So the shapesCollideWith(shape) function is not being added?

vrld commented 5 years ago

How would it differ from HC.collisions(shape)?

weakman54 commented 5 years ago

Oh, no, that's true, but there is still the question of setting up collision shapes "on the fly", I'm not sure exactly what @cathalgarvey means by "instantaneous-shapes", but I'm guessing it would be useful for doing for examle selection boxes, as the use case there is very "on the fly".

As it is currently, a rect shape needs to be defined beforehand, and then manipulated into the correct shape/position whenever you want to use it.

Something similar to HC.shapesAt(x, y), but for rectangles (or arbitrary shapes). Basically, a way to query the world without adding to it.

EDIT: related property that seems relevant to the issue is the fact that the collision detection is one way, I'm checking "which shapes collide with queryShape", but never "does otherShape collide with queryShape".

D0NM commented 5 years ago

I keep a global set of special shapes to use them for similar checking w/o moving of the shapes of units.