-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: if bounding box not available use bounding sphere for raycast hit #347
Conversation
Thanks for making a new PR! For the sake of proper first-hit optimization and making things easier to follow I think it would be best to compute the distance to the sphere and to the bounding box (assuming both exist) and then using the longest distance in the sort array. This is so we make sure we use the distance that best reflects the sub tile and ensures we check the closest tile first. It should also help compartmentalize the distance computations so they're simpler to follow. Thanks again for the work and your patience - If this doesn't make sense I'll try to take a look at adjusting the logic here when I get a chance over the next week. |
@gkjohnson that makes sense to me I am more than happy to add those changes. I will push up the new logic sometime today! Always appreciate the help you provide! |
@gkjohnson I have added a new utility function to calculate the distance just to simplify the code. I kept the logic that if the bounding sphere exists and raycast misses, we quit early and continue to the next tile. |
Thanks for the work - I've just pushed some changes to rework it to address some issues. This is a fairly sensitive piece of code so I want to make sure everything looks right. Do you mind taking a look and testing it out on your sphere bounding volume tileset when you get a chance? |
@gkjohnson was able to test it this morning using my sphere volume set and it worked as expected. I was able to test on both sphere volume and box volume sets successfully. |
Thanks! Just noticed it should have been using |
Related to #334
The following code runs as follows:
Now we can run the normal logic of saving a raycast hit only using the bounding sphere raycast hit if the bounding box does not exist (if bounding box exists we will still use that as primary hit detection).
Previously if a bounding box did not exist we would assume the raycast missed. The logic now states that if a bounding box does not exist, the bounding sphere is assumed to be the tightest bounding volume and a valid intersect results in a hit. If the bounding box does exist that will still require an intersect in the bounding box for a valid hit, even if the bounding sphere has an intersect.