Sign in to follow this  

DrawSubset problem

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

i have a very strange problem and it makes absolutely no sense. i have a mesh, and its local bounding box. I use a shader to transform it into world space. This is the function for drawing:: -------------------------------------------------------- //compute a local bouding box from the mesh and draw it //Get localBox NMapVertex* v = 0; m_Mesh->LockVertexBuffer(0, (void**)&v); D3DXComputeBoundingBox((D3DXVECTOR3*)v, m_Mesh->GetNumVertices(), sizeof(NMapVertex), &m_Box.minPt, &m_Box.maxPt); m_Mesh->UnlockVertexBuffer(); D3DXVECTOR3 minVec; minVec.x = m_Box.maxPt.x - m_Box.center().x; minVec.y = m_Box.maxPt.y - m_Box.center().y; minVec.z = m_Box.maxPt.z - m_Box.center().z; minVec *= 2; ID3DXMesh* box; D3DXCreateBox(g_Device, minVec.x, minVec.y, minVec.z, &box, 0); box->DrawSubset(0); box->Release(); ------------------------------------------------------------ //Draw the mesh m_Mesh->DrawSubset(0); i already set the world*view*proj matrix to my shader, but what now happens is very strange. As you can see i draw 2 things, first i calc my local bounding box, build a ID3DXMesh* from it and draw it. The second time i just draw my Mesh. Now correct me if im wrong but after this draw call both meshes should be drawed at the same position, but they are not :S the m_Mesh->DrawSubset(0) draws the mesh around 5 y-pos above the bounding box and i have absolutely no idea why. anyone knows what could cause that problem? (I set no states or anything between these 2 calls and the shader is the same)

Share this post


Link to post
Share on other sites
Quote:
Original post by of_ownage

D3DXVECTOR3 minVec;
minVec.x = m_Box.maxPt.x - m_Box.center().x;
minVec.y = m_Box.maxPt.y - m_Box.center().y;
minVec.z = m_Box.maxPt.z - m_Box.center().z;

minVec *= 2;

ID3DXMesh* box;
D3DXCreateBox(g_Device, minVec.x, minVec.y, minVec.z, &box, 0);


I don't understand this. What is m_Box.center()? does it just return (maxPt+minPt)*0.5 ? I would do it this way:



NMapVertex* v = 0;
m_Mesh->LockVertexBuffer(0, (void**)&v);
D3DXComputeBoundingBox((D3DXVECTOR3*)v, m_Mesh->GetNumVertices(), sizeof(NMapVertex), &m_Box.minPt, &m_Box.maxPt);
m_Mesh->UnlockVertexBuffer();

D3DXVECTOR3 boxDim = m_Box.maxPt - mBox.minPt;

ID3DXMesh* box;
D3DXCreateBox(g_Device, boxDim.x, boxDim.y, boxDim.z, &box, 0);

Share this post


Link to post
Share on other sites
Quote:
Original post by of_ownage
y ehm your right your code is better to understand but i dont think the box creation is the problem ;)


I think it is. The box you create is only half the size of your bounding box. Is your bounding box 10 units high by any chance?

EDIT: Also, I hope this code is just for debugging - you should never be creating objects at render time, and especially never once per frame. That's a good way to get single digit frames per second [smile]

Share this post


Link to post
Share on other sites
i know i should not create objects at runtime^^

but you should check this line of code::

minVec *= 2;

this should correct the half problem thing, and all other axis x/z are right. Its right positioned at x and z and the size is also right only the y coordinate is wrong :S

Share this post


Link to post
Share on other sites
I'm not sure what you mean by "local bounding box." Are you assuming that the box you create surrounds your mesh?

D3DXCreateBox creates a box centered at the origin. It will not "surround" your original mesh unless your mesh is also centered at the origin.

In your code, m_box surrounds your mesh, not box.

I think you need to translate your box by m_box.center() before you draw it.

Check the value of m_box.center(). If it is not ( 0,0,0 ), that's the problem.

Share this post


Link to post
Share on other sites

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