void WereMesh::GenerateBoundingBox(LPDIRECT3DDEVICE9 pD3dDevice)
{
D3DXVECTOR3 min, max, boxMeshOffset ;
BYTE* v;
// lock mesh to compute boundingBox
m_pMesh->LockVertexBuffer(0, (void**)&v);
D3DXComputeBoundingBox((D3DXVECTOR3*)v, m_pMesh->GetNumVertices(), D3DXGetFVFVertexSize(m_pMesh->GetFVF()), &min, &max);
m_pMesh->UnlockVertexBuffer();
// the offset from 0,0,0
boxMeshSize = max - min;
// creates box centered at 0,0,0
D3DXCreateBox(pD3dDevice, boxMeshSize.x, boxMeshSize.y, boxMeshSize.z, &m_pOBB, /*addjacency??*/NULL);
// center around m_pMesh ... m_pMesh may not be centered 0,0,0
int at = 0, vertexSize = 0;
m_pOBB->LockVertexBuffer(0, (void**)&v);
vertexSize = D3DXGetFVFVertexSize(m_pOBB->GetFVF());
for(UINT i = 0; i < m_pOBB->GetNumVertices(); i ++)
{
at = i * vertexSize;
((D3DXVECTOR3*)v)[at] += boxMeshSize; // <-- not the right value I know
}
m_pOBB->UnlockVertexBuffer();
// Optimize the mesh for better attribute access
m_pOBB->OptimizeInplace(D3DXMESHOPT_ATTRSORT, NULL, NULL, NULL, NULL);
}
Bounding Box applying non 0,0,0 offset
hey,
I found this way to generate bounding boxes... but it did not calculate the fact that the mesh may not be centered around {0,0,0} so i decided to move the vertices after the fact.. i think the basic "idea" i wrote for the offset is ok but i know that The value i add to the m_pOBB verticies is not right.. it does not crash.. but it does not work right it actually moved maybe two of the m_pOBB vertecies and a bunch of the m_pMesh verticies..
any ideas? I guess i could find the point that the m_pMesh is centered arround and add the difference to each vertex .... how do you find the centerpoint of a mesh?
thanks
ok i have a little prob now...
when i lock m_OBB (is a bounding box :P ) created from D3DXCreateBox()) and try to change the vertices ::SEE BELOW:: in the loop the vPtr never has any data.. I dont get it?? note the m_OBB will render so it has data..
when i lock m_OBB (is a bounding box :P ) created from D3DXCreateBox()) and try to change the vertices ::SEE BELOW:: in the loop the vPtr never has any data.. I dont get it?? note the m_OBB will render so it has data..
boxMeshOffset *= 0.5f // created above is D3DXVECTOR3BYTE* ptr = NULL;// lock the vertex bufferif(FAILED(m_pOBB->LockVertexBuffer(0, (void**)&ptr))) return;DWORD vertexSize = D3DXGetFVFVertexSize(m_pOBB->GetFVF());DWORD numVertices = m_pOBB->GetNumVertices(); // Loop through each vertex and apply offset for(DWORD i = 0; i < numVertices; i ++) { D3DXVECTOR3* vPtr = (D3DXVECTOR3*)ptr; *vPtr += boxMeshOffset; <--- crashes here vPtr has no data ptr += vertexSize; }m_pOBB->UnlockVertexBuffer();
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement