Beispiel #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 );
}
Beispiel #2
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);
}