Exemple #1
0
coordinates::coordinates( float size, float thickness ):
    m_node( new QGLSceneNode() )
{
    QGLBuilder builder;
    builder << QGLCylinder( thickness, thickness, size, 12 );
    QGLSceneNode* cylinder = builder.finalizedSceneNode();
    cylinder->setPosition( QVector3D( 0, 0, 0.5 * size ) );
    cylinder->setEffect( QGL::LitMaterial );

    QGLBuilder arrowBuilder;
    arrowBuilder << QGLCylinder( 0.01, 2 * thickness, size / 3, 12 );
    QGLSceneNode* arrow = arrowBuilder.finalizedSceneNode();
    arrow->setPosition( QVector3D( 0, 0, size ) );
    arrow->setEffect( QGL::LitMaterial );
    
    
    QGLSceneNode* x = new QGLSceneNode( m_node );
    x->addNode(cylinder);
    QMatrix4x4 matrix;
    QQuaternion q = QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 90.0f);
    matrix.rotate( q );
    x->setLocalTransform( matrix );
    QGLSceneNode* xArrow = new QGLSceneNode( m_node );
    xArrow->addNode( arrow );
    xArrow->setLocalTransform( matrix );
    QGLMaterial* xMaterial = new QGLMaterial;
    xMaterial->setDiffuseColor( QColor( 255, 0, 0, 128 ) );
    x->setMaterial( xMaterial );
    xArrow->setMaterial( xMaterial );
    
    QGLSceneNode* y = new QGLSceneNode( m_node );
    y->addNode(cylinder);
    q = QQuaternion::fromAxisAndAngle(1.0f, 0.0f, 0.0f, -90.0f);
    matrix.rotate( q );
    y->setLocalTransform( matrix );
    QGLSceneNode* yArrow = new QGLSceneNode( m_node );
    yArrow->addNode( arrow );
    yArrow->setLocalTransform( matrix );
    QGLMaterial* yMaterial = new QGLMaterial;
    yMaterial->setDiffuseColor(Qt::green);
    y->setMaterial( yMaterial );
    QGLMaterial* yArrowMaterial = new QGLMaterial;
    yArrowMaterial->setDiffuseColor( QColor( 0, 255, 0, 128 ) );
    yArrow->setMaterial( yArrowMaterial );
    
    QGLSceneNode* z = new QGLSceneNode( m_node );
    z->addNode(cylinder);
    QGLSceneNode* zArrow = new QGLSceneNode( m_node );
    zArrow->addNode( arrow );
    QGLMaterial* zMaterial = new QGLMaterial;
    zMaterial->setDiffuseColor(Qt::blue);
    z->setMaterial( zMaterial );
    QGLMaterial* zArrowMaterial = new QGLMaterial;
    zArrowMaterial->setDiffuseColor( QColor( 0, 0, 255, 128 ) );
    zArrow->setMaterial( zArrowMaterial );
}
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);
}
Exemple #3
0
/* Creates an individual randomly positioned ball */
QGLSceneNode *ModelBall::createNode(QGLMaterial *material) {
    const float defaultSize = 1.0;
    const float positionX = -1.5;
    const float positionY = 40.0;
    const float randomPositionScale = 1000.0;
    QGLBuilder builder;
    QGLSceneNode *node;
    builder.newNode();
    builder << QGLSphere(defaultSize);
    node = builder.finalizedSceneNode();
    node->setMaterial(material);
    node->setEffect(QGL::LitMaterial);
    QGraphicsTranslation3D *trans = new QGraphicsTranslation3D();
    node->addTransform(trans);
    QGraphicsTranslation3D *transStart = new QGraphicsTranslation3D();
    QVector3D *randomStart = new QVector3D(positionX +
                                           randomPosition()/randomPositionScale,
                                           positionY +
                                           randomPosition()/randomPositionScale,
                                           randomPosition()/randomPositionScale);
    transStart->setTranslate(*randomStart);
    node->addTransform(transStart);
    return node;
}
Exemple #4
0
void tst_QGLRender::sequence()
{
    QSKIP("QWidget: Cannot create a QWidget when no GUI is being used");
    QSharedPointer<QGLMaterialCollection> palette(new QGLMaterialCollection());

    // create a yellow lit material
    QGLMaterial *mat = new QGLMaterial;
    mat->setAmbientColor(Qt::yellow);
    int ix0 = palette->addMaterial(mat);

    // create a blue lit material
    mat = new QGLMaterial;
    mat->setAmbientColor(Qt::blue);
    int ix1 = palette->addMaterial(mat);

    // create a grey textured material
    int tx0;
    {
        QImage uv(1024, 1024, QImage::Format_ARGB32);
        uv.fill(qRgba(196, 196, 196, 196));
        mat = new QGLMaterial;
        mat->setAmbientColor(Qt::gray);
        QGLTexture2D *tex = new QGLTexture2D;
        tex->setImage(uv);
        mat->setTexture(tex);
        tx0 = palette->addMaterial(mat);
    }

    QGLSceneNode *scene = new QGLSceneNode;
    scene->setPalette(palette);
    QGLSceneNode *node = 0;
    QGLSceneNode *prim;
    {
        QGLBuilder builder(palette);
        QVector3D a(-1.0f, -1.0f, 0.0f);
        QVector3D b(1.0f, -1.0f, 0.0f);
        QVector3D c(1.0f, 1.0f, 0.0f);
        QGeometryData p;
        p.appendVertex(a, b, c);
        p.generateTextureCoordinates();
        builder.addTriangles(p);
        prim = builder.currentNode();
        prim->setMaterialIndex(ix0);
        builder.newSection();
        QVector3D d(-1.2f, -1.2f, 0.0f);
        QVector3D e(1.2f, -1.2f, 0.0f);
        QVector3D f(1.2f, 1.2f, 0.0f);
        QVector3D g(-1.2f, 1.2f, 0.0f);
        QGeometryData q;
        q.appendVertex(d, e, f, g);
        q.generateTextureCoordinates();
        builder.addQuads(q);
        prim = builder.currentNode();
        prim->setMaterialIndex(ix1);
        node = builder.finalizedSceneNode();
    }

    scene->addNode(node);
    QGLSceneNode *cl = prim->clone(scene);
    cl->setMaterialIndex(tx0);
    cl->setEffect(QGL::LitDecalTexture2D);

    TestView widget(scene);
    if (!widget.context()->isValid())
        QSKIP("GL Implementation not valid");

    TestPainter *ptr = new TestPainter(&widget);

    widget.paintGL(ptr);

    QList<int> starts = ptr->starts();
    QList<int> counts = ptr->counts();
    QCOMPARE(starts.at(0), 0);
    QCOMPARE(counts.at(0), 3);
    QCOMPARE(starts.at(1), 3);
    QCOMPARE(counts.at(1), 6);
}