Sphere bounding boxes algorithm

Getting there. The math is correct, but something is wonky with the Z-coordinates and the zoom on the image itself, so I had to hardcode in a few adjustments. However, it should be sufficient for what I need to do. Next: triangle bounding boxes. 

Note that for the ray-line intersection I basically normalized each ray and tried to see if it was in between the two vertices, within a small margin of error. Here is my math:






A few code snippets...



I suspect the small error margin occurred because of me flattening down the points in this manner. 




I hate hardcoded offsets...This is what I get for trying to flatten things. But again, this function shouldn't be necessary for anything other than the screen visualization, so the math can be a little wonky and as long as the numbers are correct...it shouldn't matter.  



I also wrote some unit tests after handwriting out my test cases. Due to Java's extreme degree of precision, I had to make a few small changes. And as always, here's the GitHub repo.

And finally, the result...It's not perfect, but this + the unit tests passing both show me that I'm on the right track. 



601 midterm tomorrow, and a lot more to do in general…time to get some rest then attack it all again. 

Comments

Popular posts from this blog

Unleashing my inner Disney Princess ✩₊˚.⋆☾⋆⁺₊✧ at the 2024 Disney Princesses Half Marathon

The 20-something types of Computer Science majors

The Evenstar