示例#1
0
//--------------------------------------------------------------------------------------
// 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 );
    }
}
示例#2
0
BOOL CDocumentPreview::GetBounds(PBOX* pBounds)
{
	BOOL fResult = FALSE;

	if (m_pDoc != NULL)
	{
		if (m_fEncloseObjects)
		{
			PMGPageObjectPtr pObject;

			for (pObject = (PMGPageObjectPtr)m_pDoc->objects(); pObject != NULL; pObject = (PMGPageObjectPtr)pObject->next_object())
			{
				PBOX ObjBound;

				ObjBound = ((RectPageObjectPtr)pObject)->get_bound();

				if (fResult)
				{
					UnionBox(pBounds, pBounds, &ObjBound);
				}
				else
				{
					*pBounds = ObjBound;
					fResult = TRUE;
				}
			}
		}
		else
		{
			if (m_fForceToFront)
			{
				m_pDoc->GetPreviewBound(pBounds);
			}
			else
			{
				m_pDoc->CPmwDoc::get_panel_world(pBounds);
			}

			fResult = TRUE;
		}
	}

	// If we got nothing, return an empty bound.
	if (!fResult)
	{
		pBounds->x0 =
			pBounds->y0 =
			pBounds->x1 =
			pBounds->y1 = 0;
	}
	return fResult;
}
示例#3
0
//--------------------------------------------------------------------------------------
// Name: ComputeMeshBoundingBox()
// Desc: Calculate the bounding box of the transformed mesh.
//--------------------------------------------------------------------------------------
VOID Mesh::ComputeMeshBoundingBox( MESH_DATA* pMesh, const XMMATRIX mat,
                                   XMVECTOR& vMin, XMVECTOR& vMax )
{
    // Initialize bounds to be reset on the first point
    vMin.x = vMin.y = vMin.z = +FLT_MAX;
    vMax.x = vMax.y = vMax.z = -FLT_MAX;

    DWORD dwNumVertices = pMesh->m_dwNumVertices;
    DWORD dwVertexSize = pMesh->m_dwVertexSize;

    BYTE* pVertexData;
    pMesh->m_VB.Lock( 0, 0, ( VOID** )&pVertexData, D3DLOCK_READONLY );

    while( dwNumVertices-- )
    {
        XMFLOAT3* pVertex = ( XMFLOAT3* )pVertexData;
        XMVECTOR vPos = XMVectorSet( pVertex->x, pVertex->y, pVertex->z, 0 );
        vPos = XMVector3TransformCoord( vPos, mat );

        UnionBox( vMin, vMax, vPos, vPos );  // Expand the bounding box to include the point
        pVertexData += dwVertexSize;
    }
    pMesh->m_VB.Unlock();
}