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. [SOLVED] Picking transformed copies of qglscenenodes
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Picking transformed copies of qglscenenodes

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.9k 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.
  • C Offline
    C Offline
    charles_Tester
    wrote on last edited by
    #1

    I have an object "Module" which inherits QGLSceneNode.
    @
    Module::Module(QObject *parent)
    : QGLSceneNode(parent)
    {

    m_scene1 = QGLAbstractScene::loadScene(QLatin1String(":3ds/part1.3ds"),QString(),op);
    m_scene2 = QGLAbstractScene::loadScene(QLatin1String(":3ds/part2.3ds"),QString(),op);
    m_scene3 = QGLAbstractScene::loadScene(QLatin1String(":3ds/part3.3ds"),QString(),op);
    
    m_scene1->setPickable( true );
    m_scene2->setPickable( true );
    m_scene3->setPickable( true );
    
    m_scene1->generatePickNodes();
    m_scene2->generatePickNodes();
    m_scene3->generatePickNodes();
    
    pick_nodes.append( m_scene1->pickNodes() );
    pick_nodes.append( m_scene2->pickNodes() );
    pick_nodes.append( m_scene3->pickNodes() );
    
    part1 = m_scene1->mainNode();
    part2 = m_scene2->mainNode();
    part3 = m_scene3->mainNode();
    
    addNode( part1 );
    addNode( part2 );
    addNode( part3 );
    

    }
    @
    @
    virtual QList<QGLPickNode *> get_pick_nodes() { return pick_nodes; }
    @
    In my application, I create three of these Modules, and apply some transformations to move them around relative to each other. This all works and looks fine, but the picking is screwed up. Clicking on any of one of the three Modules picks one of them; always the same one.

    Here is how I connect the pickNode clicked() signals to my SLOT:
    @
    for ( unsigned int i = 0; i < modules.size(); i++ ) {
    QList<QGLPickNode *>nodes = modules[i]->get_pick_nodes();
    for ( int j = 0; j < nodes.size(); j++ ) {
    connect( nodes[j], SIGNAL( clicked() ), this, SLOT( object_picked() ) );
    registerObject( nodes[j]->id(), nodes[j] );
    nodes[j]->setTarget( modules[i] );
    }
    }
    @
    Here is my slot:
    @
    void ModelView::object_picked() {

    QGLPickNode *pn = qobject_cast<QGLPickNode*> (sender());
    Q_ASSERT(pn);
    QGLSceneNode *n = pn->target();
    
    qDebug() << pn->id();
    
    for ( unsigned int i = 0; i < modules.size(); i++ ) {
        if ( modules[i] == n ) {
            modules[i]->set_color( Qt::cyan );
            qDebug() << "found:" << i;
        }
        else {
            modules[i]->set_color( Qt::white );
        }
    }
    updateGL();
    

    }
    @

    1 Reply Last reply
    0
    • M Offline
      M Offline
      miroslav
      wrote on last edited by
      #2

      Sounds interesting. What is the question, though? :-)

      Mirko Boehm | mirko@kde.org | KDE e.V.
      FSFE Fellow
      Qt Certified Specialist

      1 Reply Last reply
      0
      • C Offline
        C Offline
        charles_Tester
        wrote on last edited by
        #3

        Why can't I pick individual Modules? Why when I click on any of one of the three Modules, do I pick one of them, and always the same one?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          charles_Tester
          wrote on last edited by
          #4

          I solved my problem by sequentially re-numbering the ids of all my pick nodes with setId().

          Works fine now. It's just kind of slow. There is a 1-2 second delay between clicking in the glView and execution of the object_picked() slot.

          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