コード例 #1
0
ファイル: quadplane.cpp プロジェクト: Distrotech/qt3d
/*!
    Construct a new QuadPlane with \a size, subdivided \a level times.  By default
    the plane is 100.0f x 100.0f, and is subdivided 3 times - that is into an
    8 x 8 grid.

    It is centered on the origin, and lies in the z = 0 plane.
*/
QuadPlane::QuadPlane(QObject *parent, QSizeF size, int level)
    : QGLSceneNode(parent)
{
    setObjectName(QLatin1String("QuadPlane"));
    if (level > 8)
        level = 8;
    if (level < 1)
        level = 1;
    int divisions = 1;
    for ( ; level--; divisions *= 2) {}  // integer 2**n
    QSizeF div = size / float(divisions);
    QSizeF half = size / 2.0f;
    QGLBuilder builder;
    QGeometryData zip;
    QGeometryData zip2;
    for (int yy = 0; yy <= divisions; ++yy)
    {
        float y = half.height() - float(yy) * div.height();
        float texY = float(yy) / divisions;
        for (int xx = 0; xx <= divisions; ++xx)
        {
            float x = half.width() - float(xx) * div.width();
            float texX = float(xx) / divisions;
            zip.appendVertex(QVector3D(x, y, 0));
            zip.appendTexCoord(QVector2D(1.0f - texX, 1.0f - texY));
        }
        if (yy > 0)
            builder.addQuadsInterleaved(zip, zip2);
        zip2 = zip;
        zip2.detach();
        zip.clear();
    }
    QGLSceneNode *n = builder.finalizedSceneNode();
    addNode(n);
}