Unable to perform translation using QSGTransformNode
-
Hello,
I am a newbie to qml and scene graph so kindly pardon me if my question is too trivial. I am trying to write a very simple toy program. In this program I am generating a line graph and I want this line graph to appear at the center of my rectangular window. Now, I realize, that I can adjust my y value of each pixel that is getting plot on the rectangle but I do not want to do so, I assumed that since scene graph uses opengl it will have some viewport kind of functionality to do the translation for me... because eventually i will be using this prototype to plot charts, bar graphs, etc
More specifically,
I am using QSGTransformNode object to perform my translation but I do not know how do I convey this change to QSGNode,I would really appreciate any help on this matter,
following is my code ...
@
QSGNode*
LineGraph::
updatePaintNode(QSGNode *node, UpdatePaintNodeData *updatePaintNodeData)
{
QSGGeometryNode *geomNode =0;
QSGGeometry *geom =0;
QSGVertexColorMaterial *material=0;
QSGTransformNode *transNode=0;if (!node) { geom = new QSGGeometry( QSGGeometry::defaultAttributes_ColoredPoint2D(), m_numPoints); geom->setLineWidth(1.0); geom->setDrawingMode(GL_LINE_STRIP); geom->allocate(m_numPoints); geomNode = new QSGGeometryNode(); geomNode->setGeometry(geom); geomNode->setFlag(QSGNode::OwnsGeometry); material = new QSGVertexColorMaterial(); geomNode->setMaterial(material); geomNode->setFlag(QSGNode::OwnsMaterial); } else { geomNode = static_cast<QSGGeometryNode*> (node); geom = geomNode->geometry(); material = static_cast<QSGVertexColorMaterial*>(geomNode->material()); } const QRectF bounds = boundingRect(); float hh = bounds.height(); float ww = bounds.width(); // translating along yy axis by height/2 QMatrix4x4 mat1(0.0,0.0,0.0,0.0, 0.0,0.0,0.0,300, // hh/2 0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0); mat1.optimize(); transNode = new QSGTransformNode(); transNode->setMatrix(mat1); transNode->markDirty(QSGNode::DirtyNodeAdded); QSGGeometry::ColoredPoint2D *vertices = geom->vertexDataAsColoredPoint2D(); // get hold of vertices // generating sample data -- y values in range of -130 to 100 QVector <int> yyVals; for(quint32 yy=0; yy < m_numPoints; ++yy) { if (yy > m_numPoints/2) yyVals.push_back( -10 ); else yyVals.push_back( 10 ); } for(quint32 ii=0; ii < m_numPoints; ++ii) { vertices[ii].set(ii , yyVals[ii], ii%5 ,128,0,255); // testing -- drawing randon data on yAxis } geomNode->markDirty(QSGNode::DirtyForceUpdate); geomNode->appendChildNode(transNode); return geomNode;
}@
-
If you found solution, please share your knowledge.