Jump to content
  • Advertisement
Sign in to follow this  

Bounding Box applying non 0,0,0 offset

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

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?
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);
	// 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

	// Optimize the mesh for better attribute access



Share this post

Link to post
Share on other sites
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..

boxMeshOffset *= 0.5f // created above is D3DXVECTOR3
BYTE* ptr = NULL;
// lock the vertex buffer
if(FAILED(m_pOBB->LockVertexBuffer(0, (void**)&ptr)))

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;


Share this post

Link to post
Share on other sites
maybe some day ill quit repling to my own posts ;)

i had this

BYTE * v, ptr;

needed to be

BYTE *v, *ptr;

he .. heh

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!