Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Unable to perform translation using QSGTransformNode
Qt 6.11 is out! See what's new in the release blog

Unable to perform translation using QSGTransformNode

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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;
    

    }@

    1 Reply Last reply
    1
    • S Offline
      S Offline
      seyed
      wrote on last edited by
      #2

      If you found solution, please share your knowledge.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved