Skip to main content
GameDev.net gamedev.net
🔒 Locked

Bounding box offset

Started by yaneks Jul 31, 2007 at 4:29 PM 4 replies 1.5k views
Original Post
yaneks
yaneks
Hello to everyone! I have problem with mesh bounding box. The problem is when I translate the object in the scene bounding box has an offset so when I render the mesh and bounding box there is offset between them. If I don't translate the mesh and pos(0.0f, 0.0f, 0.0f) then bounding box is fine. When I exported the mesh from 3DMax the world and offset coordinates is 0.0 I just couldn't get it what is wrong whit it... The steps what I'm doing when I loding: 1) D3DXLoadMeshFromX 2) D3DXComputeNormals if necessary 3) Optimize mesh 4) D3DXComputeBoundingBox D3DXCreateBox Do I need to to any transformations or what? Thanks
jollyjeffers
jollyjeffers
You have to transform all data in the same (or relative) manner or they are no longer comparable. Direct3D won't do any automatic transformation and it won't know that the bounding box needs to follow the actual mesh.

You can use D3DXVec3TransformCoord() (iirc) to move the individual bounding box coordinates if you need to do it in software, or you can just render it using the same pipeline configuration.

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
yaneks
yaneks
Well I'm not quite shore about that, because the offset is wrong only on Y axis.
It is almost half size of offset on Y axis.

So do I need to use this function D3DXVec3TransformCoord() every frame when I translate the cube or once when I create and setup the start position of the cube?
jollyjeffers
jollyjeffers
Quote:
Original post by yaneks
So do I need to use this function D3DXVec3TransformCoord() every frame when I translate the cube or once when I create and setup the start position of the cube?
The D3DXVec3TransformCoord() idea will permanently modify the actual data, so you would need to lock-modify-unlock each time the bounding box moves. Chances are this isn't what you'd want if your cube/mesh moves around on a regular basis; instead you should be able to apply the same matrix transform for rendering the mesh to the bounding box mesh you created via D3DXCreateBox().

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
yaneks
yaneks
THANKS
yaneks
yaneks
Now it is fine
SetTransform(D3DTS_WORLD, &(*cIter)->matMatrix);//Mesh matrix
(*cIter)->pMesh->DrawSubset(i);//Render mesh

D3DXMATRIXA16 final = (*cIter)->matBox *(*cIter)->matMatrix;
SetTransform(D3DTS_WORLD, &(*cIter)->matBox );//Box matrix

(*cIter)->pBox->DrawSubset(i);//Render box

this works for static mesh, but not for dynamic mesh when I would like to do the translation and rotation.

Do I need to use some other directX matrix functions?



Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.