# D3DXComputeBoundingSphere and D3DXComputeBoundingBox

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

## Recommended Posts

Does anyone here knows what's the math behind this two function? I want to know how it is done.

##### Share on other sites
D3DXComputeBoundingBox is probably something like...

D3DXComputeBoundingBox( list_of_vertices ){     vector min = vertices[0], max = vertices[0];          for_each( vertex in vertices )     {            if( vertex.x < min )                 min.x = vertex.x;            if( vertex.y < min )                 min.y = vertex.y;            if( vertex.z < min )                 min.z = vertex.z;            if( vertex.x > max )                 max.x = vertex.x;            if( vertex.y > max )                 max.y = vertex.y;            if( vertex.z > max )                 max.z = vertex.z;     }     return boundingBox( min, max );}

Then from that you can compute the bounding sphere, i think something like...

boundingBox box = D3DXComputeBoundingBox( my_mesh_vertices );boundingSphere Sphere;Sphere.radius = distance( box.min, box.max ) / 2.0f;

My math isnt that great but it looks right to me.

##### Share on other sites
Hi,

fitfool looks right. But just to add, bounding spheres have a Center point. And it can be calculated by dividing the sum of min and max vectors by 2. Note that min and max points are both in model space. If you want to use'em correctly, you must first multiply'em by model's World Matrix.

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633701
• Total Posts
3013434
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!