Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Bouding Box Position problem

$
0
0
Hey guys, Im getting bounding box of a mesh in my engine using D3DXComputeBoundingBox, but when I use this function, looks like the mesh is every on position (0,0,0), but it isn't. The bounding box should be in position of sphere, and dont (0,0,0) D3DXComputeBoundingBox getting wrong sMin and sMax (how we can see on the pic, it isnt a problem of render...) How it should be: The code im using to get bounding box: BYTE * pData; pMeshContainer->MeshData.pMesh->LockVertexBuffer( D3DLOCK_READONLY, (void**)&pData ); //Compute Bounding Box D3DXComputeBoundingBox( (const D3DXVECTOR3*)(pData), pMeshContainer->MeshData.pMesh->GetNumVertices(), pMeshContainer->MeshData.pMesh->GetNumBytesPerVertex(), &pMeshContainer->cBoundingBox.sMin, &pMeshContainer->cBoundingBox.sMax ); pMeshContainer->cBoundingBox.sMid = (pMeshContainer->cBoundingBox.sMax - pMeshContainer->cBoundingBox.sMin) * 0.5f; pMeshContainer->cBoundingBox.sCenter = (pMeshContainer->cBoundingBox.sMax + pMeshContainer->cBoundingBox.sMin) * 0.5f; //Compute Bounding Sphere D3DXComputeBoundingSphere( (const D3DXVECTOR3*)(pData), pMeshContainer->MeshData.pMesh->GetNumVertices(), pMeshContainer->MeshData.pMesh->GetNumBytesPerVertex(), &pMeshContainer->cBoundingSphere.sCenter, &pMeshContainer->cBoundingSphere.fRadius ); pMeshContainer->MeshData.pMesh->UnlockVertexBuffer(); //We have min and max values, use these to get the 8 corners of the bounding box pMeshContainer->cBoundingBox.sBoxPoints[0] = D3DXVECTOR3( pMeshContainer->cBoundingBox.sMin.x, pMeshContainer->cBoundingBox.sMin.y, pMeshContainer->cBoundingBox.sMin.z ); //xyz pMeshContainer->cBoundingBox.sBoxPoints[1] = D3DXVECTOR3( pMeshContainer->cBoundingBox.sMax.x, pMeshContainer->cBoundingBox.sMin.y, pMeshContainer->cBoundingBox.sMin.z ); //Xyz pMeshContainer->cBoundingBox.sBoxPoints[2] = D3DXVECTOR3( pMeshContainer->cBoundingBox.sMin.x, pMeshContainer->cBoundingBox.sMax.y, pMeshContainer->cBoundingBox.sMin.z ); //xYz pMeshContainer->cBoundingBox.sBoxPoints[3] = D3DXVECTOR3( pMeshContainer->cBoundingBox.sMax.x, pMeshContainer->cBoundingBox.sMax.y, pMeshContainer->cBoundingBox.sMin.z ); //XYz pMeshContainer->cBoundingBox.sBoxPoints[4] = D3DXVECTOR3( pMeshContainer->cBoundingBox.sMin.x, pMeshContainer->cBoundingBox.sMin.y, pMeshContainer->cBoundingBox.sMax.z ); //xyZ pMeshContainer->cBoundingBox.sBoxPoints[5] = D3DXVECTOR3( pMeshContainer->cBoundingBox.sMax.x, pMeshContainer->cBoundingBox.sMin.y, pMeshContainer->cBoundingBox.sMax.z ); //XyZ pMeshContainer->cBoundingBox.sBoxPoints[6] = D3DXVECTOR3( pMeshContainer->cBoundingBox.sMin.x, pMeshContainer->cBoundingBox.sMax.y, pMeshContainer->cBoundingBox.sMax.z ); //xYZ pMeshContainer->cBoundingBox.sBoxPoints[7] = D3DXVECTOR3( pMeshContainer->cBoundingBox.sMax.x, pMeshContainer->cBoundingBox.sMax.y, pMeshContainer->cBoundingBox.sMax.z ); //XYZ SAFE_RELEASE( pMeshContainer->lpBoundingBoxMesh ); SAFE_RELEASE( pMeshContainer->lpBoundingSphereMesh ); //Create Bounding Sphere Mesh D3DXCreateSphere( lpDevice, pMeshContainer->cBoundingSphere.fRadius, 15, 10, &pMeshContainer->lpBoundingSphereMesh, NULL ); //Create Bounding Box Mesh float fWidth = pMeshContainer->cBoundingBox.sMax.x - pMeshContainer->cBoundingBox.sMin.x; float fHeight = pMeshContainer->cBoundingBox.sMax.y - pMeshContainer->cBoundingBox.sMin.y; float fDepth = pMeshContainer->cBoundingBox.sMax.z - pMeshContainer->cBoundingBox.sMin.z; D3DXCreateBox( lpDevice, fWidth, fHeight, fDepth, &pMeshContainer->lpBoundingBoxMesh, NULL ); Im not using any World transform on the mesh or bounding box...

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>