Join GitHub today
Sprite: Fix raycast bug #8424
Raycasting with sprites is an approximation in that the sprite is treated as a disk. In addition, sprites can be non-square, and can be rotated.
With this change, if the sprite is square, the "clickable" region is inside the inscribed circle. If the sprite is non-square, the approximation is not very good, but it is better than before.
The current implementation treats the sprite as a disk. So the only free parameter is the disk radius. With this implementation, the clickable region is pi / 4 ~ 80% of the area -- only the corners are missed. If the sprite has a disk-shaped texture, this implementation is exact.
If the radius is large enough to cover the entire sprite, the clickable region is 2pi / 4 ~ 160% of the area. This leads to a lot of false positives, and can select the wrong sprite.
I would consider this a stop-gap measure.
referenced this pull request
Mar 21, 2016
added a commit
this pull request
Mar 21, 2016
Sprites are just two triangles. So it seems it would be easy to properly recast against them -- ignoring the sprites' transparent regions, if any.
Thing is, sprites always face the camera. So it is probably easiest to raycast in camera space, instead of world or local space. But that means the raycaster ray needs to be mapped to camera space, and our current design does not allow for that.
So a refactoring is in order, if someone is interested in tackling this.