//-------------------------------------------------------------------------------------- // Name: ComputeFrameBoundingBox() // Desc: Calls ComputeMeshBoundingBox for each frame with the correct transform. //-------------------------------------------------------------------------------------- VOID Mesh::ComputeFrameBoundingBox( const MESH_FRAME* pFrame, const XMMATRIX matParent, XMVECTOR& vMin, XMVECTOR& vMax ) { // Initialize bounds to be reset on the first UnionBox vMin.x = vMin.y = vMin.z = +FLT_MAX; vMax.x = vMax.y = vMax.z = -FLT_MAX; // Apply the frame's local transform XMMATRIX matWorld = XMMatrixMultiply( pFrame->m_matTransform, matParent ); // Compute bounds for the mesh data if( pFrame->m_pMeshData->m_dwNumSubsets ) { XMVECTOR vMeshMin, vMeshMax; ComputeMeshBoundingBox( pFrame->m_pMeshData, matWorld, vMeshMin, vMeshMax ); UnionBox( vMin, vMax, vMeshMin, vMeshMax ); } // Compute bounds for any child frames if( pFrame->m_pChild ) { XMVECTOR vChildMin, vChildMax; ComputeFrameBoundingBox( pFrame->m_pChild, matWorld, vChildMin, vChildMax ); UnionBox( vMin, vMax, vChildMin, vChildMax ); } // Compute bounds for any sibling frames if( pFrame->m_pNext ) { XMVECTOR vSiblingMin, vSiblingMax; ComputeFrameBoundingBox( pFrame->m_pNext, matParent, vSiblingMin, vSiblingMax ); UnionBox( vMin, vMax, vSiblingMin, vSiblingMax ); } }
void Model::ComputeAllBoundingBoxes() { for (unsigned int meshIndex = 0; meshIndex < m_Header.meshCount; meshIndex++) { Mesh *mesh = m_pMesh + meshIndex; ComputeMeshBoundingBox(meshIndex, mesh->boundingBox); } ComputeGlobalBoundingBox(m_Header.boundingBox); }