[SOLVED] Picking transformed copies of qglscenenodes
-
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();
}
@ -
Sounds interesting. What is the question, though? :-)
-
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?
-
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.