# D3DXComputeBoundingSphere issue

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

## Recommended Posts

##### Share on other sites
I'm not quite sure why you would compute a bounding sphere on a ground or sky model, but because it works with those and not world "objects", I would suspect something in the difference between how you load a sky or ground model versus how you load the "world object" models. Can you show the general flow of the code or some snippets? Do you use the exact same functions for loading sky, ground, and the other models?

Chris

##### Share on other sites
i dont really want it for sky or ground it is just in all objects loading < all x files are loaded the same > as a test for now.

i load the object from a file.
m_pMesh

clone it to a specific FVF format for my terrain following < which follows but wont render and the regular object renders but wont follow...go figgure >
m_pColMesh

then i loop through the textures and materials of the x model.

then load 2 more versions of the model low res and med res.
m_pMeshLow
m_pMeshMid

then i compute the sphere for the m_pMesh

everything works fine for the sky.x, ground.x, and tiny.x. i found that my building2.x seems to work too but its radius is only 1 and should be much more 1. but the models tree3.x and rattling.x all have 0 radius and 0,0,0 for center

##### Share on other sites
i found that even the default tiger mesh wont compute a bounding radius or center just a radius of 1 and a center of 0,0,0

##### Share on other sites
not to hijack your thread, but I was having a few issues with computing bounding box's myself, which is about the same as the bounding spheres (fucntion wise).

I was wondering how you do you get the D3DVECTOR3* to the first position (the first parameter). I thought I could just use the vertex buffer for this, but am running into issues (its blowing up when I call D3DXComputeBoundingBox()).

Here's what I was trying...
// pMesh is an ID3DXMesh *			// Calculate the bounding volume of the object.  result = D3DXComputeBoundingBox( (D3DXVECTOR3*)pBuffer,                                pMesh->GetNumVertices( ),		   		pMesh->GetNumBytesPerVertex( ),   				&tempMin, &tempMax );           // D3DXVECTOR3's

If you could point me in the right direction, I'd appreciate it.

##### Share on other sites
Well i read this from the Toymaker.info and have used it to make my bounding box code pretier but still no go.

BYTE* pVertices=NULL;

if (FAILED(hr))
return FALSE;

D3DXVECTOR3 minBounds,maxBounds;

D3DXComputeBoundingBox((D3DXVECTOR3*)pVertices, m_mesh->GetNumVertices(), D3DXGetFVFVertexSize(m_mesh->GetFVF()), &minBounds, &maxBounds);

m_mesh->UnlockVertexBuffer();

also on a side note any of my meshes will load in his bounding demo and will collide correctly.

##### Share on other sites
Awesome, thank you much. That fixed my problem. :)

##### Share on other sites
well since i cant help my self im glad i helped you.

i dont know why some of my meshes will load fine and compute bounding. maybe i can try using boxes instead...i dont know.

##### Share on other sites
Or you could make your own function to calculate it, it's not that hard.

Anyways, the only problems I can think of are:
- Maybe you're not pointing to the position item in the pFirstPosition argument.
- Maybe you're not passing the right number of vertices to the function (i.e. passing the number of vertices of the low poly model)
- Are you sure you're passing the right stride into the function?

##### Share on other sites
well i assume that i am passing the correct stride. i have tried cloning the meshes to a specific FVF and using that but never seems to work correctly. I will look into refining the model loading code and check that out first. i think i might have fixed another issue i was having with loading models for colllision tests and can remove my collisionModel from the memory and just act on the models.

Also i read in an article how alot of games use the lowest res model for collision testing since it will be alot faster to check half the vert's and faces.

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631787
• Total Posts
3002351
×