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 ); }
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); }