I have managed to calculate the bounding sphere radius in two ways, but none is giving me exactly what I want. I don't need a "pixel" perfect bounding sphere but I would like something better than what I currently have.
I'm using Wavefront .obj models and to calculate the bounding sphere radius for those models I extract the current model dimensions (I'm using the GLM library from Nate Robbins) which will give me the dimension on each axis.
First approach: Divide each axis by 2 and that will give me the radius on each axis. The largest is the one I'll use for my bounding sphere. This will work for most objects specific to my project. It will not work for some, like cube-shaped ones. Basically, if I have a cube and calculate the radius with this approach, the sphere will leave the cube corners outside.
Second approach: Divide each axis by 2 and that will give me the radius on each axis. Then I do this to take out the radius for the bounding sphere:
r = SQRT(x*x + y*y + z*z)
But this gives me a pretty large radius. The object will be totally enclosed in the sphere but the sphere is pretty large, more than it should be.
I don't understand what I'm doing wrong in the formula above, as far as I know it, it should work. But I'm obviously wrong...