Exemplo n.º 1
0
void CDispInfo::ApplyTerrainMod( ITerrainMod *pMod )
{
    // New bbox.
    Vector bbMin(  1e24,  1e24,  1e24 );
    Vector bbMax( -1e24, -1e24, -1e24 );

    int nVerts, nIndices;
    CalcMaxNumVertsAndIndices( m_Power, &nVerts, &nIndices );

    // Ok, it probably touches us. Lock our buffer and change the verts.
    CMeshBuilder mb;
    mb.BeginModify( m_pMesh->m_pMesh, m_iVertOffset, nVerts );

    for( int iVert=0; iVert < nVerts; iVert++ )
    {
        if( m_AllowedVerts.Get( iVert ) )
        {
            Vector &vPos = m_Verts[iVert].m_vPos;
            Vector &vOriginalPos = m_Verts[iVert].m_vOriginalPos;

            if( pMod->ApplyMod( vPos, vOriginalPos ) )
                mb.Position3f( VectorExpand( vPos ) );

            VectorMin( vPos, bbMin, bbMin );
            VectorMax( vPos, bbMax, bbMax );
        }

        mb.AdvanceVertex();
    }

    mb.EndModify();

    // Set our new bounding box.
    m_BBoxMin = bbMin;
    m_BBoxMax = bbMax;
    UpdateCenterAndRadius();

    // Next time this displacement is seen, force it to rebuild and retesselate.
    m_bForceRebuild = true;
}