示例#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);
}
示例#3
0
void loadProperty(const QString &property, QTextStream &value) {
    if (property == "material") {
        QGLMaterial *mat = new QGLMaterial();
        QString name, file;
        value >> name >> file;

        if (file != "-") {
            QGLTexture2D *tex = new QGLTexture2D();
            tex->setImage(QImage(dataDir + file));
            mat->setTexture(tex);
            mat->setTextureCombineMode(QGLMaterial::Decal);
        }

        int r, g, b;
        value >> r >> g >> b; if (r != -1) mat->setAmbientColor(QColor(r, g, b));
        value >> r >> g >> b; if (r != -1) mat->setDiffuseColor(QColor(r, g, b));
        value >> r >> g >> b; if (r != -1) mat->setSpecularColor(QColor(r, g, b));
        qreal shin; value >> shin; mat->setShininess(shin);

        palette.insert(name, mat);

    } else if (property == "size") {
示例#4
0
文件: tank.cpp 项目: Distrotech/qt3d
static QGLMaterial *qCreateFluid()
{
    QImage image(QSize(128,128), QImage::Format_ARGB32);
    QRgb col = qRgba(rval(), rval(), rval(), 196);
    image.fill(col);
    QPainter painter(&image);
    QLinearGradient linearGrad(QPointF(56, 56), QPointF(72, 72));
    linearGrad.setColorAt(0, col);
    linearGrad.setColorAt(1, QColor(col).lighter());
    linearGrad.setSpread(QGradient::ReflectSpread);
    painter.fillRect(image.rect(), linearGrad);
    painter.end();
    QGLMaterial *mat = new QGLMaterial;
    QColor white(Qt::white);
    white.setAlpha(128);
    mat->setAmbientColor(white);
    mat->setDiffuseColor(white);
    QGLTexture2D *tex = new QGLTexture2D(mat);
    tex->setImage(image);
    mat->setTexture(tex);
    return mat;
}
示例#5
0
/*!
  Initializes the Qt3D materials used in the application.
*/
void GameView::initializeMaterials()
{
    m_MaterialCollection = new QGLMaterialCollection(this);

    QGLTexture2D *lightTexture = new QGLTexture2D;
    lightTexture->setImage(QImage(":/reflectionmap.png"));

    QColor ambientColor = QColor(64, 64, 190);

    QGLMaterial *material = new QGLMaterial;
    material->setObjectName("PauseButtonMaterial");
    QGLTexture2D *texture = new QGLTexture2D;
    texture->setImage(QImage(":/pause_button.png"));
    material->setTexture(texture);
    m_MaterialCollection->addMaterial(material);

    // Black hole material
    material = new QGLMaterial;
    material->setObjectName("BlackHoleMaterial");
    texture = new QGLTexture2D;
    texture->setImage(QImage(":/BlackHole.jpg"));
    material->setTexture(texture);
    texture = new QGLTexture2D;
    texture->setImage(QImage(":/bh_sprial.png"));
    material->setTexture(texture, 1);
    material->setTextureCombineMode(QGLMaterial::Replace);
    m_MaterialCollection->addMaterial(material);


    // Black hole center material
    material = new QGLMaterial;
    material->setObjectName("BlackHoleFrontMaterial");
    texture = new QGLTexture2D;
    texture->setImage(QImage(":/bh_sprial.png"));
    material->setTexture(texture);
    material->setTexture(lightTexture, 1);
    m_MaterialCollection->addMaterial(material);

    // Platform material
    material = new QGLMaterial;
    material->setObjectName("PlatformMaterial");
    texture = new QGLTexture2D;
    texture->setImage(QImage(":/platformtex.png"));
    material->setTexture(texture);
    m_MaterialCollection->addMaterial(material);

    // Blok material
    material = new QGLMaterial;
    material->setObjectName("BlokMaterial");
    texture = new QGLTexture2D;
    texture->setImage(QImage(":/SimpleBlock.png"));
    material->setTexture(texture);
    material->setTexture(lightTexture, 1);
    material->setAmbientColor(ambientColor);
    material->setShininess(0.2f);
    m_MaterialCollection->addMaterial(material);

    // Ball materials
    material = new QGLMaterial;
    material->setObjectName("BallMaterial1");
    material->setAmbientColor(ambientColor);
    material->setDiffuseColor(QColor(255, 255, 64));
    material->setTexture(texture, 0);
    material->setTexture(lightTexture, 1);
    material->setShininess(1.0f);
    material->setSpecularColor(material->diffuseColor());
    m_MaterialCollection->addMaterial(material);

    material = new QGLMaterial;
    material->setObjectName("BallMaterial2");
    material->setAmbientColor(ambientColor);
    material->setDiffuseColor(QColor(255, 64, 64));
    material->setTexture(texture, 0);
    material->setTexture(lightTexture, 1);
    material->setShininess(1.0f);
    material->setSpecularColor(material->diffuseColor());
    m_MaterialCollection->addMaterial(material);

    material = new QGLMaterial;
    material->setObjectName("BallMaterial3");
    material->setDiffuseColor(QColor(64, 64, 255));
    material->setAmbientColor(ambientColor);
    material->setTexture(texture, 0);
    material->setTexture(lightTexture, 1);
    material->setShininess(1.0f);
    material->setSpecularColor(material->diffuseColor());
    m_MaterialCollection->addMaterial(material);

    material = new QGLMaterial;
    material->setObjectName("BallMaterial4");
    material->setDiffuseColor(QColor(64, 255, 64));
    material->setAmbientColor(ambientColor);
    material->setTexture(texture, 0);
    material->setTexture(lightTexture,1);
    material->setShininess(1.0f);
    material->setSpecularColor(material->diffuseColor());
    m_MaterialCollection->addMaterial(material);

    material = new QGLMaterial;
    material->setObjectName("LightFlareMaterial");
    texture = new QGLTexture2D;
    texture->setImage(QImage(":/flare.png"));
    material->setTexture(texture);
    m_MaterialCollection->addMaterial(material);

    material = new QGLMaterial;
    material->setObjectName("FontMaterial");
    texture = new QGLTexture2D;
    texture->setImage(QImage(":/scorefont.png"));
    material->setTexture(texture);
    m_MaterialCollection->addMaterial(material);
}