tophat2d / tophat

:tophat: a 2d game library for Umka

Home Page:https://tophat2d.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ray collision: wrong end of the collision is detected

skejeton opened this issue · comments

commented

image
In the ray collision test, my cursor is at the bottom left side of the ray, but the collision is detected on the adjacent edge.

While your solution is a fix, I don't think that's the correct solution. I think we should report both of the collisions.

In a collision between a line and a quad, there will be between 0 and 2 collisions. So the proposed API is that the user will pass a second ic pointer, which will either be filled with a value (2 collisions), the same as the first ic (1 collision) or it's value will be undefined (no collisions).

https://github.com/marekmaskarinec/tophat/blob/d3c82fb7e29c144fed4ba99b86a2d8432aa5b529/src/collisions.c#L16-L22

Implementing this is very easy. I think the second point is calculated the same as the first, but using uB instaed.