Game Development Reference
In-Depth Information
bool ComputeBoundingSphere(
ID3DXMesh* mesh, // mesh to compute bounding sphere for
d3d::BoundingSphere* sphere) // return bounding sphere
{
HRESULT hr = 0;
BYTE*v=0;
mesh->LockVertexBuffer(0, (void**)&v);
hr = D3DXComputeBoundingSphere(
(D3DXVECTOR3*)v,
mesh->GetNumVertices(),
D3DXGetFVFVertexSize(mesh->GetFVF()),
&sphere->_center,
&sphere->_radius);
mesh->UnlockVertexBuffer();
if( FAILED(hr) )
return false;
return true;
}
bool ComputeBoundingBox(
ID3DXMesh* mesh, // mesh to compute bounding box for
d3d::BoundingBox* box) // return bounding box
{
HRESULT hr = 0;
BYTE*v=0;
mesh->LockVertexBuffer(0, (void**)&v);
hr = D3DXComputeBoundingBox(
(D3DXVECTOR3*)v,
mesh->GetNumVertices(),
D3DXGetFVFVertexSize(mesh->GetFVF()),
&box->_min,
&box->_max);
mesh->UnlockVertexBuffer();
if( FAILED(hr) )
return false;
return true;
}
Notice that the cast (D3DXVECTOR3*)v assumes the vertex position
component is stored first in the vertex structure that we are using.
Also notice that we can use the D3DXGetFVFVertexSize function to
get the size of a vertex structure given the flexible vertex format
description.
Search WWH ::




Custom Search