Archived

This topic is now archived and is closed to further replies.

Bounding Sphere Too Big

This topic is 5145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For some of my meshes, D3DXComputeBoundingSphere returns a sphere that is grossly too big and not centered correctly. Sometimes it comes out ok - on some simple cube meshes, for example. The meshes were created in MilkShape3D and exported to .x format. I actually create a sphere mesh based on the bounding sphere center/radius data, so I can see them. Has anyone encountered this problem before?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Haven''t seen this. Is your mesh centered around the origin? It may be that it has to be (that''s usually a good idea, anyway).

Share this post


Link to post
Share on other sites
The meshes are not all centered around the origin. Is there a reason they must be? Is it standard practice?

In Milkshape, I don''t think there''s a way, when you''re done with a model, to tell it to center the whole thing around the origin.

Share this post


Link to post
Share on other sites
I''ve done some experimenting since I first posted.

1) I created a sphere in Milkshape and tested it both centered and uncentered. The bounding sphere came out fine each time. The sphere is about 80x80, and D3DXComputeBoundingSphere returns a radius of about 41 - a good fit.

2) I then added a small cylinder at the top of the sphere - about 5 or 10% of the total height (the model looked a bit like a christmas ornament). The bounding sphere for this model, whether centered or not, was much bigger than it needed to be. This model is about 80x90 - only slightly bigger, but D3DXComputeBoundingSphere now gives a radius of 65.

What gives?

Share this post


Link to post
Share on other sites
the radius is getting bigger simply becuz the model is getting larger...if u have a sphere with some radius...its bounding sphere will be nice...but add a stick to this sphere and the radius of the bounding sphere must be big enough to completely encircle the entire object...for some objects that are narrow or long in one direction it is better to use bounding boxes

Share this post


Link to post
Share on other sites
Yes, the sphere should get bigger. But the problem is that it is getting too big, and it is not centered properly.

I''m wondering if there is something wrong with the .x file exporter from Milkshape or something. Perhaps some stray vertex or normal or something is throwing the bounding sphere calculations off. I don''t know. It''s making me mad.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
if your models are static the whole game why dont'' you just calculate the boudnign sphere in milkshape when u make the model? make a sphere and then delete it after you write down its properties

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
SDyer, i had the same problem. the sphere was always ~10% larger than what i thought it should be. and even the sphere center was incorrect. there are different types of bounding spheres so maybe the one they calculate is different than the one i''m used to. what i ended up doing was creating a bounding sphere based upon the min/max returned from the bounding box function, which i''ve never had a problem with.

Share this post


Link to post
Share on other sites
Can''t you calculate your own sphere? It''s quite easy. First you find the center of the mesh by finding the min/max values for x/y/z then halving each. Then you find the vertex that is farthest away from that point, and the distance from the center to that point should be your radius. Right? Am I missing something?

Share this post


Link to post
Share on other sites
I did try making my own spheres, based on the bounding box. They were a bit small, though, as I was using half the distance between the min/max points as the radius.

Aikon - I will try your method of getting the center, then determining the radius by scanning all vertices in the mesh. That ought to do it.

I''d still like to know, if anyone knows, why the DirectX function is not working as expected.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''ve had a similar problem to the one you describe where vastly larger bounding spheres were being created. I was also getting a problem with bounding boxes. After checking the .x file in txt format I found the values for the bb min to actually be a tex coordinate (I know this because it was the only -25.0 val in the file).

This made me suspicious of the FVF descriptor generated so I changed the FVF size to what I thought it should be in the CreateBoundingSphere call, and this seems to have fixed the problem altogether.

I don''t know if it''s the same as your problem, but it could be worth investigating.

Share this post


Link to post
Share on other sites
For very tight encompassing spheres, I''d have a look at this code of the day on Flipcode:

http://www.flipcode.com/cgi-bin/msg.cgi?showThread=COTD-SmallestEnclosingSpheres&forum=cotd&id=-1

This is generally a very robust (and quick) way to find the smallest encompassing bounding sphere of any arbitrary mesh.

Share this post


Link to post
Share on other sites
D3DXComputeBoundingSphere computes the center of the sphere as some sort of average of all vertices in the mesh. Therefore, if one side of the mesh has a high density of vertices, the center will be weighed towards that side.

D3DXComputeBoundingSphere works better for meshes whose vertices are more evenly distributed. If the vertex distribution is not even, you might consider using D3DXComputeBoundingBox to find the center, then compute the radius yourself using that center.

Share this post


Link to post
Share on other sites