コード例 #1
0
ファイル: modelball.cpp プロジェクト: timakima/arteacher
/* Creates the scene of balls */
void ModelBall::createScene() {
    qsrand(QDateTime::currentMSecsSinceEpoch());
    QGLMaterial *material = new QGLMaterial();
    material->setColor(Qt::blue);
    material->setSpecularColor(QColor(SPECULAR_COLOR));
    material->setAmbientColor(QColor(AMBIENT_COLOR));
    material->setEmittedLight(QColor(EMITTED_LIGHT_COLOR));
    material->setShininess(SHININESS);
    for (int i = 0; i < ANIMATION_BALLS; i++) {
        _nodes.append(createNode(material));
        _phase[i] = 2 * M_PI / ANIMATION_BALLS * i - M_PI;
    }
    _mainNode = _nodes.first();
}
コード例 #2
0
CylinderView::CylinderView(QWindow *parent)
    : QGLView(parent)
{
    QGLBuilder builder;
    // Evil hack: it is not possible to just call glClearColor on any device
    // but it is possible to have a huge, dark SkyBox. Without this hack the
    // cylinder floats over a transparent background, displaying the contents
    // of the last app
    builder << QGL::Smooth << QGLCube(1000.0f);


    // Add the cylinder
    builder << QGL::Smooth << QGLCylinder(2.0, 1.5, 2.0, 36, 3, true, true);

    QGLMaterial *matLid = new QGLMaterial;
    matLid->setAmbientColor(Qt::gray);
    matLid->setDiffuseColor(Qt::gray);
    QUrl urlLid;
    urlLid.setPath(QLatin1String(":/latte.png"));
    urlLid.setScheme(QLatin1String("file"));
    matLid->setTextureUrl(urlLid);

    QGLMaterial *matSides = new QGLMaterial;
    matSides->setColor(QColor(170, 202, 0));
    QUrl urlSides;
    urlSides.setPath(QLatin1String(":/cupTexture.png"));
    urlSides.setScheme(QLatin1String("file"));
    matSides->setTextureUrl(urlSides);

    QGLSceneNode *root = builder.sceneNode();

    QGLSceneNode *lid = root->findChild<QGLSceneNode *>("Cylinder Top");
    int lidMat = root->palette()->addMaterial(matLid);
    lid->setMaterialIndex(lidMat);
    lid->setEffect(QGL::LitDecalTexture2D);

    QGLSceneNode *sides = root->findChild<QGLSceneNode *>("Cylinder Sides");
    int sideMat = root->palette()->addMaterial(matSides);
    sides->setMaterialIndex(sideMat);
    sides->setEffect(QGL::LitDecalTexture2D);

    cylinder = builder.finalizedSceneNode();

    QGLMaterial *mat = new QGLMaterial;
    mat->setAmbientColor(Qt::gray);
    mat->setDiffuseColor(Qt::gray);
    cylinder->setMaterial(mat);
    cylinder->setEffect(QGL::LitMaterial);
}
コード例 #3
0
QGLMaterial *Bitmap3DRender::material(QColor color)
{
    Q_D(Bitmap3DRender);

    QGLMaterial *material = d->materials.material(color.name());
    if (material == NULL)
    {
        material = new QGLMaterial;
        material->setObjectName(color.name());
        color.setAlpha(1);
        material->setColor(color);
        d->materials.addMaterial(material);
    }

    return material;
}