Unsolved Wrong coordinates under Mouse
-
Hello
I draw some lines on qglviewer
Now i need to computate the shortest way from mouse position to curvevoid viewer::mouseMoveEvent(QMouseEvent *e) { qglviewer::Vec xx(e->pos().x(), e->pos().y(), 1); qglviewer::Vec xxx = this->camera()->unprojectedCoordinatesOf(xx); float dist1track = std::numeric_limits<float>::max(); for(int i = 0; i < wtrjF.size(); i++) { Atom atom = wtrjF[i]; for(float t = 0; t < atom.pos.size(); t++) { if(dist1track > qSqrt(qPow(atom.pos[t][0] - xxx[0], 2) + qPow(atom.pos[t][1] - xxx[1], 2))) { dist1track = qSqrt(qPow(atom.pos[t][0] - xxx[0], 2) + qPow(atom.pos[t][1] - xxx[1], 2)); name = atom.wname; wid = atom.wid; pos = QString::number(atom.pos[0][0]) + "_" + QString::number(atom.pos[0][1]); } } } qDebug()<<name<<dist1track; }
But its give me wrong curve
I think i got wrong coordinates under mouse cursor, but don't know how to fix it.
Also tried get coords like:qglviewer::Vec xx = camera()->pointUnderPixel(e->pos(), found); qglviewer::Vec xx(e->pos().x(), e->pos().y(), 0); glReadPixels(e->pos().x(), view[3] - e->pos().y(), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z1); qglviewer::Vec xx(e->pos().x(), e->pos().y(), z1);
Any advises?
yea, now i draw line from cursor to nearest point. wrong coords