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