Sign in to follow this  

D3DXComputeBoundingSphere issue

This topic is 4554 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

Ok i have like 7 models that are loaded into a model list and then the game spawns objects that link to the model. Everything works fine for drawing and moving and having lots of objects. But now i am trying to do some basic object interactions like selecting a target object and basic collision work and i found an error. I have code included that uses D3DXComputeBoundingSphere to give me the center of the object and its radius for ray to sphere intersection testing before i check ray to triangle of the model. I have an error with some models and not others. So to debug i added output information durring the loading of models and instancing of creatures. It apears that the tiny.x model and my sky.x and ground.x models all load and compute proper bounding spheres but my rattling.x and tree3.x all have radius 0 and center 0,0,0. I even have it checking for HRESULT failures in all parts of the bounding sphere creation and get no failures just get zero's for the results. It thinks it is working but computes nothing. Any ideas why? could it be bad models, bad code, or bad DX8.1?

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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;

hr=m_mesh->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)&pVertices);
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
this is driving me nuts. The same exact peice of code is called to load each model and compute the bounding center and radius for each model. I have it set to output the results and any errors but i get no errors and it always says the center is 0,0,0 and radius 1 for every model except the Tiny.x from dxsdk and my homemade models skydome.x and ground.x.

I thought it might be something due to the size of the models and made a humongous rat model and it simply drew a humongous rat with a radius of 1 and center 0,0,0 i even tried moving the model away from its axis so that the center could not be 0,0,0

Share this post


Link to post
Share on other sites
i think i may have figured this one out.

Seems that my modeler program defaults to a size that is really small. I always had to scale the model up in my program and that was the problem. It seems that D3DXComputeBoundingSphere didn't return an error if the model was very small it just pretened that it didnt have any dimensions. I scaled the model in the editor to about 10x its size and it gets collisions right now.
which is sad since i have to reduce the model size in the game to make them all fit together.

Share this post


Link to post
Share on other sites
That's funny. I was just about to suggest that as I neared the end of the thread, because I knew that the tiny.x model used a pretty large scale. That is a good reason to have models all created with the same scale in the modeling program. i.e. 1 unit always equals 1 inch or foot or meter. If the D3DX computations aren't working for your scale, then you can easily write your own. Just loop through all vertices and keep track of the lowest and highest ones.

Chris

Share this post


Link to post
Share on other sites
yeah i was using the tiny model and the seafloor.x model's to begin testing. Tiny never fit until she was reduced to 0.15 of her size. All my models where based on that scale and fit to her.

Share this post


Link to post
Share on other sites

This topic is 4554 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this