Skip to content
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

Merged
merged 4 commits into from
Jun 10, 2023

Conversation

jesse-small
Copy link
Contributor

@jesse-small jesse-small commented Jun 5, 2023

Related to #334

The following code runs as follows:

  • Check bounding sphere for raycast hit
    • If raycast miss, continue to next tile
  • Check if bounding box exists
    • If bounding box exists, check for raycast hit
      • If raycast miss, continue to next tile
  • If we haven't continue to next tile that means either 1) bounding sphere had a raycast hit and bounding box does not exist or 2) bounding box exists and had a hit

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.

@gkjohnson
Copy link
Contributor

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.

@jesse-small
Copy link
Contributor Author

@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!

@jesse-small
Copy link
Contributor Author

@gkjohnson I have added a new utility function to calculate the distance just to simplify the code.
Now if the bounding sphere raycast hits, it will calculate the distance and add it to the array, if the bounding box exists and raycast hits it will also add it to the sorted array.

I kept the logic that if the bounding sphere exists and raycast misses, we quit early and continue to the next tile.

@gkjohnson
Copy link
Contributor

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?

@jesse-small
Copy link
Contributor Author

@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.

@gkjohnson
Copy link
Contributor

Thanks! Just noticed it should have been using max instead of min so I made that change. Thanks again for your help!

@gkjohnson gkjohnson merged commit 610fbe0 into NASA-AMMOS:master Jun 10, 2023
2 checks passed
@gkjohnson gkjohnson added this to the v0.3.19 milestone Jun 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants