示例#1
0
void TaperDeformAction::deform(Lattice& lattice)
{
    float taper;
    gmtl::Vec3f cellPoint, move, min, max;

    gmtl::Vec3i cellDivisions = lattice.getCellDivisions();
    Lattice::Vector3d& cellPoints = lattice.accessCellPoints();

    lattice.centerOrigin(min, max, move);
    taper = (max[z] - min[z]) / taperFactor;


    if (sign > 0)
    {
        for (int h = 0; h <= cellDivisions[0]; ++h)
            for (int w = 0; w <= cellDivisions[1]; ++w)
                for (int l = 0; l <= cellDivisions[2]; ++l)
                {
                    lattice.moveTo(cellPoints[h][w][l], cellPoint, move);
                    // f(z) = (max z - z) / (max z - min z)
                    // z' = z

                    // x' = f(z) * x
                    cellPoint[x] *= ((max[z] - cellPoint[z]) / taper);
                    // y' = f(z) * y
                    cellPoint[y] *= ((max[z] - cellPoint[z]) / taper);

                    lattice.moveBack(cellPoint, cellPoints[h][w][l], move);
                }
    }
    else
    {
        for (int h = 0; h <= cellDivisions[0]; ++h)
            for (int w = 0; w <= cellDivisions[1]; ++w)
                for (int l = 0; l <= cellDivisions[2]; ++l)
                {
                    lattice.moveTo(cellPoints[h][w][l], cellPoint, move);
                    // f(z) = (max z - z) / (max z - min z)
                    // z' = z

                    // x' = f(z) * x
                    cellPoint[x] *= (((max[z]) + cellPoint[z]) / taper);
                    // y' = f(z) * y
                    cellPoint[y] *= (((max[z]) + cellPoint[z]) / taper);

                    lattice.moveBack(cellPoint, cellPoints[h][w][l], move);
                }
    }
}