xboxscene.org forums

Author Topic: Computing A Bounding Box  (Read 276 times)

JbOnE

  • Archived User
  • Full Member
  • *
  • Posts: 242
Computing A Bounding Box
« on: May 22, 2004, 08:58:00 PM »

trying to get this function to return the far right (xmax) value from the computed bounding box of the mesh. unfortunately i keep ending up with 1.84035e+031 values instead of nice usable floats

CODE

D3DVECTOR GetBox()
{    
    D3DVECTOR   returnBox;
    D3DXVECTOR3    minBox, maxBox;
    DWORD      num_Verts   = m_pMesh->GetNumVertices();
    DWORD         t_FVF  = m_pMesh->GetFVF();
    LPDIRECT3DVERTEXBUFFER8   temp_VB  = NULL;
    BYTE*       pVertices;
    
    m_pMesh->LockVertexBuffer( D3DLOCK_READONLY, &pVertices );
    m_pMesh->GetVertexBuffer( &temp_VB );
    D3DXComputeBoundingBox( &temp_VB, num_Verts, t_FVF, &minBox, &maxBox );
    m_pMesh->UnlockVertexBuffer();

    returnBox.x = minBox.x;
    returnBox.y = maxBox.x;
    returnBox.z = 5.0f;

    return returnBox; /// far left, far right, spacer
}


returnbox.z is 5.0f as a spacer to add to the correctly returned xmax value later on
tia for any input - Jay
Logged

knepley

  • Archived User
  • Jr. Member
  • *
  • Posts: 57
Computing A Bounding Box
« Reply #1 on: May 23, 2004, 06:28:00 PM »

I am not a huge X mesh lover, mostly because everything is so black box.
Hmmm lemme try writing a bbox routine in the post window:

CODE

BYTE *pVert;
D3DXVECTOR3 minv(0,0,0),maxv(0,0,0),temp;
UINT v_size=D3DXGetFVFVertexSize(mesh->GetFVF());
mesh->LockVertexBuffer(0,&pVert);
for(int i=0;iGetNumVertices();i++)
{
memcpy(&temp,pVert,sizeof(D3DXVECTOR3));
minv.x=min(minv.x,temp.x);
maxv.x=max(maxv.x,temp.x);
//etc etc etc

pVert+=v_size;
}
mesh->UnlockVertexBuffer();

There's a couple things that need to be right in the mesh for that to work, i.e. position needs to be the first 12 bytes. The mesh also needs to be based around the origin. You can always change that by setting min and max as the first vert and then going through all the other verts. Should consider getting off .x and onto a raw vert list or something.
-PeteGabe
Logged

JbOnE

  • Archived User
  • Full Member
  • *
  • Posts: 242
Computing A Bounding Box
« Reply #2 on: May 24, 2004, 09:06:00 AM »

wink.gif anyone with an idea on how to do so pls feel free to speak wink.gif

peace
JbOnE
Logged

knepley

  • Archived User
  • Jr. Member
  • *
  • Posts: 57
Computing A Bounding Box
« Reply #3 on: May 24, 2004, 11:50:00 AM »

Not sure what you are talking about when you say ani hiccup when creating a mesh from a file. What I usually do is use a maxscript to dump mesh data each frame and just linearly interpolate between keyframes. I am going to write a tutorial for the aftershock webpage once we get Star Wars out. Don't want to be giving out secrets before the game is even out.

PeteGabe
Logged

JbOnE

  • Archived User
  • Full Member
  • *
  • Posts: 242
Computing A Bounding Box
« Reply #4 on: May 24, 2004, 12:15:00 PM »

what i'm doing.....

the text is a custom 3d font comprised of binary, compressed .x meshes - the ani hiccup i'm talking about is when the text is created - it's a 2 second freeze using binary-compressed .x's and an 8 second freeze using text .x's.

i'd like to just create one of each char on app init as a vertex buffer and then just keep referencing or cloning the vb to draw text to the screen when needed - hopefully this will eliminate the freeze hiccup that has been pissing me off for days now ;)

unfortunately like i said b4 - all i've found is half-ass tutorials on how to turn a .x mesh into the vertex buffer i need :(

any help would be MORE than appreciated - TIA - Jay


*LOL - yes - the ani hiccup is bugging me more than not having the bounding boxes working right now*

This post has been edited by JbOnE on May 24 2004, 07:17 PM
Logged