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

D3DXComputeBoundingBox Problem

Started by bpopp May 22, 2003 at 1:32 AM 9 replies 4.5k views
Original Post
bpopp
bpopp
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!
  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();
}  
bpopp (bpopp.net)
bpopp
bpopp
Yeah, I noticed that in some of the sample code I found on here and tried it. The DX9 docs definitely indicate that the parameter is a count:

dwStride - [in] Count or number of bytes between vertices.

I''m guessing that this has been changed since DX8. I''m using 8 so I tried switching to the actual FVF to no avail. I still get the problem described earlier.

Here''s something strange I noticed that might help someone explain what''s happening. After the first itteration, data in my vertexbuffer appears to be correct. Would this function require my coordinates to be transformed (to either view, world, or projection) space prior to being used? I assumed this function would be returning LOCAL coordinates but maybe that''s not the case?

Again, help! My poor, inadequate MD2 just doesn''t have any idea how big he is and it''s beginning to affect his personality. I just watched him kick the family dog for absolutely no reason.



bpopp (bpopp.net)
tzuvich
tzuvich
You might want to try something like this:

// here is your FVF, replace with whatever your combination realy is
#define D3DFVF_VERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)

HRESULT r = D3DXComputeBoundingBox( (PVOID)pData, m_VertexCount, D3DFVF_VERTEX, &bottomLeft, &upperRight );

That should work in DX8, if your earlier call to:

memcpy(pData,GetVertexData(),m_VertexCount * sizeof(D3DVERTEX));

Is doing what you think its doing.
bpopp
bpopp
Yeah, like I said, I tried that and I''m still getting the same thing. I''m thinking it''s a transformation issue and that I''m just checking the bounds in the wrong place. Does anyone know of any SDK examples which use this function so I could see how it''s used in context.

bpopp (bpopp.net)
bpopp
bpopp
Thanks AP. All very helpful comments. First of all, yes *I think* my D3DVERTEX is correct and matches the FVF. It looks like:


  #define D3DFVF_CUSTOMVERTEX	( D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEX2 )

//structures

typedef struct SVertex
{
FLOAT x, y, z;
DWORD color;
FLOAT tu, tv; // The texture coordinates.

FLOAT tu2, tv2;
} D3DVERTEX;


I think my next step _is_ going to be building a custom BoundingBox function so I can try and watch exactly what''s happening. I tried running the D3DXComputeBoundingBox() function on some of my simpler meshes, but was still getting some unusual results. Also, I''ll check out the SDK Cull sample so I can see where in the rendering pipeline it''s being used.

Thanks again! The family dog owes you one!


aker_jus
aker_jus
You don''t need to put TEX1 | TEX2, actually I think that would be wrong. TEX2 specifies that there will be 2 texture corrdinate sets in the structure, why OR the TEX1 and TEX2?
GraphicsWare|RenderTechhttp://www.graphicsware.com3D Graphics & Solutions
bpopp
bpopp
But I have two sets of texture coordinates.. one for each texture pass.

bpopp (bpopp.net)
bpopp
bpopp
Sure enough, that was it. Thanks so much for the help!

[edited by - bpopp on May 23, 2003 12:47:15 PM]

Topic Locked

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

Sign in to reply to this topic.