Exemplo n.º 1
0
StereoView::StereoView(QWidget *parent)
    : QGLView(parent)
{
    scene = new QGLSceneNode(this);

    QGLSceneNode *teapot;
    QGLSceneNode *cube;

    {
        QGLBuilder builder;
        builder << QGLTeapot();
        teapot = builder.finalizedSceneNode();
    }

    {
        QGLBuilder builder;
        builder.newSection(QGL::Faceted);
        builder << QGLCube(1.0f);
        cube = builder.finalizedSceneNode();
    }

    cube->setPosition(QVector3D(-1.0f, 0.0f, 2.0f));
    scene->addNode(teapot);
    scene->addNode(cube);

    QGLMaterial *china = new QGLMaterial(this);
    china->setAmbientColor(QColor(192, 150, 128));
    china->setSpecularColor(QColor(60, 60, 60));
    china->setShininess(128);
    scene->setMaterial(china);
    scene->setEffect(QGL::LitMaterial);

    camera()->setEye(QVector3D(0.0f, 0.0f, 15.0f));
    camera()->setEyeSeparation(0.2f);
}
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);
}
Exemplo n.º 3
0
/*!
  Constructor, creates Qt3D Cube object as a particle, with lighting normals
  separated for each face for a faceted appearance.
*/
ExplosionParticle::ExplosionParticle(QGLShaderProgramEffect *effect,
                                     QGLMaterialCollection *materialCollection)
    : IParticle()
{
    m_DiffuseLoc = -1;

    QGLBuilder builder;
    builder.newSection(QGL::Faceted);
    builder << QGLCube(0.6);
    addNode(builder.finalizedSceneNode());

    if (effect)
        setUserEffect(effect);

    setPalette(materialCollection);
}
Exemplo n.º 4
0
CubeItem::CubeItem(QGraphicsItem *parent)
    : QGLGraphicsViewportItem(parent)
    , mScene(0)
    , fbo(0)
    , navigating(false)
    , pressedFace(-1)
    , pressedButton(Qt::NoButton)
{
    startNavCamera = new QGLCamera();

    setFlag(ItemIsFocusable, true);

    QGLBuilder builder;
    builder.newSection(QGL::Faceted);
    builder << QGLCube(CubeSize);
    cube = builder.finalizedSceneNode();
}
Exemplo n.º 5
0
void CubeView::initializeGL(QGLPainter *painter)
{
    QGLBuilder builder;
    builder.newSection(QGL::Faceted);
    builder << QGLCube(1.5f);
    cube = builder.currentNode();

    builder << QGLTeapot();
    teapot = builder.currentNode();

    scene = builder.finalizedSceneNode();
    scene->setParent(this);

    fbo = new QGLFramebufferObject(512, 512, QGLFramebufferObject::Depth);

    QImage textureImage(":/qtlogo.png");
    qtlogo.setImage(textureImage);

    painter->setBlendingEnabled(true);
}