Original Post
I''m having a helluva time trying to get a BoundingBox from a loaded VertexBuffer. The first paragraph works fine and the vertex buffer appears to load up without a hitch. It renders perfectly with no visual artifacts. Then in the second paragraph (see below) the D3DXComputeBoundingBox() function returns with no errors. When I look at the results, however, the min and max vectors x/y/z members have crazy negative numbers which look like "-1.24395e+006".
As an experiment, I added the "D3DVERTEX* test=(D3DVERTEX*) pData;" line so I could get a look at the vertexbuffer. What''s interesting about the results is that each time I run the program, the test variable has what appears to be random values for the XYZ portion of the structure (they change each time I run the program). This had me thinking I had my pointer arithmetic screwed up somewhere but what''s strange is the rest of the structure (color, coordinates, etc.) are all normal (exactly as I set them originally).
Again, this seems very strange to me because I know my vertexbuffer is good. I use it just a few lines down to render a beautiful MD2 model.
Please help! I''m totally at a loss!
bpopp (bpopp.net)
BYTE* pData;
if ( SUCCEEDED(m_vertexBuffer->Lock(0,0,(BYTE**)&pData,D3DLOCK_DISCARD ) ) )
{
memcpy(pData,GetVertexData(),m_VertexCount * sizeof(D3DVERTEX));
m_vertexBuffer->Unlock();
}
// Get a bounding box.
D3DXVECTOR3 upperRight = D3DXVECTOR3 (0,0,0);
D3DXVECTOR3 bottomLeft = D3DXVECTOR3 (0,0,0);
if ( SUCCEEDED(m_vertexBuffer->Lock(0,0,&pData,D3DLOCK_READONLY) )
{
D3DVERTEX* test = (D3DVERTEX*)pData;
HRESULT r = D3DXComputeBoundingBox( (PVOID)pData, m_VertexCount, sizeof (D3DVERTEX), &bottomLeft, &upperRight );
m_vertexBuffer->Unlock();
}